Jump to content

New to sessions


corbin

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.