Page 1 of 2

Login Script Not Working

Posted: Tue Sep 04, 2007 4:40 am
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]

Posted: Tue Sep 04, 2007 4:48 am
by miro_igov
you should use isset() first.

Posted: Tue Sep 04, 2007 5:07 am
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]

Posted: Tue Sep 04, 2007 5:25 am
by miro_igov
Where is $connect coming from? Are you sure a successful mysql connection is established with mysql_connect() ?

Posted: Tue Sep 04, 2007 7:27 am
by Poomerio
$connect should be defined as a MySQL database connection in ../config.php

- Poomie

Posted: Tue Sep 04, 2007 7:46 am
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']))

Posted: Tue Sep 04, 2007 7:57 am
by Poomerio
OK, well that fixed my login.php problem, now what about my do_login.php issue?

- Poomie

Posted: Tue Sep 04, 2007 8:12 am
by s.dot
var_dump($connect);

see what that outputs.

Posted: Tue Sep 04, 2007 8:17 am
by Poomerio
resource(3) of type (mysql link)
- Poomie

Posted: Fri Sep 07, 2007 2:30 pm
by Poomerio
So is there any more help available?

- Poomie

Posted: Fri Sep 07, 2007 2:34 pm
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.

Posted: Fri Sep 07, 2007 3:36 pm
by Poomerio
Tried that, and it makes no difference.

- Poomie

Posted: Fri Sep 07, 2007 3:40 pm
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.

Posted: Fri Sep 07, 2007 3:42 pm
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

Posted: Fri Sep 07, 2007 3:46 pm
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.