log in authntication

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sloppyjoe
Forum Newbie
Posts: 20
Joined: Thu Jul 09, 2009 3:43 pm

log in authntication

Post by sloppyjoe »

Hi.

Im having trouble gettin my log in to authenticate.

I've been going over it racking my head and i cant see why.

I have the log in form in HTML which i cant see there would be a problem there

Code: Select all

 
<!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" xml:lang="en" lang="en">
 
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta name="author" content="Fred!" />
 
    <title>Log in</title>
</head>
 
<body></body>
    <FONT FACE="Arial, Helvetica, Geneva">
 
 
Please enter your user log in details here...<br><br>
 
<form action = "authenticate.php" method = "post">
 
Username: <br>
<input type = "text" name = "username">
<br><br>
Password: <br>
<input type = "password" name = "password"> 
<br><br>
<input type = "submit" value = "Log In">
 
</form>
 
</font>
</body>
</html>
 
The problem is in the authenticate.php

Code: Select all

 
 
<?php
  //include("header.php");
 
  //can we use mysql?
  if(!function_exists('mysql_connect')) die("MySQL extension not enabled");
 
  //connect to mysql server
  $conn =@mysql_pconnect('************', '*********', '*******') or die(mysql_error());
  mysql_select_db('b11_4059953_db1') or die(mysql_error());
 
  //find our script name
  $script = $_SERVER['PHP_SELF'];
  $referer = $_SERVER ['HTTP_REFERER']
  $username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : '';
  $password = (isset($_POST['password'])) ? mysql_real_escape_string($_POST['password']) : '';
  
  
  
  //if either form is empty return to login
  
  if ((!$username) or(!$password))
  
{
    header ("Location:$referer"); exit();
}
//create query
$sql="select * from users where username =\"$username\" and password =\"$password\"";
 
 
//execute the query
$rs = mysql_query ($sql, $conn) or die ("could not execute query")
 
//get number of rows
 
$num = mysql_numrows ( $rs );
 
//log in if match
 
if ($num !=0)
{
        
    $msg = "Welcome $username - you are logged in";
            
}
 
else
{
    
    header ("Location:$referer"); exit();
    
}
?>
<html> <head> <title> Logged in </title> </head>
<body>
<?php echo ( $msg );
 
?>
</body>
</html>
 

Please excuse my sloppy indentation.

The problem is after logging in the page just goes to a blank screen.
Can anyone see why?
I appreciate all help.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: log in authntication

Post by jackpf »

Have you turned on error reporting? If you're getting a blank page then there's probably some error that you can't see.
sloppyjoe
Forum Newbie
Posts: 20
Joined: Thu Jul 09, 2009 3:43 pm

Re: log in authntication

Post by sloppyjoe »

i added this

Code: Select all

 
 
ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);
 
 
and still get a blank page
sloppyjoe
Forum Newbie
Posts: 20
Joined: Thu Jul 09, 2009 3:43 pm

Re: log in authntication

Post by sloppyjoe »

i just tried this code

Code: Select all

 
<?php
if(isset($_POST['username'])) {
    $conn =@mysql_pconnect('******', '********', '**********') or die(mysql_error());
  mysql_select_db('b11_4059953_db1') or die(mysql_error());
   $sql ="SELECT * FROM user WHERE username = '".$_POST['username']."' AND password = '".$_POST['password']."'";
    
   $resultSet = pg_query($sql,$conn);
   $count = pg_num_rows($resultSet);
   
   if($count != 1) {
      
      echo "Wrong username or password";
      
   } else {
      
      echo "Successfully logged in";
   }
   
}
?>
 
error reporting is on, and still after filling out the login fields, i get a blank page :banghead:
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: log in authntication

Post by jackpf »

What does

Code: Select all

print_r($_POST);
display?
sloppyjoe
Forum Newbie
Posts: 20
Joined: Thu Jul 09, 2009 3:43 pm

Re: log in authntication

Post by sloppyjoe »

Thats not in my code :?:
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: log in authntication

Post by jackpf »

Exactly, so put it there :dubious:
Post Reply