0

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?

Thanks.

4
Contributors
6
Replies
9
Views
6 Years
Discussion Span
Last Post by cableguy414
0

Hello,

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 :)

0

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...

0

As I said, you can use a session.

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

Example:
Form/validation...

if(isset($_POST['something']))
{
   // YAY!  Redirect!
   /* Start session... */
   session_start();

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

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

Lookup page (example)

/* Start the session */
session_start();
if(isset($_SESSION['something']))
{
  // YAY!  PHP has the value that was sent in the form/validation page!
  echo "This is what you sent: ".$_SESSION['something']; // Example
}
else
{
  // 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 */
session_destroy();
session_unset();

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

Edited by Kieran Y5: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.