-2

I am trying to do a header redirect using script.I am not well versed with PHP/JS but i can make out there is some syntax error which i am not able to troubleshoot. Following is the code. Experts, please help.

<?php $sendvar = "?subject=".$subjectfromemail."&from=".=$from."&message=".$messagefromemail."&wrong_code=true";
echo "<script type='text/javascript'>
window.top.location='$_SERVER['HTTP_REFERER']+$sendvar';
</script>"; exit;?>
user2852960
  • 63
  • 1
  • 7
  • There is a lot of help here: http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php – user2182349 Oct 28 '15 at 01:39

3 Answers3

1

You can do redirect using PHP itself.

How to make a redirect in PHP?

$sendvar = "?subject=".$subjectfromemail."&from=".=$from."&message=".$messagefromemail."&wrong_code=true";
header("Location:". $_SERVER['HTTP_REFERER'].$sendvar);
die();
Community
  • 1
  • 1
Deshan
  • 2,112
  • 25
  • 29
0

to be able to use an array value inside of a string, please enclose it with curly brackets like this:

<?php $sendvar = "?subject=".$subjectfromemail."&from=".=$from."&message=".$messagefromemail."&wrong_code=true";
echo "<script type='text/javascript'>
window.top.location='{$_SERVER['HTTP_REFERER']}+$sendvar';
</script>"; exit;?>

Regards,

Stefan

Stefan Dochow
  • 1,454
  • 1
  • 10
  • 11
  • This worked. I had to do couple of modification to finally get it functional. window.top.location='{$_SERVER['HTTP_REFERER']}$sendvar'; "; exit;?> Thanks Stefan! – user2852960 Oct 28 '15 at 02:33
0

Or a clearer way :

<?php
$sendvar = "?subject=".$subjectfromemail."&from=".=$from."&message=".$messagefromemail."&wrong_code=true";
echo "<script type='text/javascript'>
window.top.location='".$_SERVER['HTTP_REFERER'].$sendvar."';
</script>"; exit;
?>
Raphaël Vigée
  • 2,048
  • 14
  • 27