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

Recommended Answers

All 4 Replies

What's on Line 35 of your Login.php file?

What's on Line 35 of your Login.php file?

$uid = $row["uid"];   //line 35
session_register('uid'); 
$_SESSION['uid'] = $uid;
       
$username = $row["username"];   
session_register('username'); 
$_SESSION['username'] = $username;

Hi,
If I understand right, you have 2 files??
If this is correct have you a session_start() in your login.php?

if($login_check > 0){

what happends if == 0 ??

didier

Hi,
If I understand right, you have 2 files??
If this is correct have you a session_start() in your login.php?

if($login_check > 0){

what happends if == 0 ??

didier

login detail submitted doesn't exist in the database and error message will appear prompting to try again

else { // if login_check is equal to 0 they do not exist in my database
		    $errorMsg = "Incorrect login data, please try again";
		}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.