-3

I am looking for a PHP Script that can redirect users to specific and different URLS when they hit "Submit" button.

I can afford to have the URL Like

www(.)mydomain(.)com/form.php?id=www(.)rediectedurl(.)com

Now if the user clicks submit button it redirects him/her to www.redirecturl.com. So for multiple posts i can easily change the URL and it redirects differently?

I hope anyone can answer it.

Thanks

7
  • First, don't ask for free work. Second, just point the forms action to whatever URL you want. Commented Oct 5, 2013 at 0:31
  • java != javascript, and i dont see either one being used here Commented Oct 5, 2013 at 0:34
  • First, You are here to help, for free i think? Right?. Second, Not a good idea Commented Oct 5, 2013 at 0:34
  • This may be helpful stackoverflow.com/questions/2675580/… Commented Oct 5, 2013 at 0:34
  • Help, yes. Do all the work for you, no. Commented Oct 5, 2013 at 0:36

1 Answer 1

1

First you'll need to escape the "URL" types of characters in your domain.com URL so that PHP can properly read the second one as a parameter. So if you wanted to redirect to www.redirect.com?foo=bar, your main URL would look something like:

www.mydomain.com/form.php?id=www.redirect.com%3Ffoo%3Dbar

Now, form.php needs to do several things:

  • Read the parameter
  • Unescape it
  • Use PHP's built-in header() function to set the "Location" header to the unescaped parameter
    • Example: header("Location: www.redirect.com?foo=bar");

Hope that gets you started.

Sign up to request clarification or add additional context in comments.

6 Comments

I want it to be automatic. I don't want to Edit the Header again and again? Thanks for the help though.
Right. That's why you have the first two steps there. You need to read the parameter, unescape it, and then use that string with the header() call. Something like: header("Location: $url");
And what function, I will be using to call $url as "ww.redirect.com?foo=bar"?
Use $_GET to get the parameters and their values. Then you can use urlencode() and urldecode() to swap between the encoded/unencoded values for that parameter.
Tried using few. none worked.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.