Page 1 of 1

Form: Submits to self on any page?

Posted: Fri Jun 11, 2004 12:40 pm
by jonas
I'm looking to work on my login script today for my site.... it is in the header of every page on my site.... check it out
http://www.bolt3.com/systems.php

So, the top right will be where they can login. So I know this is probably simple but I searched for a bit and haven't found a solid answer but how do I get the form to submit to itself regardless of what page it's on?

So if they login on systems.php it will submit to systems.php but if they are on forums.php it will know to submit to forums.php and not to systems.php

I'm putting the login check in the header so it will be on every page but I just need to know how to make a form submit to itself.

Is it PHP_SELF or something... I know it's probably quite easy. :roll: :roll: :lol:

Posted: Fri Jun 11, 2004 1:02 pm
by feyd
PHP_SELF should be it.. although it's not guaranteed to exist, so check your server variables to make sure it's there.. if it's not there, $_SERVER['SCRIPT_NAME'] should be there...

Posted: Fri Jun 11, 2004 7:29 pm
by Joe
<form action="" method="POST">

There is no need for PHP_SELF I don't think!

Posted: Fri Jun 11, 2004 8:12 pm
by feyd
true, in a lot of browsers... but I not entirely sure all browsers will work without action...

Posted: Fri Jun 11, 2004 8:32 pm
by andre_c
I use this:

Code: Select all

<form action="?">
( i don't know if it's correct to do that, but it works )

Posted: Fri Jun 11, 2004 11:41 pm
by RobertGonzalez
Use $_SERVER['PHP_SELF']...

In your PHP do something like...

Code: Select all

<?php
$form_action = $_SERVER['PHP_SELF'];
?>
... and call it like this ...

Code: Select all

&lt;form action="&lt;?= $form_action ?&gt;" method="post"&gt;
This is just one way (of many possible ways) to do this. Works pretty well for posting to the same script your app is running.

Something to remember (this may or may not affect your needs) but the PHP_SELF server variable always carries with it the leading forward slash and directory path from root, ie:

scriptname: myapp.php
location: root
PHP_SELF: /myapp.php

scriptname: otherapp.php
location: /test
PHP_SELF: /test/otherapp.php

Hope this helps :D