Jump to content

Archived

This topic is now archived and is closed to further replies.

corbin

New to sessions

Recommended Posts

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:
[code]<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>[/code]

login_action.php:
[code]<?
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>[/code]

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

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?

Share this post


Link to post
Share on other sites
HI

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

[url=http://www.phpfreaks.com/forums/index.php/topic,99222.0.html]http://www.phpfreaks.com/forums/index.php/topic,99222.0.html[/url]
cheers

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Got it.  I was using $SESSION and not $_SESSION...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.