Forum Moderators: coopster

Message Too Old, No Replies

PHPSelf

         

quozt

2:40 pm on May 3, 2004 (gmt 0)

10+ Year Member



im trying to use the same code on many of my pages im submitting a form that i want to refresh the page at the moment in action i have the page name but i continually have to change this for every page how would i use phpself or something in this context

<form action="add.php" method="post">

coopster

2:46 pm on May 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



<form action="<?php print $_SERVER['PHP_SELF'];?>" method="post">

quozt

3:01 pm on May 3, 2004 (gmt 0)

10+ Year Member



thanks for the help

StupidScript

9:09 pm on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or:

<form action="<?php echo $PHP_SELF?>" method="post">

jamesa

4:15 am on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or:

<form action="<?=$PHP_SELF?>" method="post">

:)

ergophobe

4:55 pm on May 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have to recommend against the last two versions. Unless you have an old or a non-default setup of PHP, this will not work and will throw a notice (requires register_globals on I believe).

Stick to $_SERVER['PHP_SELF'] and be safe!

Tom

jatar_k

6:09 pm on May 6, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the short tags version of coopster's is

<form action="<?= $_SERVER['PHP_SELF']?>" method="post">

and ergophobe and coopster are right, use the $_SERVER version

register_globals is always off by default now and shouldn't be turned on anyway.

StupidScript

6:06 pm on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not complaining...just commenting... :)

1) We're running PHP v.4.3.3 and having no problem with $PHP_SELF. We do have register_globals=on...see (2)...

2) We were having trouble keeping sessions active without register_globals=on. Why shouldn't we?

Thanks!

StupidScript

6:07 pm on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually...to give you the exact syntax we use:

<form action="<?echo $PHP_SELF?>" method=post>

Of course...it works fine with our configuration.

coopster

6:57 pm on May 7, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



We were having trouble keeping sessions active without register_globals=on. Why shouldn't we?

For security purposes. Here are some resources...

Preventing SQL inject commands! [webmasterworld.com]
Predefined variables [php.net]
Using Register Globals [php.net]