使用 PHP 在 iPhone/iPod Touch 上损坏会话变量

发布于 2024-09-17 18:16:37 字数 1480 浏览 13 评论 0原文

我试图在一个页面上设置会话变量,然后将其加载到另一页面上。此代码适用于 Windows 7 上的 Firefox。在我的 iPod Touch 上访问相同页面时,它不起作用。

第一页是这样的:

session_start(); 
$id = "e0vgrejdmkjbltrdrtqtnjgzmy1cqurfluuzodeyqjlcoey5rx0";
$_SESSION['id'] = $id;

第二页包含此代码:

session_start();
$id = $_SESSION['id'];
echo "ID is $id";

然后输出显示为:

ID is 

如果我运行此代码:

echo "Cookie ";
print_r($_COOKIE);
echo "Session ";
print_r($_SESSION);

我的 Windows 机器上的输出是:

Cookies Array ( [__utma] => 118825363.834893446.1282611798.1283521628.1283525684.13 [__utmz] => 118825363.1283397018.9.7.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=spf test [PHPSESSID] => 6333ddae9f0514f7c4744e340a6746d1 [__utmc] => 118825363 [__utmb] => 118825363.5.10.1283525684 [id] => eza3odazrtcxlty5mdutoem2ms05ndqxltrcnzvgrjjbnzrgqn0 ) Session Array ( [id] => ezffmddgmdmxluvcmzmtruvfnc0wmdu4ltrfnzddnevfmdhfnx0 ) 

我的 iPhone 上的输出是:

Cookies Array ( [PHPSESSID] => 8ec43ead5611dde399d763166926021d [__utma] => 118825363.1927811493.1283218120.1283521676.1283525856.6 [__utmb] => 118825363.1.10.1283525856 [__utmc] => 118825363 [__utmz] => 118825363.1283490501.4.3.utmcsr=(mydomain.com)|utmccn=(referral)|utmcmd=referral|utmcct=/ ) Session Array ( [id] => )

没有发生错误,它只是出现我认为将 $id 设置为“”。这看起来很简单。我是否遗漏了什么,导致您无法在 Apple 设备上执行此操作?

I am trying to just set a session variable on one page, then load it on another page. This code works on Firefox on Windows 7. It does not work when accessing the same pages on my iPod Touch.

The first page is like this:

session_start(); 
$id = "e0vgrejdmkjbltrdrtqtnjgzmy1cqurfluuzodeyqjlcoey5rx0";
$_SESSION['id'] = $id;

The second page contains this code:

session_start();
$id = $_SESSION['id'];
echo "ID is $id";

The output then shows as:

ID is 

If I run this code:

echo "Cookie ";
print_r($_COOKIE);
echo "Session ";
print_r($_SESSION);

The output on my Windows machine is:

Cookies Array ( [__utma] => 118825363.834893446.1282611798.1283521628.1283525684.13 [__utmz] => 118825363.1283397018.9.7.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=spf test [PHPSESSID] => 6333ddae9f0514f7c4744e340a6746d1 [__utmc] => 118825363 [__utmb] => 118825363.5.10.1283525684 [id] => eza3odazrtcxlty5mdutoem2ms05ndqxltrcnzvgrjjbnzrgqn0 ) Session Array ( [id] => ezffmddgmdmxluvcmzmtruvfnc0wmdu4ltrfnzddnevfmdhfnx0 ) 

and the output on my iPhone is:

Cookies Array ( [PHPSESSID] => 8ec43ead5611dde399d763166926021d [__utma] => 118825363.1927811493.1283218120.1283521676.1283525856.6 [__utmb] => 118825363.1.10.1283525856 [__utmc] => 118825363 [__utmz] => 118825363.1283490501.4.3.utmcsr=(mydomain.com)|utmccn=(referral)|utmcmd=referral|utmcct=/ ) Session Array ( [id] => )

No error happens, it just appears to set $id to be "" I think. This seems simple enough. Is there something I am missing where you cannot do this on an Apple device?

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

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

发布评论

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

评论(5

勿忘初心 2024-09-24 18:16:37

已解决:我使用的是绝对 URL,而不是相对 URL。我想这会把一切搞乱。

Solved: I was using an absolute URL instead of a relative one. I guess that messes everything up.

玩套路吗 2024-09-24 18:16:37

差异一定是在 cookie 中。
执行 print_r($_COOKIES);
您会看到 iPad/iPhone 由于某种原因不想向您发送 cookie,然后我们会看到。

The difference must be in cookies.
Do print_r($_COOKIES);
and you will see that iPad/iPhone for some reason does not want to send you cookies, then we'll see.

虐人心 2024-09-24 18:16:37

由于 cookie 被禁用,您无法在 iPhone 上获取会话。

请在您的 iPhone 中转至 Safari> 设置 > 接受 Cookie,并将其设置为接受来自 Visited 的 Cookie。

然后您将能够在 PHP 中创建会话。

You are not able to get the session on the iPhone because cookie is disabled.

Please go to Safari>Settings>Accept Cookies in your iPhone and set it to accept from Visited.

Then you will be able to create the session in PHP.

烟─花易冷 2024-09-24 18:16:37

检查两个脚本中的 session_id()。很可能由于某种原因,iPhone 没有存储会话 cookie,因此每次创建第二个页面时都会创建一个新会话,该页面不会存储上一个会话中的 id

在 iPhone 上使用某种有线嗅探器(如果无法在手机上执行此操作,则在服务器上使用)来查看是否有适当的 cookie 标头来回移动。

Check the session_id() in both scripts. Most likely the session cookie is not being stored by the iPhone for some reason, so a new session is created each time the second page is created, which won't have the id stored from the previous session.

Use some kind of wire sniffer on the iphone (or on the server if you can't do it on the phone) to see if the appropriate cookie headers are going back and forth.

迷途知返 2024-09-24 18:16:37

你的问题的答案很简单。

$_SESSION['id'] 是只读

如果您在下一页执行$_SESSION['id'] = 'foo';,它将恢复为其原始值。

要更改会话 ID:

session_id('foo');

必须,您必须调用 session_id('foo'); before session_start()

The answer to your question is easy.

$_SESSION['id'] is read-only.

If you do $_SESSION['id'] = 'foo'; the next page it will revert back to its original value.

To change the session id:

session_id('foo');

It is imperative that you call session_id('foo'); before session_start().

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