Jump to content

[SOLVED] HELP: Log in script doesn't work!


dezkit

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

<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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.