Passing session data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
warznorth
Forum Newbie
Posts: 2
Joined: Thu Apr 09, 2009 10:41 am

Passing session data

Post by warznorth »

Ok I have 2 pages 1st page is public and second page can only be called by link on first page.

here is my code for 1st page

Code: Select all

session_start();
$_SESSION['pass']="allow";
 
echo "<a href='page2.php'>click for page 2</a>"
And code for 2nd page

Code: Select all

if ($_SESSION['pass'] != "allow") { echo"Cannot call from that page";exit;
 
}else {
 
 
 
echo"this is page2";}
It doesnt work what am I doing wrong?
Im new at this sorry for the dumb question.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Passing session data

Post by watson516 »

You need to put session_start() on every page that uses sessions
warznorth
Forum Newbie
Posts: 2
Joined: Thu Apr 09, 2009 10:41 am

Re: Passing session data

Post by warznorth »

Simple

It works now
Post Reply