Jump to content

Recommended Posts

Hi, this script looks fine, but I can't figure out what is wrong. It must be something on the "checklogin.php" page. When I enter in the registered user and password, which is in the database ok, it says "wrong user or pass". I don't see what is wrong with the code. Any help greatly appreciated. Thank you.

 

Here is the main login page.

 

<!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>
</head>

<body>

<div align="center"><table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><div align="center"><strong>Member Login </strong></div></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</div>


</body>

</html>

 

that was the sign_in.php.  below is the checklogin.php

 

############### Code

<?php
$host		= " ";
$database 	= " ";
$username 	= " ";
$password 	= " ";
$tbl_name   = "users";
mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error());

mysql_select_db($database);

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$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("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

 

now here is the login success page but I never get there

 

############### Code

// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>

<html>
<body>
<p>Login Successful</p>
<p> </p>
<p>Welcome to the  members page. to log out click <a href="Logout.php">HERE. </a></p>
</body>
</html>

Thank you. I got errors from them, and I fixed the SHA1 problem. But the links you gave me do not offer an alternative. Do you know of an alternative way that I could do it please.

 

$_SESSION['myusername']=$myusername;
$_SESSION['mypassword']=$mypassword;
if(!isset($_SESSION['myusername']))

Thank you very much HDFilmMaker2112. That helped me get to the welcome page. It gives me the following warnings with this code though, headers already sent. Any more help I would be great . thanks.

 

EDIT: I found an answer but I don't know how to do it.

 

"In simple terms, you cannot have your header() [us3.php.net] function in the middle of a HTML page. You must find a way to have the header() [us3.php.net] function called before anything gets printed to the screen, including your HTML that you have before your PHP. "

 

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['myusername']=$myusername;
$_SESSION['mypassword']=$mypassword;
header("location:login_success.php");
}

if (!isset($_SESSION['myusername']))
{
echo "Wrong Username or Password";
}
?>

 

 

// Check if session is not registered , redirect back to main page. // Put this code in first line of web page.

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /hermes/bosweb/web173/b1739/login_success.php:5) in /hermes/bosweb/web173/b1739/login_success.php on line 6

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web173/b1739/public_html/login_success.php:5) in /hermes/bosweb/web173/b1739/public_html/login_success.php on line 6

 

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web173/b1739/public_html/login_success.php:5) in /hermes/bosweb/web173/b1739//public_html/login_success.php on line 8

 

Login Successful

Thank you very much HDFilmMaker2112!! Everything works now. I now have a completed registration and login system. very simple but works. I really need to study up on sessions and sql now. I got impatient learning the php syntax and just decided to rush into tutorials, and I managed to do pretty well, but it is kind of like getting into a sports car when you are only used to riding a bicycle. So I will try to read up more at the same time as the tutorials. But thanks for helping. Teaching myself php is the hardest thing I have ever tried to do, mainly because the lack of good php tutorials I find on the net. Most are old, poorly coded, or overly hard. But I will keep going. Thank you!

 

 

   

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.