Jump to content

Header doesn't work on server


Baconian
 Share

Recommended Posts

hi guys, here i'm again!

soo this time i have a more complex question (i think). I made a simple form site who works fine on the local server (except the part of the email who never came!). I was trying to put the files on a server and use the email account that the server provide me to receive the emails from my form site, then i found a strange error, my headers functions don't work on the server (with 1 exception), after a few minutes on google i found some answers with .php but any of them work, soo here i'm asking for some light

 

 

here is one of the headers who doesn't work

$resultado = mysqli_query($conexao,$sql);if($resultado){	$_SESSION['usuario_logado'] = $linha['IDUSER'];	header('Location: test.php?info=User created and loged KEEP SAFE YOUR USERNAME');} 

and here is the only one who works

<?php	session_start();	if (!isset($_SESSION['usuario_logado'])) {		header('Location: home.html');		exit;	}?>//this verify if a user is loged

i tried to use ob_start(); but then i just have a blank page

if anyone can help me will be awesome!

Link to comment
Share on other sites

If the header isn't being sent then that means that the condition is not evaluating to true.

 

SESSION variables aren't saved when you call the location header because the script hasn't finished running before leaving the page. To save the variables before sending a location header use session_write_close()

Link to comment
Share on other sites

If the header isn't being sent then that means that the condition is not evaluating to true.

 

SESSION variables aren't saved when you call the location header because the script hasn't finished running before leaving the page. To save the variables before sending a location header use session_write_close()

 

 

i add a

echo("<h3>Let the carnage begin!</h3>");

on the begin of the file and the session_write_close() before reach the header, but still a blank page :/

$resultado = mysqli_query($conexao,$sql);if($resultado){	echo("<h3>Yeah!</h3>");	$_SESSION['usuario_logado'] = $user;	session_write_close();	header('Location: test.php?info=User created and loged KEEP SAFE YOUR USERNAME');}

so i tried use meta tags, apparently work, but i have a strange delay on the load of the pages

$resultado = mysqli_query($conexao,$sql);	if($resultado){	echo("<h3>Yeah!</h3>");	$_SESSION['usuario_logado'] = $user;	session_write_close();	//header('Location: test.php?info=User created and loged KEEP SAFE YOUR USERNAME');	?><meta http-equiv="refresh" content="0;url=http://www.mydomain.com/form_test/test.php?info=User%20created%20and%20loged%20KEEP%20SAFE%20YOUR%20USERNAME"><?php}

it's normal this delay? considering that are extremely light pages?

Edited by Baconian
Link to comment
Share on other sites

You can't print any content before sending a header. No echo, no HTML. Headers have to be sent before any other content.

 

There's no point in printing anything either, because once you redirect the page is gone.

Link to comment
Share on other sites

i removed all echos, var_dump and html, all seems to work now '-'

the delay persist but the headers are working.

 

and i put the echos to see if the condition is evaluating to true, 'cause the new users are on database soo the mysqli_query must return true

Link to comment
Share on other sites

The delay would be because the browser is sending a new HTTP request, there will always be a delay unless you have a really fast internet connection.

Link to comment
Share on other sites

thanks Ingolme :) and here are the last version of code thescientist

$resultado = mysqli_query($conexao,$sql);if($resultado){	$_SESSION['usuario_logado'] = $user;	session_write_close();	header('Location: test.php?info=User created and loged KEEP SAFE YOUR USERNAME');}

the only difference between the final version and the first version is the session_write_close() , i don't know if the SESSION variables can be source of my problem but all work now soo it's ok

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...