isset() Problem

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
User avatar
alsaffar
Forum Newbie
Posts: 16
Joined: Sun Sep 29, 2002 12:03 pm

isset() Problem

Post by alsaffar »

Hi there,

I have a page that have the following code:

<?
if (!isset($SID))
{
$SID = mt_rand();
echo $SID;
}
else
{
echo "SID already set";
}
?>

The problem is everytime I hit refresh button (F5) the variable is re-created! I want only to create that variable only if its the first time the user enter that page.

Please I appreciate your help.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Where does $SID come from?

Depending on the answer to the above this may help:
viewtopic.php?t=511

Mac
User avatar
alsaffar
Forum Newbie
Posts: 16
Joined: Sun Sep 29, 2002 12:03 pm

Post by alsaffar »

Forget that SID is SessionID, assume it any varibale (lets say ID) and I want this variable (ID) to be careated once, and when the user hit the refresh button (F5) it will not be re-created.

So the code will be:

<?
if (!isset($ID))
{
$ID = mt_rand();
echo $ID;
}
else
{
echo "ID already set";
}
?>

One more thing I dont want to use session_start() becuse this command requires a cookie, and maybe the user disabled the cookies on his/her PC.

Please I apreciate you help.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You have to have some way of creating a session variable that is uniquely linked to a client. You need to use sessions or cookies. Sessions can be used with cookies disabled as the session id can be passed through the URL.

Mac
User avatar
alsaffar
Forum Newbie
Posts: 16
Joined: Sun Sep 29, 2002 12:03 pm

Post by alsaffar »

I can't remember which PHP's version that my webHost is using, but what I can remember very good that the PHP's version that my webHost is using is if the cookie is disabled the variable will not be inserted in the URL automatically! from this point I dont want to use sessions.

So, is there is any way to stop re-creating (ID) variable everytime the user hit the refresh button?

I know that in PHP you can play around anything and implement your crazy idea:)
superwormy
Forum Commoner
Posts: 67
Joined: Fri Oct 04, 2002 9:25 am
Location: CT

Post by superwormy »

YOu need to have a way of identifying the client and setting the SID for that client, then having the client passign the SID to each page they visit.

You can only do this by setting a session cookie or generic cookie, or passing it through the URL.

If you don't do one of those things, then no, there is no way to stop it from recreating a new session each time.
Post Reply