views:

49

answers:

3

I'm trying to make a page where, when a form is submitted, it returns to the page from where the form was called from. Normally, I'd just set the form action to basename($_SERVER['SCRIPT_NAME']); and it would work fine. The problem that I'm having is that the form on this page is now being called from a url like www.yaddayadda.com/article.php?id=4, so when I use $_SERVER['SCRIPT_NAME'] it only returns article.php. Is there anyway to make it return the variables after the script name as well?

A: 

You can add $_SERVER["QUERY_STRING"] or use $_SERVER["REQUEST_URI"] that combines both.

It's often useful to do a print_r($_SERVER); or phpinfo(); to find out what your specific environment has to offer in terms of server variables.

Pekka
A: 

Use $_SERVER['SCRIPT_NAME'].$_SERVER['QUERY_STRING'] or $_SERVER['REQUEST_URI'] as stated here.

neo
+1  A: 

You probably need $_SERVER['REQUEST_URI']. If you print_r() all $_SERVER variables, you'll see there're several good candidates. The main difference comes when your script goes through CGI, gateways or URL rewriting (such as Apache's mod_rewrite). I believe REQUEST_URI is pretty safe.

Álvaro G. Vicario