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?

asked May 8, 2013 at 13:16
4
  • 2
    That's some strange way to do redirection... why in the world would you want to do it like that while there's so many ways to redirect was it client or server side ? Commented May 8, 2013 at 13:18
  • The code syntax coloring above should be a big clue for you. Commented May 8, 2013 at 13:18
  • What @Bartdude said -- have you considered simply doing <?php header('Location: http://www.google.com/'); ?> Commented May 8, 2013 at 13:19
  • Because this is one of rare ways to keep referer from the redirect page, isn't it? Commented May 9, 2013 at 0:02

2 Answers 2

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/");
answered May 8, 2013 at 13:17
Sign up to request clarification or add additional context in comments.

2 Comments

I could but what referrer would be in the first case? I mean referer the destination page would see.
Seems like there are problems with the second method with referer passing stackoverflow.com/questions/4762254/…
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>';
answered May 8, 2013 at 13:18

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.