Need help passing a variable in PHP?

  • Thread starter Thread starter elven_rangers
  • Start date Start date
E

elven_rangers

Guest
It's not a 'scope' problem (at least not in the regular programming sense of the word).

As I can deduce, your install script works in multiple steps which are processed by the same script.

Now, at each step you need to pass on the name of the file as the use set it.

On step 1 (first if branch), you take the filename from the input where the user gives it (I assume). On that branch you can work with the $filename which you take from the $_POST array.

To have it on the second branch (which takes care of step 2 or something like that) you need to either place the $filename in session (see php.net about how to work with sessions, how to initialize them and put variables in them which you can later retrieve) OR add it to the url so that you can have it $_GET OR make a hidden input somewhere in the HTML output you have under the 1st branch so you can send it again by POST.
 
I'm creating an install script, and in one part of the script, the user inputs a path and filename, which creates and writes to a file.

My problem is that I need to open and read this file later on the script, but because the variables to the name the user set for the file is declared in a different scope, I can't access the name; nor can I change the scope it's declared in (the program won't work correctly if I do)

Does anyone know how I can retrieve the variables that are located in a different scope?

Below is a VERY compact version of the script, just to illustrate where I'm having issues

if(isset($_POST['1'])) {
$filename = $_POST['filename']; //the variable I need to retrieve
$path = $_POST['path'];
}
elseif($_GET['cont'] == 2) {
echo $filename; //can't retrieve variable contents in this scope
}
 
Back
Top