views:

89

answers:

4

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?

+1  A: 

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.

BarsMonster
Ok I've gone through those steps and added that data.
MikeD
I just found out you should actually use $_COOKIE not $_COOKIES. I updated the post.
MikeD
Why you do $id = "e0vgrejdmkjbltrdrtqtnjgzmy1cqurfluuzodeyqjlcoey5rx0";$_SESSION['id'] = $id; ? Please try different key in SESSION array, like uid :-)
BarsMonster
A: 

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.

Marc B
A: 

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().

hopeseekr
I am just trying to store a variable called id, it has nothing to do with the "session id". So I figured from your comment that I could just use a different name so I used: `$_SESSION['new_id'] = $id;`And it is still not working, hmm. The PHPSESSID changes from one page to another.
MikeD
A: 

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

MikeD