Jump to content

[SOLVED] session problem


mike12255

Recommended Posts

Im making a sort of admin protected area on my site so after the user enters the info and clicks submit it runs this code:

 

<?php
include("Connect.php");

if(isset($_POST['submit'])){
$name = $_POST['name'];

$pass = md5($_POST['password']);


$sql = "SELECT * FROM accounts WHERE username = '$name' AND password = '$pass'";
$result = mysql_query($sql);
$row = mysql_num_rows($result);

if ($row > 0){
$_SESSION['user'] = $name;
header("Location: index.php");

}else{
header("Location: login.php");
}
}

?>

 

that runs fine and i get directed to the index.php page. When i click on one of the links to go to another page though it sends me back to the login page and acts as if there was no session. The code on these pages is:

 

<?php

session_start();
if (!$_SESSION['user']){
header("Location: login.php");
}
?>

 

anyone know why my users can login but not view the protected pages?

Link to comment
https://forums.phpfreaks.com/topic/161302-solved-session-problem/
Share on other sites

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.