Jump to content

php header() help


black_pearl
Go to solution Solved by iarp,

Recommended Posts

hey guys,

 

i have just uploaded my website online and the headers seems to be broken whenever i login it has to normally redirect me to the home page but it just jam there and nothing happens and i have to refresh the page or go to the home page on my own

 

and on my localhost they work fine no problem at all and i am using the same code nothing has changed 

 

someone told me it might be coz of the php version on my localhost i have 5.5.12 and online its 5.5.27

 

 

code : 

<?php
class LoginController {
	public function __construct() {
	}
	public function run() {
		// if user already connected redirect to user home page
		if (!empty ( $_SESSION ['authentification'] )){
			header ( 'Location: index.php?action=home' );
			die ();
		}
		
		// initial notification
		$notification = '';
		
		if (! empty ( $_POST )) {
				
			if (empty ( $_POST ['username'] ) && empty ( $_POST ['password'] )) {
				$notification = 'Entrez un login et mot de passe non vides.';
			} elseif (empty ( $_POST ['username'] )) {
				$notification = 'Entrez un login non vide.';
			} elseif (empty ( $_POST ['password'] )) {
				$notification = 'Entrez un mot de passe non vide.';
			} elseif (preg_match ( '/^[a-z]{4,5}$/', $_POST ['username'] )) {
				
				$login = htmlentities ( $_POST ['username'] );
				$password = htmlentities ( $_POST ['password'] );
				
				if (Db::getInstance ()->login_exists ( $login )) {			
					// authentication
					if (Db::getInstance ()->authentication ( $login, $password )) {
						// create session username and copy login
						$_SESSION ['login'] = $login;
						$_SESSION ['authentification'] = 'admin';
						// Redirection HTTP to home page
						header ( 'Location: index.php?action=home' );
						die ();						
					}
				}
				
				// in case login doesn't exist in db or incorrect paswsord
				$notification = 'Nom d\'utilisateur et/ou mot de passe incorrecte(s).';
			} else { // in case login doesn't match preg_match
				$notification = 'Nom d\'utilisateur et/ou mot de passe incorrecte(s).';
			}
		}
		
		
		// view : login.php
		require_once (VIEWS_PATH . 'login.php');
	}
	
}
?>
Edited by black_pearl
Link to comment
Share on other sites

  • Solution

You most likely cannot see any errors as display_errors = Off within your php.ini

 

Try adding the code below to the top of that script, or whatever script you're getting a blank page on.

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
Link to comment
Share on other sites

hey iarp i tried the code and it gives me this error

 

Warning: Cannot modify header information - headers already sent by (output started at /customers/8/c/6/bemotors.be/httpd.www/views/header.php:7) in /customers/8/c/6/bemotors.be/httpd.www/controllers/LoginController.php on line 39

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.