Page 1 of 1

$PHP_SELF

Posted: Thu Feb 24, 2005 11:58 am
by s.dot
Is there a way I can preserve the state of the page (variables tacked on to the URL) while using $PHP_SELF ?

Posted: Thu Feb 24, 2005 11:59 am
by feyd
read through the $_SERVER superglobal documentation.

Posted: Thu Feb 24, 2005 12:13 pm
by s.dot
Okay, I got it to work, but it just feels weird using it. So I don't know if I'm doing it correctly

Code: Select all

<form action=<? echo $_SERVER&#1111;'PHP_SELF?QUERY_STRING']; ?> method="post">

Posted: Thu Feb 24, 2005 12:18 pm
by feyd

Code: Select all

$_SERVER&#1111;'PHP_SELF'] . (!empty($_SERVER&#1111;'QUERY_STIRNG']) ? '?' . $_SERVER&#1111;'QUERY_STRING'] : '')

Posted: Thu Feb 24, 2005 1:42 pm
by s.dot
feyd wrote:

Code: Select all

$_SERVER&#1111;'PHP_SELF'] . (!empty($_SERVER&#1111;'QUERY_STIRNG']) ? '?' . $_SERVER&#1111;'QUERY_STRING'] : '')
That works, but doesn't tack on the query string.

Posted: Thu Feb 24, 2005 2:19 pm
by The Monkey
scrotaye wrote:
feyd wrote:

Code: Select all

$_SERVER&#1111;'PHP_SELF'] . (!empty($_SERVER&#1111;'QUERY_STIRNG']) ? '?' . $_SERVER&#1111;'QUERY_STRING'] : '')
That works, but doesn't tack on the query string.
Typo in feyds' code.

Code: Select all

$_SERVER&#1111;'PHP_SELF'] . (!empty($_SERVER&#1111;'QUERY_STRING']) ? '?' . $_SERVER&#1111;'QUERY_STRING'] : '')

Posted: Thu Feb 24, 2005 2:27 pm
by feyd
oops... typing too fast.. oh well..:roll:

Posted: Fri Feb 25, 2005 12:18 am
by s.dot
Any reason why this works in IE, but not firefox?

Code: Select all

<form action="<? echo $_SERVER&#1111;'PHP_SELF'] . (!empty($_SERVER&#1111;'QUERY_STRING']) ? '?' . $_SERVER&#1111;'QUERY_STRING'] : ''); ?>" method="post">
		<input type="hidden" name="action" value="selectskin">
		<B>Skin: </B>
		<select name="skintoselect">
		<option>Select</option>
		<option value="cokacola">Coka-Cola</option>
		<option value="girlygirl">Girly Girl</option>
		<option value="grim">Grim</option>
		<option value="hellfire">HellFire</option>
		<option value="hunter">Hunter</option>
		<option value="lemonlime">Lemon-Lime</option>
		<option value="lightblue">Light Blue</option>
		<option value="default">Plain</option>
		<option value="skies">Skies</option>
		</select>
		<input type="submit" value="Go">
		</form>

Posted: Fri Feb 25, 2005 12:48 am
by feyd
which part are you referring to?

Posted: Fri Feb 25, 2005 12:57 am
by s.dot
The action attribute for the form.

Form shows up fine in firefox.

Posted: Fri Feb 25, 2005 1:01 am
by feyd
I don't know of anything that'd cause a problem.. what's not "working" in the action? Maybe you could post a link to your working copy?

...

Posted: Fri Feb 25, 2005 1:05 am
by s.dot
I can't do that... this is a "choose your skin" for members only. So to see it working you'd have to be a member. However I'll post the whole code.

Code: Select all

if($action == "selectskin")&#123;
$setskinsql = "UPDATE users SET skin = '$skintoselect' WHERE username = '".$_COOKIE&#1111;'username']."'";
mysql_query($setskinsql) or die(mysql_error()); &#125;

<form action="<? echo $_SERVER&#1111;'PHP_SELF'] . (!empty($_SERVER&#1111;'QUERY_STRING']) ? '?' . $_SERVER&#1111;'QUERY_STRING'] : ''); ?>" method="post"> 
      <input type="hidden" name="action" value="selectskin"> 
      <B>Skin: </B> 
      <select name="skintoselect"> 
      <option>Select</option> 
      <option value="cokacola">Coka-Cola</option> 
      <option value="girlygirl">Girly Girl</option> 
      <option value="grim">Grim</option> 
      <option value="hellfire">HellFire</option> 
      <option value="hunter">Hunter</option> 
      <option value="lemonlime">Lemon-Lime</option> 
      <option value="lightblue">Light Blue</option> 
      <option value="default">Plain</option> 
      <option value="skies">Skies</option> 
      </select> 
      <input type="submit" value="Go"> 
      </form>

Posted: Fri Feb 25, 2005 1:08 am
by feyd
are you talking about the hidden field named action? $_POST['action']

Posted: Fri Feb 25, 2005 1:22 am
by s.dot
Okay, that's something I've pondered alot about.

Is it okay if I just use $action instead of $_POST['action'] ?

I've never been too sure about this.

I've always just used the single variable, as this is how I learned it.

Every single query on my site is like this (well into the thousands). Everything appears to be working fine and I haven't had complaints from others.

Posted: Fri Feb 25, 2005 1:33 am
by feyd
if you have a newer version of php, > 4.2.0, register_globals is off by default. The $_POST style superglobals are needed to access the data.

you may want to read the documentation pages on register globals if you want to know more.