Jump to content

Login script problem


nicolette

Recommended Posts

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

//host name
$host = "localhost";
//mysql login info
$username = "root";
$password = "";
//DB info
$db_name = "syllabus";
//DB table info
$tbl_name = "syll";

//Connecting to server and selecting the DB
mysql_connect("$host", "$username","$password") or die ("cannot connect to the database");
mysql_select_db("$db_name") or die ("cannot select the database");

//send username and password from form
$user = $_POST['user'];
$pass = $_POST['pass'];

//protection for mysql
$user = stripslashes($user);
$pass = stripslashes($pass);
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);

$sql = "SELECT * FROM $tbl_name WHERE user='$user' and pass='$pass'";
$result = mysql_query($sql);

//Count rows
$count = mysql_num_rows($result);

// if there is a match there must be only one row
if ($count == 1)
{
	//register the session and redirect to next page
	session_register("user");
	session_register("pass");
	header("location:FinalPart5Form2.php");
}
else
{		
	echo "Invalid username $user or password $pass";
}
?>

 

I receive these errors:

Deprecated: Function session_register() is deprecated in C:\xampp\htdocs\FinalPart5ProcessForm1.php  on line 39

 

Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\FinalPart5ProcessForm1.php:39) in C:\xampp\htdocs\FinalPart5ProcessForm1.php on line 39

 

Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\FinalPart5ProcessForm1.php:39) in C:\xampp\htdocs\FinalPart5ProcessForm1.php on line 39

 

Deprecated: Function session_register() is deprecated in C:\xampp\htdocs\FinalPart5ProcessForm1.php on line 40

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\FinalPart5ProcessForm1.php:39) in C:\xampp\htdocs\FinalPart5ProcessForm1.php on line 41

 

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0

 

I have checked for whitespace and there is none but the first time i attempted to log in i spelled it wrong and got the echo statement "invalid blah blah..." does that cause this header problem?

 

I know that the session_register is depreciated and is now $_SESSION() i just haven't quite figured out how to use it.

 

Does anyone see the problem or is the session_register depreciation causing the header problems?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/206429-login-script-problem/
Share on other sites

You're getting the header problems because of the warning messages being sent to the screen.

 

To use the SESSION variables, you need to put

<?php
session_start()
?>

at the beginning of your code and then instead of

<?php
	session_register("user");
	session_register("pass");
?>

use

<?php
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
?>

 

To check whether they are set, use

<?php
if (isset($_SESSION['user']))
?>

 

Ken

//register the session and redirect to next page
	session_start();
	$_SESSION['user'] = $user;
	$_SESSION['pass'] = $pass;
	header("location:FinalPart5Form2.php");

 

ok so while I was waiting I played with the code and changed the session stuff it removed all the errors I was getting in the previous post but now i'm getting told that the redirect location  was not found on this server which i find interesting because i was just playing with that file

 

**ken you posted as I was typing this you said to do everything that i did so it is nice to know I was on the right track However I didn't know about the:

if (isset($_SESSION['user']))

would I do another one for the password?

 

anyway i'm off to play some more just thought I would post this for anyone else who was having the same problems. 

 

Nicolette

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.