This may be a silly question, but I attempted to use the include() function to access variables from a different PHP file - however when I run it on local host I simply get redirected to the page I wanted to access variable scope from. How do I stop this from happening?
1 Answer
include() takes all the code from the file it points to and includes it in the file you called it from and executes that code before moving on to the next line of the original file.
Thus if the file you are including contains more than variable definitions .i.e. it contains code that would cause output you're going to see that output in the file you called include from.
Maybe split your variables in to a third file and and include() that in the other two files.
ob_startthenincludethenob_end_cleanif you don't want any output.includeis not a function. If theincluded file hasheader('LOCATION: '.$urlHere);, or something that redirects, then your other page will go to that page.