Login Script Not Working

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

Poomerio
Forum Newbie
Posts: 18
Joined: Tue Sep 04, 2007 4:38 am
Location: SE England

Login Script Not Working

Post by Poomerio »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi guys.

I'm making a login script for my forum software, but I'm having troubles.

First of all, I get this error in login.php:

Code: Select all

Notice: Undefined index: logged in C:\apache2triad\htdocs\easybb\login\login.php on line 15
login.php:

Code: Select all

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

if (is_dir ('../install'))
{
header('Location: ../install/error.php');
}
else
{
//Requires header
require("includes/header.php");

if (!$_COOKIE['logged'] == "*E5805F1AE06514B2C19FB2A223F3D0A27DB2F003")
{

  echo "<div id='starter'>
  <div class='border'>
	<div class='block'>
		<div class='bottom'>
  <h3>Login</h3>
		</div>
		<ol>
<form method='POST' action='do_login.php'>
Username:<br/>
<input type='text' name='user'>
<br /><br/>
Password:<br/>
<input type='password' name='pass'>

  		</ol>
  		</div>
  	</div>
  </div><br/>
<input type='image' src='img/btn_next.gif' border='0' alt='Submit'></form><br/><br/>";

}
else
{

  echo "<div id='starter'>
  <div class='border'>
	<div class='block'>
		<div class='bottom'>
  <h3>Login</h3>
		</div>
		<ol>
You must be <a href='../logout.php'>logged out</a> to login.
  		</ol>
  		</div>
  	</div>
  </div><br/>";

}

}

//Requires footer
require("includes/footer.php");

?>
Thanks,
- Poomie


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

you should use isset() first.
Poomerio
Forum Newbie
Posts: 18
Joined: Tue Sep 04, 2007 4:38 am
Location: SE England

Post by Poomerio »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Well I looked into header.php and took out a line of code, and now I don't get an error.

The next errors I get are on do_login.php:

Code: Select all

Warning: mysql_select_db(): 6 is not a valid MySQL-Link resource in C:\apache2triad\htdocs\easybb\login\do_login.php on line 30 Warning: mysql_query(): 6 is not a valid MySQL-Link resource in C:\apache2triad\htdocs\easybb\login\do_login.php on line 32
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\apache2triad\htdocs\easybb\login\do_login.php on line 35
Warning: mysql_close(): 6 is not a valid MySQL-Link resource in C:\apache2triad\htdocs\easybb\login\do_login.php on line 86
do_login.php:

Code: Select all

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

//Connects to database
require("../config.php");

$user = $_POST['user'];
$pass = $_POST['pass'];
$user = strtolower($user);

if (is_dir ('../install'))
{
header('Location: ../install/error.php');
}
else
{

if ($user == "" or $pass == "")
{
header('Location: login.php');
}
else
{

//Requires header
require("includes/header.php");

mysql_select_db($dbname,$connect);
$login_sql = "SELECT user_title, user_password FROM easybb_users WHERE user_title = '".$_POST['user']."' AND user_password = PASSWORD('".$_POST['pass']."')";
$login_res = mysql_query($login_sql,$connect);

//Get number of rows. Should be 1 if a match
if (mysql_num_rows($login_res) == 1)
{

//If a match, get values of username
while($info = mysql_fetch_array($login_res))
{
$user_title = stripslashes($info['user_title']);
}

//Set auth cookie
setcookie("logged", "*E5805F1AE06514B2C19FB2A223F3D0A27DB2F003", time()+86400);

  echo "<div id='starter'>
  <div class='border'>
	<div class='block'>
		<div class='bottom'>
  <h3>Login</h3>
		</div>
		<ol>
You have successfully logged in as '".$_POST['user']."'.
  		</ol>
  		</div>
  	</div>
  </div><br/>";

}
else
{

  echo "<div id='starter'>
  <div class='border'>
	<div class='block'>
		<div class='bottom'>
  <h3>Login</h3>
		</div>
		<ol>
You could not be logged in.
  		</ol>
  		</div>
  	</div>
  </div><br/>";

}

//Requires footer
require("includes/footer.php");

}
}

//Closes connection
mysql_close($connect);

?>
- Poomie


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Where is $connect coming from? Are you sure a successful mysql connection is established with mysql_connect() ?
Poomerio
Forum Newbie
Posts: 18
Joined: Tue Sep 04, 2007 4:38 am
Location: SE England

Post by Poomerio »

$connect should be defined as a MySQL database connection in ../config.php

- Poomie
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

You're checking for the existence of $_COOKIE['logged'] wrong.

Code: Select all

if(!$_COOKIE['logged'])
Should be:

Code: Select all

if(!isset($_COOKIE['logged']))
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Poomerio
Forum Newbie
Posts: 18
Joined: Tue Sep 04, 2007 4:38 am
Location: SE England

Post by Poomerio »

OK, well that fixed my login.php problem, now what about my do_login.php issue?

- Poomie
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

var_dump($connect);

see what that outputs.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Poomerio
Forum Newbie
Posts: 18
Joined: Tue Sep 04, 2007 4:38 am
Location: SE England

Post by Poomerio »

resource(3) of type (mysql link)
- Poomie
Poomerio
Forum Newbie
Posts: 18
Joined: Tue Sep 04, 2007 4:38 am
Location: SE England

Post by Poomerio »

So is there any more help available?

- Poomie
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

mysql_select_db($dbname, $connect);
Unless you're working with more than one database, the $connect parameter is optional in this piece of code. Try removing it and see if php uses your mysql link by default.

Somewhere along the line, $connect is getting screwed up.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Poomerio
Forum Newbie
Posts: 18
Joined: Tue Sep 04, 2007 4:38 am
Location: SE England

Post by Poomerio »

Tried that, and it makes no difference.

- Poomie
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Just include your database file source code in here. We cannot make correct assumptions about the database connection without seeing the code.

Make sure to not put your real passwords when you post it.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Poomerio
Forum Newbie
Posts: 18
Joined: Tue Sep 04, 2007 4:38 am
Location: SE England

Post by Poomerio »

Yeah, sure thing.

config.php:

Code: Select all

<?php
$dbhost = 'localhost';
$dbuser = '--------';
$dbpass = '--------';
$dbname = 'forum';
$forumname = 'EasyBB';

$connect = mysql_connect($dbhost,$dbuser,$dbpass,$dbname);
if (!$connect)
  {
  die('Could not connect ' . mysql_error());
  }
?>
Thanks,
- Poomie
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

$dbname in your mysql_connect() link is spawning a new link, i'm guessing, which is causing the errors.

Code: Select all

$connect = mysql_connect($dbhost,$dbuser,$dbpass);
Would be the correct way to connect, in your circumstance.

EDIT| Sorry, i forked that code. The code above should be correct now.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply