So I have a index.php file that has all of my html code in it. It includes store.php in the same directory. store.php just serves to grab the folder name the store.php is in. $variable1=basename(getcwd()); It also includes process.php in another directory. I need to automatically pass $variable1 to the process.php but it isnt working right. Any ideas what I'm doing wrong?
Yes...actually I just figured it out. $currentdirectory= basename(getcwd()); $_SESSION['sellerID']= $currentdirectory; $sellerID= $_SESSION['sellerID']; include /home/test.php then retrieved it in the test.php $sellerID= $_SESSION['sellerID'];
This does not look right. although this will technically work, it is not the right way of doing it. I am guessing that you are using '$sellerID' in a function? if you do <?php // in file1.php $sellerID = 'This is my seller id'; include( 'file2.php' ); ?> ... // file2.php <?php echo $sellerID; ?> PHP: and that should work, (you should see 'This is my seller id'). But if $sellerID is in a function in either file then you will need to add global $sellerID; PHP: in front. FFMG
arent globals bad? if you need to pass stuff from a function cant you just add it like exampleFunction($sellerID)
It really depends on the code. Without seeing the OPs code we cannot tell. But using a super global, ($_SESSION), to pass data around is even worse. FFMG