lookee Posted October 30, 2008 Share Posted October 30, 2008 I've almost got my login script working, but for some reason the username string is not passing to my successful.php page. Code -------------------------------------------- <?php session_start(); include 'config.php'; // Connect to server and select databse. //mysql_connect("$host", "$username", "$password")or die("cannot connect"); //mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $username=$_POST['username']; $password=$_POST['password']; // captures username & passwords, so they can be passed on to other pages session_register("username"); $sql="SELECT * FROM nixon WHERE username='$username' and password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matches table row must be 1 row if($count==1){ header("location: successful.php"); } else { header ("Location: again.html"); } ?> ------------------------ Any assistance would be of great help! Thanks! (edited by kenrbnsn to add tags) Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/ Share on other sites More sharing options...
bobbinsbro Posted October 30, 2008 Share Posted October 30, 2008 can you post the login form page please? Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678004 Share on other sites More sharing options...
lookee Posted October 30, 2008 Author Share Posted October 30, 2008 Certainly... the login form and the receiving successful page are below... --------------------- Login Form <div id="dispanel"> <table width="750" border="0" background="../images/graybk.jpg"> <tr> <td width="736" colspan="3"><form name="form2" method="post" action="member.php"> <table width="736" height="221" border="0"> <tr> <td height="21"> </td> <td colspan="3" align="left" valign="top"> </td> <td> </td> </tr> <tr> <td width="13" height="22"> </td> <td colspan="3" align="left" valign="top"><p class="style13 style23">Registered User Login</p> </td> <td width="12"> </td> </tr> <tr> <td> </td> <td width="163"> </td> <td width="167"> </td> <td width="359"> </td> <td> </td> </tr> <tr> <td> </td> <td><span class="style3 style30">Username</span></td> <td><label> <input name="username" type="text" id="username"> </label></td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><span class="style3 style30">Password</span></td> <td><input name="password" type="text" id="password"></td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td><label> <input name="submit" type="submit" id="submit" value="Login" /> </label></td> <td> </td> <td> </td> </tr> <tr> <td height="21"> </td> <td colspan="3"> </td> <td> </td> </tr> <tr> <td height="21"> </td> <td colspan="3"><hr /></td> <td> </td> </tr> </table> ------------ Successful page that should receive the session strings... <?php session_start(); include 'config.php'; echo "Welcome,".$username; ?> -------------------------- Thanks in advance! (edited by kenrbnsn to add tags) Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678012 Share on other sites More sharing options...
revraz Posted October 30, 2008 Share Posted October 30, 2008 Because you are not transferring the variable to a $_SESSION variable. Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678030 Share on other sites More sharing options...
bobbinsbro Posted October 30, 2008 Share Posted October 30, 2008 as revraz said, you should be using $_SESSION. since your'e not using it i assume you need more information... check out the examples and accompanying notes on this page: http://il2.php.net/manual/en/function.session-start.php Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678039 Share on other sites More sharing options...
lookee Posted October 30, 2008 Author Share Posted October 30, 2008 I just purchased a tutorial that gave an example of the session string, and the tutorial is not formatted as $_SESSION['thing'] = 'formstring'; It's formatted $loggedin="username"; session_register("loggedin"); Please see attachment for actual screen capture of example code... Is this not correct? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678057 Share on other sites More sharing options...
bobbinsbro Posted October 30, 2008 Share Posted October 30, 2008 i believe it is correct, but it's rather old, and i don't really know how to do things the old way . if you're in a hurry to get this solved, you really should check out the examples on the page i gave you. otherwise, i hope someone who knows what they're talking about will come along. sorry to be so unhelpful... Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678062 Share on other sites More sharing options...
CroNiX Posted October 30, 2008 Share Posted October 30, 2008 Read the notes in the manual... http://uk.php.net/session_register If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled. Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678064 Share on other sites More sharing options...
lookee Posted October 30, 2008 Author Share Posted October 30, 2008 Thanks... I got it to work whe I use $_SESSION['loggedin'] = $username; session_register("loggedin"); but I was wondering why I couldn't get it to work using the format in the tutorial, which is... // captures username to be passed on to other pages $loggedin = $username; session_register("loggedin"); thanks! [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678068 Share on other sites More sharing options...
lookee Posted October 30, 2008 Author Share Posted October 30, 2008 Solved... thanks! Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678069 Share on other sites More sharing options...
kenrbnsn Posted October 30, 2008 Share Posted October 30, 2008 Do NOT use "session_register()". It will cause problems. Ken Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678071 Share on other sites More sharing options...
CroNiX Posted October 30, 2008 Share Posted October 30, 2008 Its because your tutorial is outdated. In modern php versions, registered globals is set to off (as it should be because its a big security risk). As Ken said and I tried to point out, do not use session_register(). page 1: <?php session_start(); $_SESSION['loggedin'] = $username; ?> page 2 and so on... <?php session_start(); $username=$_SESSION['loggedin']; echo $username; ?> Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678077 Share on other sites More sharing options...
revraz Posted October 30, 2008 Share Posted October 30, 2008 And I seriously hope you didn't really "purchase" it, because if you paid money for it, you got ripped. Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678092 Share on other sites More sharing options...
lookee Posted October 30, 2008 Author Share Posted October 30, 2008 Thanks! I just noticed the PHP tutorial by Mustafa on VTC.com was released 2002. I have requested my refund. Quote Link to comment https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/#findComment-678093 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.