Welcome to WebmasterWorld Guest from 34.204.191.31

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHPSelf

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

Junior Member

10+ Year Member

joined:Apr 11, 2004
posts:71
votes: 0


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">

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

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12555
votes: 3


<form action="<?php print $_SERVER['PHP_SELF'];?>" method="post">
3:01 pm on May 3, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 11, 2004
posts:71
votes: 0


thanks for the help
9:09 pm on May 5, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 20, 2004
posts:1477
votes: 0


Or:

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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2002
posts:710
votes: 0


Or:

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

:)

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

Senior Member

WebmasterWorld Senior Member ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8639
votes: 283


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

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

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 20, 2004
posts:1477
votes: 0


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!

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 20, 2004
posts:1477
votes: 0


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

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

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

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

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12555
votes: 3


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]