bob2588 Posted October 23, 2009 Share Posted October 23, 2009 hello i wrote this php login but it not login me in can you guys take a look at it for me <?php include 'db.php'; // username and password sent from form $username=$_POST['username']; $password=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM admin WHERE login='$username' and pass1='$password'"; $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 file "login_success.php" session_register("username"); session_register("password"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> Link to comment https://forums.phpfreaks.com/topic/178752-solved-login-session-is-not-creating/ Share on other sites More sharing options...
Bricktop Posted October 23, 2009 Share Posted October 23, 2009 Hi bob2588, The tutorial you may have taken this code from here shows the login_success.php file to contain: <? session_start(); if(!session_is_registered(myusername)){ header("location:main_login.php"); } ?> <html> <body> Login Successful </body> </html> Because in your code you are registering "username" (session_register("username") and not "myusername" as the above code shows, change your code to read: <? session_start(); if(!session_is_registered(username)){ header("location:main_login.php"); } ?> <html> <body> Login Successful </body> </html> Hope this helps. Link to comment https://forums.phpfreaks.com/topic/178752-solved-login-session-is-not-creating/#findComment-942911 Share on other sites More sharing options...
bob2588 Posted October 23, 2009 Author Share Posted October 23, 2009 i fix it i had a problem with login_success.php thanks for the help Link to comment https://forums.phpfreaks.com/topic/178752-solved-login-session-is-not-creating/#findComment-942914 Share on other sites More sharing options...
mrMarcus Posted October 23, 2009 Share Posted October 23, 2009 WARNING: This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged. session_register() should be avoided since (as stated above), it's soon to be removed, and is already deprecated. instead of: session_register("username"); session_register("password"); use: $_SESSION['username'] = 'username here'; $_SESSION['password'] = 'password here'; read more about $_SESSION's EDIT: and then access the $_SESSION like so: if (!isset ($_SESSION['username'])) { header("location: main_login.php"); } Link to comment https://forums.phpfreaks.com/topic/178752-solved-login-session-is-not-creating/#findComment-942928 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.