Jump to content

php header() help


black_pearl

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');
	}
	
}
?>
Link to comment
https://forums.phpfreaks.com/topic/297565-php-header-help/
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
https://forums.phpfreaks.com/topic/297565-php-header-help/#findComment-1517863
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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