0

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?

2
  • You would have to show the file, if it is redirecting then it is in there or something. Probably ob_start then include then ob_end_clean if you don't want any output. Commented Dec 14, 2020 at 22:37
  • include is not a function. If the included file has header('LOCATION: '.$urlHere);, or something that redirects, then your other page will go to that page. Commented Dec 14, 2020 at 23:00

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.