I have a webpage with a form that collects an ID number. Within the page I have validation with PHP to make sure the number entered is in the right format.

What I need to do is, if validation is successful, pass that id number to a new php page that will perform a lookup.

My problem is that I'm not sure how to direct the validation php script to open the new page.

Does that make sense?



I assume you need to redirect the page. If the validation bit is before the headers (that is, before any text is sent, including a space " " to the browser) then you can use the header function with a Location like this:

header("Location: /folder1/folder2/index.php");

You can/should also be able to use GET variables as well:

header("Location: /folder1/folder2/get.php?something=a_value");

You can't send POST values over but you could always create a session if you want to pass data to this page.

Kieran :)

I might have to rethink my validation then. If I just use

header("Location: /folder1/folder2/index.php");

It doesn't pass on the variables from the form to the new page. And I'm not fond of:

header("Location: /folder1/folder2/get.php?something=a_value");

Because then it will have the form data in the URL which can be modified. Not very secure...

As I said, you can use a session.

Sessions are easy and secure, well I think they are secure, more secure than POST anyway....


   // YAY!  Redirect!
   /* Start session... */

   /* Add POST value to session variable */
   $_SESSION['something'] = $_POST['something'];

   /* Redirect */
   header("Location: /folder1/folder2/index.php");

Lookup page (example)

/* Start the session */
  // YAY!  PHP has the value that was sent in the form/validation page!
  echo "This is what you sent: ".$_SESSION['something']; // Example
  // Oh, no variable sent...
  echo "hmmm";

If you do this, remember to "destroy" the session when you are done, or at the end of the page when you don't want to use the variable(s) anymore.

/* Something like this */

NOTE: The session can be accessed by all pages on your site (with the same URL) and can be stored for a certain period of time. You should always destroy a session that you don't want to work with anymore.

Check out this tutorial for sessions if you need to: http://www.w3schools.com/PHP/php_sessions.asp that might make things a bit clearer.

Kieran :)

Hope this helps

I think you should mark this as solved if your problem is solved.

Member Avatar

Oh! We've got a piggybacker!