Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with PHP_SELF and refreshing

Status
Not open for further replies.

hpicken

Technical User
Apr 12, 2001
142
AU
I'm running php 4.2.3 on Apache 1.3.27 on FBSD4.7.

I just moved some scripts from and old server with "register_globals" on to this one with the rgs turned off.

I'm trying to get my head around the new variable format Some times I feel really old as I can't seem to understand it.

The snip below works OK with rgs on but goes into an endless loop continously adding records to the DB with them off. I've tries playing with the $_[*] declarations but can't work it out.

Can someone give me a hand here please?

TIA

Howard


<snip>

if ($uid != &quot;&quot;) {
$result=mysql(&quot;$DBName&quot;,&quot;SELECT * FROM Users WHERE User='$uid'&quot;);
$num=mysql_num_rows($result);
if ($num == &quot;0&quot;) {
$dt=date(&quot;YmdHi&quot;);
$uid=&quot;$dt$ip&quot;;
$date=date(&quot;z&quot;);
mysql(&quot;$DBName&quot;,&quot;INSERT INTO Users VALUES ('$uid','$date')&quot;);
Header(&quot;Location: $PHP_SELF?UID=&quot;.$uid);
}
}

if ($uid == &quot;&quot;) {
$dt=date(&quot;YmdHi&quot;);
$uid=&quot;$dt$ip&quot;;
$date=date(&quot;z&quot;);
mysql(&quot;$DBName&quot;,&quot;INSERT INTO Users VALUES ('$uid','$date')&quot;);
Header(&quot;Location: $PHP_SELF?UID=&quot;.$uid);
}

<snip>
 
why r u again coming to the same page after inserting a record?

if uid is empty it goes into if ($uid == &quot;&quot;) { condition ,
inserts the record in databse and again comes to the same page using header() with uid value empty, and stucks in the loop.



--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Basically the code is from on on-line ordering system modified from sample code by Christopher Ostmo of Rosenet Internet Services (MyCart).

The system is simple and easy to modify, does exactly what I need and works fine with register globals on.

This first page simply checks to see if the visitor has a session id (not a PHP session ID but a mysql one). If they don't have one, assign it, when/if they have one continue on with the rest of the page.

The problem is my understanding of the new global variables (or lack of).

Howard
 
ok,
php variables r case sensitive.
so u have to pass the variable exactly the same as u r checking for it..

either check with if ($UID == &quot;&quot;) //UID caps
or pass the variable as
Header(&quot;Location: $PHP_SELF?uid=&quot;.$uid);

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Sorry... That was a typo. All uid's are in lowercase.

The problem is definately the fact that when the header is sent to SELF the info is there (I've commented out the Header and placed an echo which returns that correct var info). But when the page is reread it's not picking up the uid variable so it sets it again and the whole process keeps looping.

Howard
 
HA! fixed it. Ended up doing this

global $uid;

if (isset($_GET[&quot;uid&quot;])) {
$uid = $_GET[&quot;uid&quot;];
}

if ($uid != &quot;&quot;) {
$result=mysql(&quot;$DBName&quot;,&quot;SELECT * FROM Users WHERE User='$uid'&quot;);
$num=mysql_num_rows($result);
if ($num == &quot;0&quot;) {
$dt=date(&quot;YmdHi&quot;);
$uid=&quot;$dt$ip&quot;;
$date=date(&quot;z&quot;);
mysql(&quot;$DBName&quot;,&quot;INSERT INTO Users VALUES ('$uid','$date')&quot;);
Header(&quot;Location: &quot;.$HTTP_SERVER_VAR[PHP_SELF].&quot;?uid=&quot;.$uid);
}
}

if ($uid == &quot;&quot;) {
$dt=date(&quot;YmdHi&quot;);
$uid=&quot;$dt$ip&quot;;
$date=date(&quot;z&quot;);
mysql(&quot;$DBName&quot;,&quot;INSERT INTO Users VALUES ('$uid','$date')&quot;);
Header(&quot;Location: &quot;.$HTTP_SERVER_VAR[PHP_SELF].&quot;?uid=&quot;.$uid);
}

Thanks anyway spookie

Howard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top