473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Cannot pass SESSION variables between pages

Trying a simple test of passing $_SESSION variables between two php pages. I don't see any data on the second page and the session id that is printed out is not the same as the first page session id of the same SESSIONSAMPLE name, which I think is the problem. When I refresh either page the session id constantly changes as well which doesn't seem right either. I have session.auto_start set to 0 (off). Any help would be greatly appreciated. Here are the two scripts:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_name('SESSIONSAMPLE');
  4. session_start();
  5.  
  6. $_SESSION['user_name'] = 'chippy';
  7. $_SESSION['full_name'] = 'Chippy the Chipmunk';
  8. $_SESSION['last_visit'] = '2 weeks ago';
  9. $_SESSION['favourites'] = 'Books';
  10.  
  11.  
  12.  
  13. print_r($_SESSION);
  14. echo "<br/>\n";
  15. print_r(session_id());
  16. echo "<br/>\n";
  17. print_r(session_name());
  18. echo "<br/>\n";
  19. print_r(session_get_cookie_params());
  20. echo "<br/>\n";
  21.  
  22. ?>
  23.  
  24. <br/>
  25. <br/>
  26. <a href="session2.php">Click Here for Next Page</a>
  27. <br/>
  28.  
  29.  
  30. session2.php
  31.  
  32. <?php
  33. session_name('SESSIONSAMPLE');
  34. session_start();
  35.  
  36. //
  37. // show the session data as we have them thus far.
  38. //
  39. print_r($_SESSION);
  40. echo "<br/>\n";
  41. print_r(session_id());
  42. echo "<br/>\n";
  43. print_r(session_name());
  44. echo "<br/>\n";
  45. print_r(session_get_cookie_params());
  46. echo "<br/>\n";
  47. ?>
[Please use CODE tags when posting source code. Thanks! --pbmods]
Jun 29 '07 #1
5 3998
pbmods
5,821 Expert 4TB
Heya, Manny.

What happens if you remove the session_name() calls?

You can also set session.name in your php.ini file.
Jun 29 '07 #2
Tried it without the session_name calls and get the same results except I now see the default PHPSESSID session name displayed.
Jun 29 '07 #3
pbmods
5,821 Expert 4TB
Heya, Manny.

Ok, I'm curious. If you echo session_id() on each page, do you get the same result?
Jun 29 '07 #4
Heya, Manny.

Ok, I'm curious. If you echo session_id() on each page, do you get the same result?



Session ID is different on both pages.
OUTPUT from page1:

Array ( [user_name] => chippy [full_name] => Chippy the Chipmunk [last_visit] => 2 weeks ago [favourites] => Books )
32ohq5adgif60vpj60aq9lrrh0
PHPSESSID
Array ( [lifetime] => 0 [path] => \ [domain] => [secure] => [httponly] => )


OUTPUT from page 2:

Array ( )
24lhatmjlq3jt63sbte6a2i1t0
PHPSESSID
Array ( [lifetime] => 0 [path] => \ [domain] => [secure] => [httponly] => )
Jun 29 '07 #5
kovik
1,044 Expert 1GB
Is this online for others to try Considering your sessions use cookies, I'm thinking you may have cookies turned off on your browser, which would cause the client to be unaware of it's session id.

Any chance that that's the case?
Jun 29 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Lina Manjarres | last post by:
Hello, I have a session variable in a login page. Then I go to a form page where I uses the ProfileID and the UserID. Then I go to a result page where I would like to use the UserID as a filter,...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
9
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example...
4
by: ruca | last post by:
Hi, How can I pass the values of some variables from page1.aspx to page2.aspx? I try to define some variables in page2 and then when I click a button in page1 it will fill that variables (in...
2
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the...
1
by: ChrisN | last post by:
Hi there, Two questions related to each other. 1. Session variables expire by defualt when not used for 20 minutes. Does "used" mean that a user has not access any session varibles in 20...
3
by: mike | last post by:
Hello, I've got a .aspx page that passes login information to an .asp page using a querystring. The problem is its not secure, the user can see the login information right there and type in...
3
by: hon123456 | last post by:
Dear all, I have a session variable session("loginid) which can be passed from A.asp to B.asp. Then In B.asp I have a hyperlink to C.asp e.g. < A href..C.asp>. The session variable cannot be...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.