php redirect syntax

Maxchen

New Member
Can any one help me with a little syntax problem i have.

Currently the code reads

PHP:
<?php
header("location:http://www.website.com/$row_rbs_redirect['redirect']");
exit;
?>

where the last part of the url is gathered from a recordset. The problem is in this area but i don't know what's wrong with it. I just inserted the code from the bindings panned in DreamWeaver.

thank you!
 

PrimaFacie

New Member
you can't use a variable within a string... your variable $row_rbs_redirect['redirect'] is not interpreted as a variable, but as a normal string!
the correct version is:

PHP:
<?php
header("location:http://www.website.com/".$row_rbs_redirect['redirect']);
exit;
?>
 

Jecht

New Member
No, you can! For arrays, you can't just write 'em, you need some {} around instead. Honestly i find this way more convenient than PrimaFacie's solution. Just a matter of habits...
PHP:
<?php
header("location:http://www.website.com/{$row_rbs_redirect['redirect']}");
exit;
?>

PS: works with not-arrays too
PHP:
<?php
echo "Bla bla bla {$myVar} bla bla";
?>
 
Last edited:
Top