Page 1 of 1

I need help with my login script

Posted: Sun Jun 29, 2014 3:40 am
by billyston
Hi guys, I have this login in scrpt. When logged in it should take the user to index.php but rather stops at process.php. All I want is the user to be redirected to index.php after entering the correct username and password. I have the session script in my classes folder and the process script is in the the root folder as the login.php and index.php. Below is my code

process.php function:

Code: Select all

function procLogin()
	   	{
	      	global $session, $form;
			
	      	/* Login attempt */
	      	$retval = $session -> login( $_POST['username'], $_POST['password'], isset( $_POST['remember'] ) );
			
	      	/* Login successful */
	      	if( $retval )
	      	{
				header(" Location: ".$session -> referrer );
	      	}
			
	      	/* Login failed */
	      	else
	      	{
	      		$_SESSION['value_array'] = $_POST;
	         	$_SESSION['error_array'] = $form -> getErrorArray();
	         	header(" Location: ".$session -> referrer );
	      	}
	   	}


session.php function:

Code: Select all

function startSession() 
   		{
      		global $database;  //The database connection
      		session_start();   //Tell PHP to start the session

      		/* Determine if user is logged in */
      		$this -> logged_in = $this -> checkLogin();

      		/**
       		* Set guest value to users not logged in, and update
       		* active guests table accordingly.
       		*/
      		if( !$this -> logged_in )
      		{
         		$this -> username = $_SESSION['username'] = GUEST_NAME;
         		$this -> userLevel = GUEST_LEVEL;
         		$database -> addActiveGuest( $_SERVER['REMOTE_ADDR'], $this -> time );
      		}
			
      		/* Update users last active timestamp */
      		else
      		{
         		$database -> addActiveUser( $this -> username, $this -> time );
      		}
      
      		/* Remove inactive visitors from database */
      		$database -> removeInactiveUsers();
      		$database -> removeInactiveGuests();
      
      		/* Set referrer page */
	      	if( isset( $_SESSION['url'] ) )
     		{
         		$this -> referrer = $_SESSION['url'];
	      	}
     		else
	      	{
         		$this -> referrer = "/";
	      	}

      		/* Set current url */
      		$this -> url = $_SESSION[ 'url' ] = $_SERVER[ 'PHP_SELF' ];
   		}


Re: I need help with my login script

Posted: Sun Jun 29, 2014 6:20 am
by Celauran
What do you mean "it stops at process.php"? What errors are being generated? Where?

Re: I need help with my login script

Posted: Mon Jun 30, 2014 6:32 pm
by techkid
billyston wrote:Hi guys, I have this login in scrpt. When logged in it should take the user to index.php but rather stops at process.php. All I want is the user to be redirected to index.php after entering the correct username and password. I have the session script in my classes folder and the process script is in the the root folder as the login.php and index.php. Below is my code

process.php function:

Code: Select all

function procLogin()
	   	{
	      	global $session, $form;
			
	      	/* Login attempt */
	      	$retval = $session -> login( $_POST['username'], $_POST['password'], isset( $_POST['remember'] ) );
			
	      	/* Login successful */
	      	if( $retval )
	      	{
				header(" Location: ".$session -> referrer );
	      	}
			
	      	/* Login failed */
	      	else
	      	{
	      		$_SESSION['value_array'] = $_POST;
	         	$_SESSION['error_array'] = $form -> getErrorArray();
	         	header(" Location: ".$session -> referrer );
	      	}
	   	}


session.php function:

Code: Select all

function startSession() 
   		{
      		global $database;  //The database connection
      		session_start();   //Tell PHP to start the session

      		/* Determine if user is logged in */
      		$this -> logged_in = $this -> checkLogin();

      		/**
       		* Set guest value to users not logged in, and update
       		* active guests table accordingly.
       		*/
      		if( !$this -> logged_in )
      		{
         		$this -> username = $_SESSION['username'] = GUEST_NAME;
         		$this -> userLevel = GUEST_LEVEL;
         		$database -> addActiveGuest( $_SERVER['REMOTE_ADDR'], $this -> time );
      		}
			
      		/* Update users last active timestamp */
      		else
      		{
         		$database -> addActiveUser( $this -> username, $this -> time );
      		}
      
      		/* Remove inactive visitors from database */
      		$database -> removeInactiveUsers();
      		$database -> removeInactiveGuests();
      
      		/* Set referrer page */
	      	if( isset( $_SESSION['url'] ) )
     		{
         		$this -> referrer = $_SESSION['url'];
	      	}
     		else
	      	{
         		$this -> referrer = "/";
	      	}

      		/* Set current url */
      		$this -> url = $_SESSION[ 'url' ] = $_SERVER[ 'PHP_SELF' ];
   		}

We need more information to debug. Did you try header(" Location: index.php"); instead of header(" Location: ".$session -> referrer );. Also can you post the code of your login function ($session->login). Did you add return true to the end of $session -> login?.