0

Here is a script that i would like to use for redirection:

<form id="form1" method="post" action="http://yahoo.com">
<script language="javascript" type="text/javascript">
    document.getElementById('form1').submit();
</script>
</form>

Now I have to control it with a php code, but this one doesn't work:

 $redirect = '<form id="form1" method="post" action="http://google.com">
 <script language="javascript" type="text/javascript">
    document.getElementById('form1').submit();
 </script>
</form>' 

I guess there is a syntax error, but I am unable to figure it out. Please help.

Also let me know is it an ok redirect method that keeps the script execution page as referrer?

Zox
  • 203
  • 3
  • 8

2 Answers2

3

You are getting the ' wrong inside getElementById

$redirect = '<form id="form1" method="post" action="http://google.com">
 <script language="javascript" type="text/javascript">
    document.getElementById("form1").submit();
 </script>
</form>' 

By the way, this is a unusual way of doing the redirect. Why not use window.location.href instead?

Or a PHP header redirect?

header("Location: http://www.google.com/");
DrColossos
  • 12,656
  • 3
  • 46
  • 67
  • I could but what referrer would be in the first case? I mean referer the destination page would see. – Zox May 08 '13 at 13:48
  • Seems like there are problems with the second method with referer passing http://stackoverflow.com/questions/4762254/javascript-window-location-does-not-set-referer-in-the-request-header – Zox May 08 '13 at 13:53
1

Try this, you need to escape single quotes

$redirect = '<form id="form1" method="post" action="http://google.com"> <script language="javascript" type="text/javascript">
document.getElementById(\'form1\').submit(); </script></form>';
chandresh_cool
  • 11,753
  • 3
  • 30
  • 45