matthew798 Posted September 11, 2008 Share Posted September 11, 2008 OK. I have a problem i cannot fix. No matter what i try. I cannot get the session variable $_SESSION['username'] to carry from one page to another. There are three pages (more in the whole site, but if i get it working on these three then i can do the rest) -Login page -Login process -admin page Here is the login page (pertinent part): <form action="loginprocess.php" method="POST"> <span class="style1">Username</span><br /> <input name="username" class="textinputhead"></textarea><br /> <span class="style1">Password</span><br /> <input name="password" class="textinputhead"></textarea><br /><br /> <input type="submit" class="textinputsubmit" /> </form> here is loginprocess.php: <?php session_start(); include 'dbconnect.php'; $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $sql="SELECT * FROM users WHERE username='$username' and password='$password'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register('$username'); header('location:test.php'); } else { echo "Wrong Username or Password. Use the back button. If you think this message is incorrect, contact the webmaster."; } ?> here is an admin page that would use info from the session created in loginprocess.php: <?php session_start(); $username = $_SESSION['username']; include 'dbconnect.php'; $q = mysql_query("SELECT permission FROM users WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_assoc($q); $permissions = explode(",", $row['permission']); if ( $permissions['0'] == 0 ){ die('You do not have permission to access this administrative function'); } ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <LINK REL=StyleSheet HREF="stylemain.css" TYPE="text/css" MEDIA=screen /> </head> <body bgcolor="black"> <table border="0"> <tr> <td><form action="newsprocess.php" method="POST"> <span class='headline'>Title</span><br /> <input name="title" type="text" class='textinputhead' /> <br /><br /> <span class='headline'>Body</span><br /> <textarea name="body" type="text" class='textinputbody' /></textarea><br /><br /> <input type="submit" value='Post News' class='textinputsubmit'/> </form></td> </tr> </table> </body> </html> I have tried everything my poor little brain could think of. Different quotes, with and without the $, brackets, no brackets. But whatever i do the bloody session variable does not carry! Important to note: The variable doesn't come up as undefined, when i echo $_SESSION['username'] on the admin page, it echoes blank but does not give me an error. PLEASE. I am the type of person that won't be able to sleep tonight if i can't figure this out. I have to get things done. ANYTHING will help. Link to comment https://forums.phpfreaks.com/topic/123709-solved-session-problem-making-my-brain-hurt/ Share on other sites More sharing options...
goatdog Posted September 11, 2008 Share Posted September 11, 2008 try session_register("username"); instead of session_register("$username"); then you assign the variable to the session with $_SESSION['username'] = $username Link to comment https://forums.phpfreaks.com/topic/123709-solved-session-problem-making-my-brain-hurt/#findComment-638775 Share on other sites More sharing options...
matthew798 Posted September 11, 2008 Author Share Posted September 11, 2008 you, gotdog, with your two posts have just solved the appitamy of my existance. And for that, i will be donating 20$ to PHP Freaks. You are indeed a very good human. Link to comment https://forums.phpfreaks.com/topic/123709-solved-session-problem-making-my-brain-hurt/#findComment-638779 Share on other sites More sharing options...
goatdog Posted September 11, 2008 Share Posted September 11, 2008 i'm so excited i was right. i've been there before, grinding my teeth all night, then realizing its a typo or i'm missing a comma Link to comment https://forums.phpfreaks.com/topic/123709-solved-session-problem-making-my-brain-hurt/#findComment-638781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.