Jump to content

PHP Login System Not Working


Trekky1700

Recommended Posts

Hi everyone,

 

I'm having a problem with part of a login code.

 

When I try to login, rather than redirecting to the index page like it's told, it just stays on the blank "login.php" file.

 

Could some nice person tell me what I'm doing wrong?

 

<?php
session_start();
session_regenerate_id ();

include ("dbconnect.php");

$user=$_POST['user'];
$pass=$_POST['pass'];
$title=$_POST['title'];

if(isset($user) && isset($pass))
{
	if (isset($_SESSION["logged_in_".$title]) && $_SESSION["logged_in_".$title] == $user) {
		echo $user.", you are already logged in.<BR><BR>";
		exit;
	}

    $connection = new db();
    $connection->connect();

    $result = mysql_query("SELECT username,password FROM mobagi_".$title." WHERE username='".$user."' AND
                          password=sha1('".$pass."') ");
  if(!$result)
  {
      echo "An error occured while querying database";
      exit;
  }
  if(mysql_num_rows($result)>0)
  {
      $_SESSION["logged_in_".$title]=$user;
      session_register("logged_in_".$title);
      header("Location:index.php");

  }
  else
  {
      header("Location:index.php");
  }

    $connection->close();
}
else if ($user || $pass)
{
    echo "Please fill in both fields.";
}
?>

 

Thanks  ;D

Link to comment
Share on other sites

Don't use session_register. The PHP manual says:

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

Just doing

<?php
$_SESSION["logged_in_".$title]=$user;
?>

is fine.

 

As for your problem, try changing:

<?php
    $result = mysql_query("SELECT username,password FROM mobagi_".$title." WHERE username='".$user."' AND
                          password=sha1('".$pass."') ");
  if(!$result)
  {
      echo "An error occured while querying database";
      exit;
  }
?>

to

<?php
    $query = "SELECT username,password FROM mobagi_".$title." WHERE username='".$user."' AND
                          password=sha1('".$pass."') ";
    $result = mysql_query($query) or die("An error occured while querying database, query: $query<br>" . mysql_error());
?>

and see if an error gets issued.

 

Ken

 

Link to comment
Share on other sites

No error was issued, it just keeps going to a blank screen (the login.php file). It does the same if I enter the wrong password too.

 

Is there any other code I should include, such as the login box code or the database info?

 

Link to comment
Share on other sites

Ok, apperently none of the scripts on the page are running. I just tried filling out 1 out of the 2 boxes on my login, and it still displays blank. Here's my current code.

 

<?php
session_start();
session_regenerate_id ();

include ("dbconnect.php");

$user=$_POST['username'];
$pass=$_POST['password'];
$title=$_POST['accounttype'];

if(isset($user) && isset($pass))
{
	if (isset($_SESSION["logged_in_".$title]) && $_SESSION["logged_in_".$title] == $user) {
		echo $user.", you are already logged in.<BR><BR>";
		exit;
	}

    $connection = new db();
    $connection->connect();

    $query = "SELECT username,password FROM ".$title." WHERE username='".$user."' AND
                          password=sha1('".$pass."') ";
    $result = mysql_query($query) or die("An error occured while querying database, query: $query<br>" . mysql_error());

  if(mysql_num_rows($result)>0)
  {
      $_SESSION["logged_in_".$title]=$user;
      header("Location:index.php");

  }
  else
  {
      header("Location:register.php");
  }

    $connection->close();
}
else if ($user || $pass)
{
    echo "Please fill in both fields.";
}
?>

Link to comment
Share on other sites

Are you debugging this code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that ALL the errors php detects will be reported and displayed?

 

Current Error Settings:

 

; display_errors

;  Default Value: On

;  Development Value: On

;  Production Value: Off

 

; display_startup_errors

;  Default Value: On

;  Development Value: On

;  Production Value: Off

 

; error_reporting

;  Default Value: E_ALL & ~E_NOTICE

;  Development Value: E_ALL | E_STRICT

;  Production Value: E_ALL & ~E_DEPRECATED

 

; html_errors

;  Default Value: On

;  Development Value: On

;  Production value: Off

 

; log_errors

;  Default Value: On

;  Development Value: On

;  Production Value: On

Link to comment
Share on other sites

Those are all comments and don't tell use the current settings on your system.

 

Ken

 

Thanks everyone for the help, ended up going through every scrap of code I had written prior, and it turened out to be a tiny spelling difference in another file associated to the login process. Sorry for wasting anyones time! :-[

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.