I tried to make a simple login system and I am seriously stuck. The problem is with the sessions. When I press login, I am redirected at the login page. Now as far as I could see, a session is started in the login page.session_id() gives some number.
But the protected page shows NULL. How to start the session on the protected page? I tried to implement some code of some examples - still redirects to login page. I tried with new empty page,just the form on the page but with the same db and still redirects to login page.
This is the login page
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
require('dbcon.php');
if (isset($_POST['email']) && ($_POST['password'])) {
$e = mysqli_real_escape_string($dbcon, $_POST['email']);
$p = mysqli_real_escape_string($dbcon, $_POST['password']);
$q = "SELECT uid,mail,psword,unm FROM pics WHERE (mail='$e' AND psword=SHA1('$p'))";
$result = mysqli_query($dbcon,$q);
if(mysqli_num_rows($result) == 1){
session_start();
$uid = mysqli_fetch_array ($result, MYSQLI_ASSOC);
$_SESSION['uid'] = $uid['uid'];
header("location: members.php");
exit();
mysqli_free_result($result);
mysqli_close($dbcon);
}else{
echo 'no match';
}
}else{
echo 'Empty fields...';
}
}
?>
And this is on top of the "protected" page
<?php
session_start();
if(!isset($_SESSION['uid'])){
header("Location:index.php");
}
?>
session info
session
Session Support enabled
Registered save handlers files user
Registered serializer handlers php_serialize php php_binary wddx
Directive Local Value Master Value
session.auto_start Off Off
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path C:\xampp\tmp C:\xampp\tmp
session.serialize_handler php php
session.upload_progress.cleanup On On
session.upload_progress.enabled On On
session.upload_progress.freq 1% 1%
session.upload_progress.min_freq 1 1
session.upload_progress.name PHP_SESSION_UPLOAD_PROGRESS PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefix upload_progress_ upload_progress_
session.use_cookies On On
session.use_only_cookies On On
session.use_strict_mode Off Off
session.use_trans_sid 0 0