passing sessions to another page
Posted: Wed Nov 29, 2006 8:44 pm
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi All,
I’m trying to learn how to use sessions instead of POST/GET protocols. I’m quite inexperienced but most of the progress print checks have done what I think I want them to (Now commented out on script). My troubles start at after the registering of the sessions. The print check works here, but what I want to do is to pass the sessions onto a new page and remember the sessions.
Therefore, if I am on the right track with this code, I need the link syntax to a page e.g. loggedIn.php and then have the $username printed i.e. Hello username…
Hope this is clear enough.
Regards,
FTDCode: Select all
<?PHP
session_start();
// print "session started ";
//include library files for mysql connection
include 'libs/config.php'; // variables
include 'libs/opendb.php'; // open connection
// username and password posted from sign in form
$username = $_POST['username'];
$password = $_POST['password'];
//prepare sql query
$sql="SELECT * FROM members WHERE username='$username' and password='$password'";
//test sql query (OK)
//print("<p>SQL $sql</p>");
//set variable for mysql query
$result=mysql_query($sql);
// Mysql_num_row counts table row
$count=mysql_num_rows($result);
//test print OK
//print "$count check";
// if rows exist place into rows (array)
if ($count == 1){
$_SESSION['id'] = $row[0];
$_SESSION['class'] = $row[1];
$_SESSION['username'] = $row[2];
$_SESSION['password'] = $row[3];
$_SESSION['firstName'] = $row[4];
$_SESSION['lastName'] = $row[5];
$_SESSION['email'] = $row[6];
$_SESSION['country'] = $row[7];
$_SESSION['description'] = $row[8];
//test print OK
//print "success";
//check username and password are sent (OK)
print("<p>Username $username</p>");
print("<p>Password $password</p>");
//trouble starts here
//need to pass to a new page and pass these session variables over
} else
{
echo "Sorry, wrong Username or password, try again";
print("<p><a href = 'main_login.php'>Link back home</a></p>");
}; //end else
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]