Jump to content

Php Order Of Opperations

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 post
Share on other sites

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

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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