开发者

PHP How can I send a SAFE url via POST so that after a php script has finished it can redirect back to the page it came from?

What is the best way to go back to a page where a form was submitted?

For example, if i send some data via POST to "save-data.php" and that file in turn uploads the posted data to a database how can i then return to the page that initially sent the POST data if the url is not known?

I'm not sure I have explained right.

MORE DETAIL:

the data is posted by an admin 开发者_如何学运维user only. Im using this code for an editable navigation bar stored in a database. The admin can edit the label and href then store it. The trouble is that it can be edited from any page in the site so long as you are logged in as an admin. When you hit a save button (on the same page as the navigation bar) it posts the data to a php script which inserts/updates the database. I just need to send the user back to the page where save was clicked.


If this is dynamic, you could pass a hidden input value:

<input type="hidden" name="return" value="myfile.php" />

Not a fan of this as it can be changed by the user. But I do stuff like that in my applications a lot but its more like this:

<input type="hidden" name="return_action" value="detailview" />

Then do a lot of stuff to validate the action and then permissions involved (larger conversation than this.)

If this is a static return and you control it, you can simply do this:

header('Location: myfile.php');
exit();

Just add that after your save and your fine.

Edit Sorry just noticed if the URL is not known. Do you control all parts? Which parts do you control and to what level? I am assuming your not just letting everyone post data to a URL?


You can do it with JavaScript:

window.onload = history.go(-1);

It's impossible to do in PHP. You need to know the referring URL to send someone there. $_SERVER['HTTP_REFERER'] may contain the referrer, but it's not guaranteed to be sent (some firewalls and browsers removes the referer header).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜