Dear all, I have 3 pages which go to the same page example add_user.php update_user.php delete_user.php all these pages go to: show_user.php I want to know in the "show_user.php" page where it comes from ? because based on the previous page I will deal in a different way. I wish I find a soon replay. Thank You in advance.
you can give your forms to different names. for example: name form "ok" for add_user.php and "ok1" to update_user.php on show_user.php do this: if (isset($_POST['ok])) { //code for add_user.php } PHP: if (isset($_POST['ok1])) { //code for update_user.php } PHP:
Another alternative is to add a hidden form value to each page. Example: <input type="hidden" name="page" value="page1"> And the just look at the value of "page" if($POST['page']=="page1") { //Code }
You can do that by checking the referer, something like: if(strstr($_SERVER['HTTP_REFERER'], "add_user.php")){ // do something for add_user.php } elseif(strstr($_SERVER['HTTP_REFERER'], "update_user.php")){ // do something for update_user.php } elseif(strstr($_SERVER['HTTP_REFERER'], "delete_user.php")){ //do something } else { // load default page } PHP:
Thanks all, I did something like the following <input type="hidden" value="add_user" name="source_file"> PHP: switch($_POST["source_file"]){ case 'add_user': {// do stuff addUser(); break; } case 'update_user': { // do stuff updateUser(); break; } case 'delete_user': { // do stuff echo "id: ".$_POST["id"]."<br>"; deleteUser($_POST["id"]); break; } } PHP: and the problem is solved. Thank God Thanks all
Never do this. Very bad advice. The HTTP_REFERER value is frequently empty. Almost every type of user privacy software/option will strip the value off the request.
He's submitting data from an html form, the HTTP_REFERER will return the page from where the data was submitted.
The value is sent from the browser posting the form. I'm not guessing here. I'm telling you from experience lol. Test it. Install nortons, or just turn on private browsing and see for yourself.
Ok no problem, Test the following code in your localhost... and let me know <form action="<?=$_SERVER['PHP_SELF'];?>" method="post"> <input type="submit" name="submit" value="Test!" /> </form> <?php if (isset($_POST['submit'])){ echo "Referer: ".$_SERVER['HTTP_REFERER']; } ?> PHP:
http://forums.asp.net/p/275968/3134828.aspx#3134828 http://codingforums.com/archive/index.php/t-7630.html http://www.webmasterworld.com/forum88/4108.htm http://karmak.org/2004/reftest/fix Not good enough? How about the php.net page on the _SERVER array? Trust that one? http://php.net/manual/en/reserved.variables.server.php I'm done arguing this with you, man. You use the value all you want. lol
Maybe, maybe not. You can't trust HTTP_REFERER for anything. Trusting it for security will let people abuse you. Trusting it for functionality will make your application break for at least some users. It's advisory and nothing else. The only decent use I've seen it put to is for making more informative 404 pages.