在 Safari 中使用用户名和密码重定向到 FTP URL

发布于 2024-11-28 21:38:13 字数 528 浏览 1 评论 0原文

我在 Safari 上遇到了一个无法解决的问题:

<?php
    header("Location: ftp://username:[email protected]/somefile.zip");
?>

此代码片段适用于所有浏览器(Fx、Chrome、IE7-9),但不适用于最新的 Safari,这告诉我我不这样做具有查看该页面的权限(即,它使用正确的协议重定向到正确的页面[somedomain.org],但不处理身份验证数据)。

有趣的是,当我将其直接复制到地址栏或放入 标签并单击它时,它会起作用。这是 Safari 的 bug,还是我在这里遗漏了一些其他浏览器忽略的东西?如果这是 Safari 的错误,是否有某种解决方法?

I've got a problem with Safari I haven't been able to solve:

<?php
    header("Location: ftp://username:[email protected]/somefile.zip");
?>

This code-snippet works in every browser (Fx, Chrome, IE7-9), but not in the latest Safari, which tells me that I don't have permission to view the page (that is, it redirects to the correct page [somedomain.org] with the correct protocol, but does not process the authentication data).

Interestingly it works when I copy it directly to the address bar or when I put in in an <a>-tag an click on it. Is this a Safari bug, or am I missing something here, which the other browsers ignore? And if it's a Safari bug, is there some kind of workaround?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

被你宠の有点坏 2024-12-05 21:38:14

我也遇到过类似的问题,最后发现是钥匙扣的问题!如果您曾经允许 safari、omniweb 或 opera(或者在您的情况下为 ftp 进程)将用户名和密码存储在该站点的钥匙串中,则该用户名和密码将被发送到该站点,而不是 URL 中的用户名和密码。 FireFox 不这样做,所以事情按预期进行。

I had similar problems, and it turned out to be the keychain! If you ever allowed safari, omniweb or opera (or the ftp process in you case) to store the username and password in the keychain for that site, this will be sent to the site instead of the one in the URL. FireFox doesn't do this, so things work as expected there.

妄司 2024-12-05 21:38:13

尝试:

header('HTTP/1.1 301 Moved Permanently');
header('Location: ftp://username:[email protected]/somefile.zip');

如果它不起作用尝试:

echo <<< EOF
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=ftp://username:[email protected]/somefile.zip">
EOF;

或者:

header ('Location: ftp://username:[email protected]/somefile.zip');   
header ('Content-Length: 0');

我从以下位置得到的最后一个解决方案: http:// /www.ultrashock.com/forum/viewthread/90424/

Try:

header('HTTP/1.1 301 Moved Permanently');
header('Location: ftp://username:[email protected]/somefile.zip');

if it doesn't work try :

echo <<< EOF
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=ftp://username:[email protected]/somefile.zip">
EOF;

Or:

header ('Location: ftp://username:[email protected]/somefile.zip');   
header ('Content-Length: 0');

The last solution I got from: http://www.ultrashock.com/forum/viewthread/90424/

时光暖心i 2024-12-05 21:38:13

echo "window.location='ftp://用户名:[电子邮件受保护]/somefile.zip';";

尝试 JS 重定向,看看是 PHP 还是请求有问题。

echo "window.location='ftp://username:[email protected]/somefile.zip';";

Try that JS redirect and see if it's PHP or the request it has a problem with.

稚然 2024-12-05 21:38:13

您可能缺少一些它需要的 header() 信息,例如 - header("Status: 200");... 不久前标题重定向在 chrome 中没有此行时不起作用。

You are probably missing some header() info it needs like - header("Status: 200");... A while back header redirect did not work w/o this line in chrome.

夜空下最亮的亮点 2024-12-05 21:38:13

您可以让 PHP 脚本在后台获取文件,并将其提供给浏览器。如图所示,PHP 脚本充当代理。
假设您的下载量不超过您的网络服务器的 PHP 内存限制,那么就可以了。

好处:
- 没有重定向。
- 您不会在 URL 中公开用户/密码。

如果您决定重定向到受密码保护的 FTP,请考虑其他选择。有很多方法可以保护通过 http 访问文件的安全。如今,HTTP 性能与 FTP 大致相当(很久以前,情况并非如此,快速站点需要 FTP 进行下载)。

You could make the PHP script fetch the file in the background, and serve it to the browser. As in, the PHP script acts as a proxy.
Assuming your download is not larger than your webserver's PHP mem limit, this will be OK.

Benefits:
-There is no redirect.
-You would not be exposing the user/pass in the URL.

If redirecting to the pw protected FTP is your decision, consider the alternatives. There are lots of ways to secure access to a file via http. These days, HTTP performance is about equal to that of FTP (long ago this was not true, and fast sites needed FTP for downloading).

二手情话 2024-12-05 21:38:13

您收到任何错误或只是不工作吗?

确保 phpconfig 中的输出缓冲区设置正确

do you receive any error or just not working?

make sure the the output buffer is set correctly in the phpconfig

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文