Jump to content

Recommended Posts

I put this in my index.php:

 

session_start();

// If they don't visit index.php this variable won't be set.

$_SESSION['has_session'] = true;

 

to set the session...

 

Then in a php file I didn't want to allow direct access without going through index.php I used this:

 

session_start();

// Check if the variable has been set.

if(!isset($_SESSION['has_session']))

{

  // It hasn't, they must go to index.php.

  header('Location: http://' . getenv('HTTP_HOST') . '/', true, 302);

  exit();

}

 

 

 

However now I get this error:

 

The browser has stopped trying to retrieve the requested item. The site is redirecting the request in a way that will never complete.

 

Now I believe the first part is setting the session and the index.php should load no matter what... however it won't load now...

 

 

Link to comment
https://forums.phpfreaks.com/topic/116719-solved-php-session-question/
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.