User submits username from p1.html, p2.php does the authorization work with db.php as required file and upon successful authorization, it directs the user to p3.php.
As seen, I have commented out the line require('../myDBFolder/db.php'); in p3.php because its not needed as I have already one open connection in p2.php. Because of commenting the above line, I am not able to retrieve some of the parameters like $connection and $table_name_data which are used in p3.php. And I have already read that storing connection parameter in session is not a good idea so not using that approach. Could anyone advise how can I adjust my variables to make sure they are available in p3.php and wherever needed.
These statements contradict one another.
Clearly the connection script is needed.
If you are concerned about including the connection any more times than necessary you could use require_once instead of just require.
There simply is no connection, because you commented out the connection script.
Ordinary variables only have scope within their âpageâ, so the connection is closed after p2 runs, so must be re-opened in p3.
Sorry for not being clear. Actually I am referring to the problems I have mentioned when I included the script. Attaching the screenshot to address my issue in a more clear manner:
Do the $_POST values remain after youâve done the header redirection from p2.php to p3.php? I thought theyâd only be kept as part of a form submit with POST method, and if thatâs the case, when you include db.php in p3.php, it effectively blanks out the session variable in the first couple of lines by setting it to a blank variable.
Remove the two lines in db.php that write into the session variable. Youâve already stored the value in p2.php, so thereâs no need to do it again. Move the relevant lines in p2.php to be before you include the db.php file and the variables should be populated by then.
Well, you will, because the $_POST is only populated with a form submission using the POST method. Not using a header redirect. Save what you need in session variables before you redirect from p2 to p3.
It does save the username session variable, but the $_POST array will be blank in p3. But you donât need the $_POST array any more, because youâve saved the username in the session variable.