Topic awaiting preservation: PHP and sessions (Page 1 of 1) |
|
---|---|
Maniac (V) Inmate From: there...no..there..... |
posted 12-29-2006 16:51
I know this is a bit of stuff, but here is what I have. Very simple login script that uses sessions and authenticates to users in a database. code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Log In</title> <meta name="generator" content="MAX's HTML Beauty++ 2004" /> <link rel="stylesheet" type="text/css" href="css/stylin.css" /> </head> <body> <div id="login"> <form name="form1" class="form1" method = "post" action = "checklogin.php"> <fieldset> <legend>User Log In</legend> <ol> <li> <label for = "uname">User Name : </label> <input name = "uname" type = "text" id = "uname" /> </li> <li> <label for = "usrpass">Password : </label> <input name = "usrpass" type = "password" id = "usrpass" /> </li> <li> <input type="submit" name="Submit" value="Login"> </li> </ol> </fieldset> </form> </div> </body> </html>
code: <?php /* * checklogin.php */ require("constants.php"); // username and password sent from form $myusername=$_POST['uname']; $mypassword=$_POST['usrpass']; // encrypt password $encrypted_mypassword=md5($mypassword); $sql="SELECT * FROM " . TBL_NAME . " WHERE username='$myusername' and password='$encrypted_mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to the admin page session_register("myusername"); session_register("mypassword"); //can change this to the location where the authorized user can go to. //change this to go to the gallery upload page header("location:login_success.php"); }else { echo "Wrong Username or Password"; } ?>
|
Lunatic (VI) Inmate From: under the bed |
posted 12-29-2006 18:00
I've never used the 'session_register' code: $_SESSION['myusername'] = $myusername;
|
Maniac (V) Inmate From: there...no..there..... |
posted 12-29-2006 20:42
well, I tried to do exactly what you have there, but it still didn't work. I was testing it by sending it to another page from the form and just printing out the session information. Nothing was there |
Paranoid (IV) Mad Librarian From: Glieberlermany |
posted 12-29-2006 23:47
And you did call session_start() both in checklogin.php and the other test file? |
Lunatic (VI) Inmate From: under the bed |
posted 12-30-2006 01:03
Yeah, remember to start the session on each page that will need to check the session info, not just the pages that set or update the info... |
Maniac (V) Inmate From: there...no..there..... |
posted 12-30-2006 02:46
yeah, I started each page with session_start() each time. Now...I didn't put it into the checklogin.php page you see above. That page was there to do the registering of the session. |
Paranoid (IV) Mad Librarian From: Glieberlermany |
posted 12-30-2006 10:52
quote:
|
Maniac (V) Inmate From: there...no..there..... |
posted 12-30-2006 14:02
quote:
|
Maniac (V) Mad Scientist From: Denver, CO, USA |
posted 01-09-2007 20:59
From PHP.NET quote:
code: function redirect($url = "") { ob_clean(); $host=$_SERVER['HTTP_HOST']; $uri=rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); Header("Location: http://$host$uri/$url"); exit; }
|