I want to use sessions to identify if a user is signed in.
If user is signed in they should be directed to their own profile.
If the user is not signed in then the user should be taken to the login page.
on my header I have options
when user not logged in: Login and Register
when user is Logged in: My Account and Logout
I followed some tutorial and have bases sorted but the sessions dont seem to be working correctly.
check user log file (partial)
<?php
session_start();
include_once "connect_db.php";
$soption = '';
if (!isset($_SESSION['uid'])) {
if (!isset($_COOKIE['uidCookie'])) {
$soption = '<a href="http://www.mydomain.co.uk/registration.php">Register Account</a>
<a href="http://www.mydomain.co.uk/login.php">Log In</a>';
}
}
if (isset($_SESSION['uid'])) {
$uid = $_SESSION['uid'];
$username = $_SESSION['username'];
$soption = '<a href="http://www.mydomain.co.uk/profile.php?id=' . $uid . '">' . $username . '</a>
<a href="http://www.mydomain.co.uk/myaccount.php">Account</a>
<a href="http://www.mydomain.co.uk/logout.php">Log Out</a>';
Login Script Partial
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$uid = $row["uid"];
$_SESSION['uid'] = $uid;
$username = $row["username"];
$_SESSION['username'] = $username;
mysql_query("UPDATE user SET lastloggedin=now() WHERE uid='$uid' LIMIT 1");
}
if($remember == "yes"){
setcookie("uidCookie", $uid, time()+60*60*24*100);
setcookie("usernameCookie", $username, time()+60*60*24*100);
setcookie("passwordCookie", $password, time()+60*60*24*100);
}
header("location: profile.php?id=$uid");
exit();
I seem to get the following error:
Notice: Undefined index: uid in /home/forkitu1/public_html/login.php on line 35
Warning: Cannot modify header information - headers already sent by (output started at /home/forkitu1/public_html/login.php:35) in /home/forkitu1/public_html/login.php on line 49
Warning: Cannot modify header information - headers already sent by (output started at /home/forkitu1/public_html/login.php:35) in /home/forkitu1/public_html/login.php on line 50
Warning: Cannot modify header information - headers already sent by (output started at /home/forkitu1/public_html/login.php:35) in /home/forkitu1/public_html/login.php on line 51
Warning: Cannot modify header information - headers already sent by (output started at /home/forkitu1/public_html/login.php:35) in /home/forkitu1/public_html/login.php on line 54
Thanks in advance and sorry for the long post