开发者

How do you get a PHP page with arguments to point to itself?

I'm trying to make a page where, when a form is submitted, it returns to the pag开发者_运维问答e 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?


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜