$PHP_SELF

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
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

$PHP_SELF

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

read through the $_SERVER superglobal documentation.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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">
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$_SERVER&#1111;'PHP_SELF'] . (!empty($_SERVER&#1111;'QUERY_STIRNG']) ? '?' . $_SERVER&#1111;'QUERY_STRING'] : '')
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
The Monkey
Forum Contributor
Posts: 168
Joined: Tue Mar 09, 2004 9:05 am
Location: Arkansas, USA

Post 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'] : '')
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

oops... typing too fast.. oh well..:roll:
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

which part are you referring to?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

The action attribute for the form.

Form shows up fine in firefox.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

...

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you talking about the hidden field named action? $_POST['action']
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply