Jump to content

Need help with session in script


geloo
 Share

Recommended Posts

Hallo my problems is something with the session in my script as it redirects even when i logged in can someone help out please..

 

the code

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<title> </title> 

</head>
<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method ="post">
Username:<input type="text" name="username" />
Password:<input type="password" name="password" />
<input type="submit" name="submit" value="submit" />
</form>

<?php


$host = '---';
$user = '---';
$pass = '---';
$db = '---';


$connect = mysql_connect($host, $user, $pass) or die ('Could not connect');
$database = mysql_select_db($db) or die ('Could not connect');



$username = $_POST['username'];
$password = $_POST['password'];

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql= " SELECT * FROM Users WHERE  username= '".$username."' AND password = '".$password."' ";
$result = mysql_query($sql);




if(mysql_num_rows($result) == 1){

$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

header("location: login_succes.php");
}


?>

</body>
</html>

 

code login_succes.php

 

<?php
session_start();
if(!isset($_SESSION['username'])){

header('location: login.php'); 
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<title> </title> 

<link rel="stylesheet" href="stylesheet.css" type="text/css" />

</head>

<body>
login succesfull

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

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