Jump to content


Photo

New to sessions


  • Please log in to reply
3 replies to this topic

#1 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 02 July 2006 - 08:55 PM

Recently I've started tryin to teach my self about sessions, but i cant figure out how to get sessions to span multiple pages... So far I've been messin around with a very very very simple login script...

login.php:
<form method=POST action="login_action.php">
Name: <input type=text name="name"><BR>
Password: <input type="password" name="pass"><BR>
<input type="Submit" value="submit">
</form>

login_action.php:
<?
include('db.php');
$name = $_POST['name'];
$pass = $_POST['pass'];
$q = "SELECT * from accounts WHERE ((name='$name') && (password='$pass'))";
$a = mysql_query($q);
$r = mysql_num_rows($a);
if($r > 0) {
session_start();
$SESSION['user'] = $name;
}
?>
<a href="test.php">test</a>

and last test.php:
<?
session_start();
echo $SESSION['user'];
?>

so lets say i login with the name corbin, on login_action.php it can echo $SESSION['user'] fine, but on test.php it doesnt think SESSION['user'] is set... So pretty much im asking how do i get it to recognize a session from 1 page on another?

Why doesn't anyone ever say hi, hey, or whad up world?

#2 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 02 July 2006 - 09:03 PM

HI

Take a look here i just posed this one for someone else

http://www.phpfreaks...ic,99222.0.html
cheers
Im loving it ........

#3 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 02 July 2006 - 09:09 PM

Seems to me that that script doesnt even need to use sessions for what it does...

That script doesnt help me (i dont think  ???) it just forwards you to different pages based on access level... Im asking how do i get page2.php to echo the session data that was set using page1.php
Why doesn't anyone ever say hi, hey, or whad up world?

#4 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 02 July 2006 - 09:48 PM

Got it.  I was using $SESSION and not $_SESSION...
Why doesn't anyone ever say hi, hey, or whad up world?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users