Jump to content

[SOLVED] session not passing username string....


lookee

Recommended Posts

I've almost got my login script working, but for some reason the username string is not passing to my successful.php page.

 

Code

 

--------------------------------------------

 

<?php

session_start();

 

include 'config.php';

 

// Connect to server and select databse.

//mysql_connect("$host", "$username", "$password")or die("cannot connect");

//mysql_select_db("$db_name")or die("cannot select DB");

 

// username and password sent from form

$username=$_POST['username'];

$password=$_POST['password'];

 

// captures username & passwords, so they can be passed on to other pages

session_register("username");

 

$sql="SELECT * FROM nixon WHERE username='$username' and password='$password'";

$result=mysql_query($sql);

 

// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

 

// If result matches table row must be 1 row

if($count==1){

 

header("location: successful.php");

}

else {

header ("Location: again.html");

}

?>

 

------------------------

 

Any assistance would be of great help!  Thanks!

 

Link to comment
Share on other sites

basically session_register() is deprecated (reasons below), use:

$_SESSION['username'] = $username;

 

and please, PLEASE tell me this is simplified sample script right?

you are not actually taking $_POST variables, adding them directly to a session and then using them in an sql statement are you?  :o

 

quoted from PHP Manual:

Caution:

If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.

 

Note: register_globals: important note

As of PHP 4.2.0, the default value for the PHP directive register_globals is off, and it was completely removed as of PHP 6.0.0. The PHP community discourages developers from relying on this directive, and encourages the use of other means, such as the superglobals.

Link to comment
Share on other sites

Guest
This topic is now 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.