Try this
session_start();
// pass variable form login.php
$username = $REQUEST['username'];
$password = $REQUEST['password'];
mysql_connect( "$host", "$user", "$pwd" );
mysql_select_db( "$db" );
$sql = "SELECT * FROM user WHERE user='$username' AND password='$password' ";
$result = mysql_query( $sql );
$num = mysql_num_rows( $result );
if ( $num != 0 )
{ $auth = true;
$_SESSION['username']=$username
}
hope this help
Martijn D. wrote:
I'm trying to make a login-system for my website using sessions.
But I don't get it working! Argh!
This is what I'm doing:
On login.php is a log-in form whith <form ... action='page1.php'>.
On page1.php there is a script that checks whether the username and password are known in the database. If so, username and id will be registered session variables (using $_SESSION['username']). User will be linked to a page2.php.
On page2.php I want to check for the session variables.
This is what happens:
Everything works, until I'm at page2.php. Yhere my session variables are gone! I can't echo them, and when I do a isset($_SESSION['username'], it is NOT set. But I DID set it on page1.php!
There is something strange besides that. When I use session_start() on page2.php my session file in /tmp become empty 0(kš! when I don't use session_start(), they're 34(kš containing 'username' and 'id', but still won't show up on page2.php with an echo.
Can anyone help me please! I really ne....