0

I need help for my code when i login successfly i have error this is my code:

<?php
session_start();



$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="portfolio_baza"; // Database name
$tbl_name="skole_login"; // Table name

// 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
$email=$_POST['email'];
$login_pass=$_POST['login_pass'];

// To protect MySQL injection (more detail about MySQL injection)
$email = stripslashes($email);
$login_pass = stripslashes($login_pass);
$email = mysql_real_escape_string($email);
$login_pass = mysql_real_escape_string($login_pass);

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

$count=mysql_num_rows($result);


if($count==1){
session_register("email");
session_register("login_pass");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

error in this page login_success.php"

<?php
session_start();
if(!session_register(email)){ // error on line 3
header("location: adminskola.php");
}
?>

Login Successful
3
Contributors
5
Replies
38
Views
3 Years
Discussion Span
Last Post by gogs85
0

EDIT:

It's because you're trying to regiester a session. You should probably just use:

if(!isset($_SESSION['email']))
{
   // redirect
}

OR

if(!session_register($email)){ // error on line 3

Bleh. Please tell us what the purpose of 'login_success.php' is?

Edited by phorce

0

You shouldn't be using session_register as it is a depricated function. Just assign your session vaiables like

$_SESSION['email'] = $email;
$_SESSION['login_pass'] = $login_pass;

And then check the session is there as @phorce said by using

if(!isset($_SESSION['email'])) {

}

However there are also two other points I would like to make:

  1. Whay would you want to store a password in a session - highly unsafe and no need to

  2. I would suggest using a mulitiple session array so that you can add other variables if required at any time and then unset your session with just one call to the outer array key rather than having to go through and unset them all individually:

    $_SESSION['user']['email'] = $email;
    $_SESSION['user']['id'] = $id; // Just an example
    $_SESSION['user']['username'] = $username; // Just an example

    // To unset
    unset($_SESSION['user']);

    // Rather than
    unset($_SESSION['email'']);
    unset($_SESSION['id']);
    unset($_SESSION['username']);

0

Thanks! I login but how when i make this code for logout i have error
<?php
session_start();

session_destroy();

header("location:../index.php");
exit();
?>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.