Matrix166
Matrix166

Reputation: 79

Using a variable value in <meta http-equiv="refresh" content=" url="/>?

Alright, in my PHP file I need the program to make a redirect from the middle of a big if-loop. I can successfully use the command to redirect to another page when I manually set the seconds, like:

echo '<meta http-equiv="refresh" content="2; url='www.google.com'"/>';

However, in the background I run a SQL-query, from where I get the refresh "rate". That value I have passed into a variable, and I want to use the variable value like this:

echo '<meta http-equiv="refresh" content="'.$refreshvalue.'; url='www.google.com'"/>';

I don't know where is the problem. In my program, everything works out as intended when I set the value manually, but when I try to get the value from the variable, the program simply does not execute the redirect.

The query gives me the correct value, and I can pass it to variable. But there's something wrong in the syntax, I assume. I've tried couple of other ways.

Also, if you have a simple alternative to using 'meta' or php function header(), I'm more than interested to hear about it.

Is my syntax wrong, or what's up here?

Upvotes: 1

Views: 3239

Answers (2)

Nic3500
Nic3500

Reputation: 8611

You have a quoting problem. Change it to this:

echo "<meta http-equiv=\"refresh\" content=\"" . $refreshvalue . "; url=http://www.google.com/\">";    

As presented in your question, you are closing your string just before www.google.com with the ' Note also the addition of http:// in front.

Upvotes: 0

Philipp
Philipp

Reputation: 15629

Are you sure, $refreshvalue contains an valid integer value and all quotes are correctly escaped? It should look something like this

$refreshvalue = 2;
echo '<meta http-equiv="refresh" content="' . $refreshvalue . '; url=\'http://www.google.com\'"/>';

Upvotes: 1

Related Questions