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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LeonelAG
Forum Newbie
Posts: 1
Joined: Thu Sep 05, 2002 3:42 pm
Contact:

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

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Code: Select all

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