dezkit Posted November 21, 2008 Share Posted November 21, 2008 Hey guys, I have this script I made: <table border="0" width="100%"> <tr> <TD ALIGN="right"> <table height=1> <?php if(session_is_registered(myusername)){ echo "<a href=\"/admin_gallery\">Edit the Gallery page.</a> <a href=\"?logout\">Log Out</a>."; } else { $Submit = $_POST["Submit"]; $logout = $_GET["logout"]; if(isset($Submit)){ include("config.php"); $tbl_name="members"; $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $encrypted_mypassword=md5($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); } else { echo "<font color=red> Wrong Username or Password </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } elseif(isset($logout)) { session_destroy(); echo "<font color=red> You have logged out. </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } else { echo "<form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } ?> </table> </td> </tr> </table> But somehow, I can't log out. Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/ Share on other sites More sharing options...
chronister Posted November 21, 2008 Share Posted November 21, 2008 I have found some instances where session_destroy does not do exactly what I need it to do. Use unset($_SESSION['myusername']) and see if that works for you. Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694928 Share on other sites More sharing options...
dezkit Posted November 21, 2008 Author Share Posted November 21, 2008 Still doesn't work :/ Current: <table border="0" width="100%"> <tr> <TD ALIGN="right"> <table height=1> <?php if(session_is_registered(myusername)){ echo "<font color=white size=\"-1\"><a href=\"/admin_gallery\">Edit the Gallery page.</a> <a href=\"?logout\">Log Out</a></font>"; } else { $Submit = $_POST["Submit"]; $logout = $_GET["logout"]; if(isset($Submit)){ include("config.php"); $tbl_name="members"; $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $encrypted_mypassword=md5($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); } else { echo "<font color=white size=\"-1\"> Wrong Username or Password </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } elseif(isset($logout)) { unset($_SESSION['myusername']); echo "<font color=white size=\"-1\"> You have logged out. </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } else { echo "<form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } ?> </table> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694936 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 instead of $logout = $_GET["logout"] try $logout = (isset($_GET["logout"])) ? 1 : 0; then instead of } elseif(isset($logout)) { try } elseif($logout) { Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694941 Share on other sites More sharing options...
dezkit Posted November 21, 2008 Author Share Posted November 21, 2008 Wow, still doesn't work! <table border="0" width="100%"> <tr> <TD ALIGN="right"> <table height=1> <?php if(session_is_registered(myusername)){ echo "<font color=white size=\"-1\"><a href=\"/admin_gallery\">Edit the Gallery page.</a> <a href=\"?logout\">Log Out</a></font>"; } else { $Submit = $_POST["Submit"]; $logout = (isset($_GET["logout"])) ? 1 : 0; if(isset($Submit)){ include("config.php"); $tbl_name="members"; $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $encrypted_mypassword=md5($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); } else { echo "<font color=white size=\"-1\"> Wrong Username or Password </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } elseif($logout) { unset($_SESSION['myusername']); echo "<font color=white size=\"-1\"> You have logged out. </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } else { echo "<form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } ?> </table> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694942 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 Dp you get any errors, or does it just load a different part of the page, and if so what part? Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694944 Share on other sites More sharing options...
dezkit Posted November 21, 2008 Author Share Posted November 21, 2008 It's still on the same page. Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694945 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 Is this all the page code? if so you havent started the session..... start_session() at the top of the page Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694947 Share on other sites More sharing options...
dezkit Posted November 21, 2008 Author Share Posted November 21, 2008 It is. Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694955 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 if(session_is_registered(myusername) && !isset($_GET['logout'])){ add that line to the top (replacing the current one) Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694964 Share on other sites More sharing options...
phpSensei Posted November 21, 2008 Share Posted November 21, 2008 It is. Show us the entire code because this doesnt seem to be it by the look of the html structure. The start_session as mentioned needs to be at the TOP of the page, with no html before it or any spaces. Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694966 Share on other sites More sharing options...
dezkit Posted November 21, 2008 Author Share Posted November 21, 2008 <?php session_start(); ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Home Page</title> The first 3 lines of my page, guys, it's not the sessions, it's the WAY my code is written, my logic isn't good enough to spot what's wrong! Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694969 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 replace if(session_is_registered(myusername)){ with if(session_is_registered(myusername) && !isset($_GET['logout'])){ Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694972 Share on other sites More sharing options...
dezkit Posted November 21, 2008 Author Share Posted November 21, 2008 Works perfectly gevans! Thanks sooo much! But now i have a different problem, after i Log in, it shows a blank page, and when i reload the page, then it shows the welcome message. Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694982 Share on other sites More sharing options...
phpSensei Posted November 21, 2008 Share Posted November 21, 2008 edit: nvm, Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694987 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 LOL, there is a lot of work to do to make this good code, it need to be completely restructured. <table border="0" width="100%"> <tr> <TD ALIGN="right"> <table height=1> <?php $Submit = (isset($_GET["Submit"])) ? 1 : 0; $logout = (isset($_GET["logout"])) ? 1 : 0; if(session_is_registered(myusername) && (!$logout && !$Submit)){ echo "<font color=white size=\"-1\"><a href=\"/admin_gallery\">Edit the Gallery page.</a> <a href=\"?logout\">Log Out</a></font>"; } else { if($Submit){ include("config.php"); $tbl_name="members"; $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $encrypted_mypassword=md5($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); } else { echo "<font color=white size=\"-1\"> Wrong Username or Password </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } elseif($logout) { unset($_SESSION['myusername']); echo "<font color=white size=\"-1\"> You have logged out. </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } else { echo "<form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } ?> </table> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694996 Share on other sites More sharing options...
dezkit Posted November 21, 2008 Author Share Posted November 21, 2008 BTW: I register the session, after i checked if it exists, does anybody know how to implement it to make a session before it checks? Thanks code: <table border="0" width="100%"> <tr> <TD ALIGN="right"> <table height=1> <?php if(session_is_registered(myusername) && !isset($_GET['logout'])){ echo "<font color=white size=\"-1\"><a href=\"/admin_gallery\">Edit the Gallery page.</a> <a href=\"?logout\">Log Out</a></font>"; } else { $Submit = $_POST["Submit"]; $logout = (isset($_GET["logout"])) ? 1 : 0; if(isset($Submit)){ include("config.php"); $tbl_name="members"; $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $encrypted_mypassword=md5($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); } else { echo "<font color=white size=\"-1\"> Wrong Username or Password </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } elseif($logout) { unset($_SESSION['myusername']); echo "<font color=white size=\"-1\"> You have logged out. </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } else { echo "<form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } ?> </table> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-694998 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 phpSensei, you were right, a little bit rough, but fixed Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-695003 Share on other sites More sharing options...
dezkit Posted November 21, 2008 Author Share Posted November 21, 2008 LOL, there is a lot of work to do to make this good code, it need to be completely restructured. Thanks for the code, but it doesn't really work Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-695004 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 <table border="0" width="100%"> <tr> <TD ALIGN="right"> <table height=1> <?php $Submit = (isset($_POST["Submit"])) ? 1 : 0; $logout = (isset($_GET["logout"])) ? 1 : 0; if(session_is_registered(myusername) && (!$logout && !$Submit)){ echo "<font color=white size=\"-1\"><a href=\"/admin_gallery\">Edit the Gallery page.</a> <a href=\"?logout\">Log Out</a></font>"; } else { if($Submit){ include("config.php"); $tbl_name="members"; $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $encrypted_mypassword=md5($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); } else { echo "<font color=white size=\"-1\"> Wrong Username or Password </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } elseif($logout) { unset($_SESSION['myusername']); echo "<font color=white size=\"-1\"> You have logged out. </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } else { echo "<form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } ?> </table> </td> </tr> </table> Another try.... (sorry it's getting late over here) Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-695021 Share on other sites More sharing options...
dezkit Posted November 21, 2008 Author Share Posted November 21, 2008 Nope. Lol, I will just re construct the code myself, it's gonna be hard; but it's going to be worth it Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-695025 Share on other sites More sharing options...
revraz Posted November 21, 2008 Share Posted November 21, 2008 Have you actually read the instructions for session_start() and how to use $_SESSIONs? Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-695028 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 It's a fairly simple script that I've had working twice over here :S, not sure what's going on... Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-695031 Share on other sites More sharing options...
dezkit Posted November 21, 2008 Author Share Posted November 21, 2008 I had rewrote it now with meta redirections after assigning a session, and logging out, but here is the problem: When ever i log out, i have "?logout" in my url, so that means whenever i try to log back in, i automatically sign out, how do i do it so that when i sign out with "?logout" in my url, php removes "?logout" after i had logged out? <table border="0" width="100%"> <tr> <TD ALIGN="right"> <table height=1> <?php if(!session_is_registered(myusername)){ $Submit = $_POST["Submit"]; if($Submit){ include("config.php"); $tbl_name="members"; $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $encrypted_mypassword=md5($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); echo "<meta http-equiv=\"refresh\" content=\"0\">"; } else { echo "<font color=white size=\"-1\"> Wrong Username or Password </font> <form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } else { echo "<form name=\"form1\" method=\"post\" action=\"\"> <input type=\"text\" name=\"myusername\" id=\"Username\" value=\"Username\" onblur=\"if(this.value.length == 0) this.value='Username';\" onclick=\"if(this.value == 'Username') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"password\" name=\"mypassword\" id=\"Password\" value=\"Password\" onblur=\"if(this.value.length == 0) this.value='Password';\" onclick=\"if(this.value == 'Password') this.value='';\" AUTOCOMPLETE=\"off\"> <input type=\"submit\" name=\"Submit\" value=\"Login\">"; } } else { $logout = $_GET["logout"]; if(isset($logout)){ unset($_SESSION['myusername']); echo "<meta http-equiv=\"refresh\" content=\"0\">"; } else { echo "<font color=white size=\"-1\"><a href=\"/admin_gallery\">Edit the Gallery page.</a> <a href=\"?logout\">Log Out</a></font>"; } } ?> </table> </table> Link to comment https://forums.phpfreaks.com/topic/133593-solved-help-log-in-script-doesnt-work/#findComment-695044 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.