Jump to content

Php Order Of Opperations


MrFish

Recommended Posts

I've written some functions for my forum to make it easier to handle users. I thought it was working fine until I checked the database and found that even if my script called to redirect an unlogged in user, all the other scripts in the code were ran.The function-

function checkUserStrict() //Checks if the visitor is logged in{	if(!isset($_SESSION["username"]))	{		$x = checkUser();		if($x == 0)			header( "Location: loginforms.php" );	}}

The page that calls the function-

	include("includes/universalfunctions.php");	checkUserStrict();	header( "Location: index.php" );

The function works fine, it will redirect me if I am not logged in. But I tested it by adding another redirect after the function. I immediately go to the index page when accessing this page. How do I tell the code to wait until it finishes the check.

Link to comment
Share on other sites

Setting a header won't cause the script to halt execution, you need to use exit() for that.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...