Page 1 of 1

How do I detect if it is the first time a user sees a page ?

Posted: Thu Sep 05, 2002 3:42 pm
by LeonelAG
Hi.
I´m having problems with authentication.

Suppose page A calls page B and B calls C. Like this.

A ==> B ==> C

In page B, I have to ask the user for his username and pw, so that C will show him his data. Every time user passes though page B, I have to ask for his username and password. This way, I can switch between users without leaving the environment.

I have tried this:

if (! $flag || !isset ($PHP_AUTH_USER) || ! isset ($PHP_AUTH_USER))
{
header('WWW-Authenticate: Basic realm="Here"');

session_register ("flag");
$flag = false;
}

Did not work. Maybe my session variables are not correctly registered ?

Thanks
Leonel

Posted: Fri Sep 06, 2002 1:48 am
by twigletmac
Have you put session_start() at the top of each page that needs to use or set session variables? Another thing you might try is instead of:

Code: Select all

session_register ("flag"); 
$flag = false;
If you have PHP 4.1 or above:

Code: Select all

$_SESSIONї'flag'] = false;
or if you have PHP 4.0.6 or below:

Code: Select all

$HTTP_SESSION_VARSї'flag'] = false
then you can prevent someone from putting a value for $flag in the URL's query string and authenticating themselves since flag is a fairly easy variable for someone to guess.

Mac

Posted: Fri Sep 06, 2002 10:41 am
by Takuma

Code: Select all

<?php
if (session_is_registered("flag")) {
  //user has revisited tha page
}
?>