0

So, I've got a variable that is set when an array returns a value that is identical to a strong. it's the most complex thing I've dealt with. Now, I've just got one more goal.

See, my site is a Wordpress site. all these calculations are taking place in the header, but the code I want changed is in the footer. The answer I seem to draw, is that I need to make the variable into a global variable. I've been trying for a few hours, but I can't seem to get it right.

Can someone tell me what I need to do? I've tried solutions seen in other questions on here, but no solutions seem to work for me.

here is the code for the header. With this site, it broaches a popular series' core communities. To ensure the site remains largely undiscovered until launch, I've changed some URLs and IDs!

$message_array = file("http://www.example.com/wp-content/themes/mytheme/Subtitles.css", FILE_IGNORE_NEW_LINES);

$message = array_rand($message_array);

$GfCheck = '<audio id="audio" src="http://www.example.com/wp-content/uploads/2016/01/example.wav" preload="auto" ></audio><a onclick="test()"><img src="http://example.com/wp-content/uploads/2016/01/Gf.png" height="90px" alt="test" title="test"/></a>';

if ($message_array[$message] == $GfCheck) {
$Gf = "1";
$GLOBALS['Gf']
}
else { }

echo "$message_array[$message]";

And here is the code I have in the footer

if($GLOBALS['Gf'])  {echo "Text to add to footer"; } ?>

It is worth noting, the second I add the $GLOBALS to the header, any tests I have in there (my test to make sure the code actually detected the correct line) cease functioning, indicating the variable stops working. As such, the code as I've presented does not work, but if I remove the globals tag, it does work perfectly for the header alone. any idea what I can do?

1 Answer 1

1

You're not handling these well.

$GLOBALS['Gf']

That's not even proper syntax. You need to set it to something at least. What I would do, instead of a $GLOBALS is to use a constant, which is global to all scopes

if ($message_array[$message] == $GfCheck) {
    $Gf = "1";
    define('GFCHECK', '1');
}

Then, later in your code

if(defined('GFCHECK'))  {echo "Text to add to footer"; } ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Absolutely perfect! thanks a bunch! Also, with the $GLOBALS, that was only the first thing I found. thanks for showing me a better alternative! =)

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.