Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP Session Variable

Member
 
Join Date: May 2009
Location: Goregaon, मुंबई IN :)
Posts: 85
#1: Jul 2 '09
Hello,
I'm new to php,

I'm storing temp variable in SESSION

Expand|Select|Wrap|Line Numbers
  1. $_SESSION['temp']='value';
when i go from one php page to other php page, the session variable is accessible
but when i go to the other page in a subdirectory.. the SESSION variable is not accesible..

am i missing some php configuration?

pls help

regards,
Nitin Sawant

code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#2: Jul 2 '09

re: PHP Session Variable


Quote:
but when i go to the other page in a subdirectory
PHP does not have a GOTO command!
Member
 
Join Date: May 2009
Location: Goregaon, मुंबई IN :)
Posts: 85
#3: Jul 2 '09

re: PHP Session Variable


Hello code green,
I'm navigating from one page to another page in subdirectory
suppose: current page 'index1.php'
then in that page i write
Expand|Select|Wrap|Line Numbers
  1. <a href='std/index2.php'>go to subdirectory</a>
  2.  
then the session variable is lost when i navigate to 'index2.php' in std subdirectory..
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#4: Jul 2 '09

re: PHP Session Variable


is in that page the session restarted?
Member
 
Join Date: May 2009
Location: Goregaon, मुंबई IN :)
Posts: 85
#5: Jul 2 '09

re: PHP Session Variable


nope, the session is not restarted..

in index1.php page i wrote..
Expand|Select|Wrap|Line Numbers
  1. if (!isset($_SESSION)) {
  2.         session_start();
  3. }
  4. $_SESSION['temp']='value';
  5.  
and in the index2.php page in std directory i'm trying to retrieve the variable
Expand|Select|Wrap|Line Numbers
  1. $var=$_SESSION['temp'];
  2.  
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#6: Jul 2 '09

re: PHP Session Variable


Quote:

Originally Posted by code green View Post

PHP does not have a GOTO command!

It does now :P
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#7: Jul 2 '09

re: PHP Session Variable


Quote:

Originally Posted by NitinSawant View Post

nope, the session is not restarted..

as I thought… you need to open a session first:
Quote:

Originally Posted by php.net

Note: […] Also note that you must start your session using session_start() before use of $_SESSION becomes available. […]

Member
 
Join Date: May 2009
Location: Goregaon, मुंबई IN :)
Posts: 85
#8: Jul 3 '09

re: PHP Session Variable


But i'm starting the session on index page only
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2.  
Member
 
Join Date: May 2009
Location: Goregaon, मुंबई IN :)
Posts: 85
#9: Jul 3 '09

re: PHP Session Variable


well, what i was missing is adding 'session_start();' on every page...

nevermind, i got it..

prob. solved


regards,
Nitin Sawant
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#10: Jul 3 '09

re: PHP Session Variable


Quote:

Originally Posted by NitinSawant View Post

well, what i was missing is adding 'session_start();' on every page...

nevermind, i got it..

prob. solved


regards,
Nitin Sawant

That's exactly what Dormilich told you to do. :)
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#11: Jul 6 '09

re: PHP Session Variable


Quote:

Originally Posted by code green View Post

PHP does not have a GOTO command!

Thanks for the laugh starting my Monday, it's been a sh*tty week.







Dan
Reply