Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

PHP not recognising include variables.?

<php

include "test.php";

$GLOBAL["TEST"] = "FooBar"

?>

---------

test php

<?php

$test=$GLOBAL["TEST"];

echo $test

?>

DOES NOT WORK. Why lol?

Update:

Thanks everyone.

@Kevy spot on, the global was declared after the include thus the value was not passed.

@cpcii No thats all the code there is, the index.php and test.php.

@mathew, umm thanks for taking the time to reply.

I just wanted to see how many people actually understood code, and kevy certainly does :)

Ill post another question and deliberately not pass the variable to a function, resulting in the variable never being passed.

3 Answers

Relevance
  • Anonymous
    5 years ago
    Favorite Answer

    Your include# is put before your TEST variable... so your code actually looks like this:

    $test=$GLOBAL["TEST"]; ### YOU CALLED $TEST before you created $TEST

    echo $test

    $GLOBAL["TEST"] = "FooBar" ### you created $TEST

    -----------------------------------------------------------

    Just put your Include below your Global $TEST

  • cpcii
    Lv 7
    5 years ago

    Are you calling the previous page or is this all in one page?

    Where are you defining the global test variable? In your php.ini? or earlier in the page?

  • Mathew
    Lv 4
    5 years ago

    Consult some one who is expert at this, he might help you and if you need some good security app you could get Leo Privacy Guard in order to secure all your apps with it.

Still have questions? Get your answers by asking now.