0

I'm trying to avoid a PHP script becoming too big and plan to create a file that will do some related tasks. My problem is that values submitted in a form are required in both and I'm not sure what the best approach to share data is.

After a user registers the form data is submitted to process.php which adds the data to the database and checks for duplicates. I'm now adding e-mail verification. I want everything to do with e-mail verification to be in it's own file, call it verify.php. Since both process.php and verify.php require data from the submitted form (e.g. username, e-mail address) what's the best way to share data? Here possible solutions I thought

  1. Have the form submit to both process.php and verify.php (not sure if this is possible)
  2. Have process.php include verify.php
    • in PHP would this automatically include the variables $_GET and $_POST from process.php?
  3. After process.php finishes use a redirect header to go to verify.php and somehow pass it the form data

Generally speaking should including files be avoided?

Celeritas
  • 14,489
  • 36
  • 113
  • 194

3 Answers3

1

Store the form data in $_SESSION and set it to expire after a given time period.

Joseph Persico
  • 602
  • 7
  • 20
1

I'd be inclined to include verify.php. Put the code there in functions and call them from process.php.

1

2- Have process.php include verify.php

This is correct option, you can do something like this:

verify.php

Contains validation function such as:

function email_validation($email){
 //
}

Then you can send the argument like this:

if(email_validation($_GET['email'])){
 //
}

Don't use global $var and $GLOBALS['var'] because Are global variables in PHP considered bad practice? If so, why?

Community
  • 1
  • 1