Jump to content

How to know previous webpage after submitting form


blogfisher

Recommended Posts

Hello,

  I want to know the webpage to return back after submitting forms in php. MY application contains basically one php file e.g. info.php which shows users info 10 users data on one page. When user click on NEXT button it shows another 10 as info.php?next=1, info.php?next=2 ...

 

Page has a form code where i am taking basic inputs such as name, address, email etc. When user submit these data, i call a adddata.php file which add data to my database.

 

Now i want to know which webpage i have to go back. if form is submitted from info.php?next=1 or infor.php?next=5 ...then i should return to same page.

 

Is there any php function available to know the previous webpage from where form is submitted ?

 

Well, simple way is to pass page number 1,2... along with form data, however i would like to know is this possible without passing this info ?

submit the page to itself and put the php code at the top whenever the user clicks the next button the page will load again

 

or if you want to keep those files seperate then put this at the top of your form page

 

<?php
    include('adddata.php'); // or whatever the file that gets the 10 records
?>

If you do this:

var_dump($_SERVER);

Then view the page source you can view loads of useful information that can be used including what the page was that you just came from.

 

As Allan as posted, using a hidden input in your form can be used and you don't have to populate it with a $_GET, you can put whatever you want in there like a code for each page you want to reference. This can then be checked in the script handling the input.

 

Or as FaT3oYCG has said (which is what I do mixed with a check of $_SERVER)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.