-4

How can I redirect a page to the user's localhost?

For example, if the user is using Firefox and he enters a certain link, I would like to redirect him to his own browser:

http://localhost?someparameter=somevalue

The localhost has to be the user's localhost

EDIT: What I am trying to do doesn't work in the link you are claiming to have the answer. I have seen websites that when you access, you get redirected to your OWN machine, not another page on the machine.

Makketronix
  • 1,389
  • 1
  • 11
  • 31
  • 1
    You can use the [`header()` function](http://us2.php.net/manual/en/function.header.php) to set the `Location:` HTTP header, just like any other redirect. – esqew Oct 21 '14 at 01:44
  • 1
    I'm not sure what Firefox has any significance. but like @esqew said, you can use the `header()` function to send an HTTP header. – Ryan Oct 21 '14 at 01:45
  • 1
    possible duplicate of [How to make a redirect in PHP?](http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) – esqew Oct 21 '14 at 01:45
  • will local host be with the point of view of the person's computer? Or the server? – Makketronix Oct 21 '14 at 01:50
  • Not a duplicate. Solution provided in that link doesn't work. – Makketronix Oct 21 '14 at 01:53
  • "you get redirected to your OWN machine, not another page on the machine". I'm confused as to what you mean. Additionally, could you provide me with the websites that do what you're trying to do? – Tim Oct 21 '14 at 01:55
  • If you try to authenticate your login with Linkedin, they send you a token to an address of your choice. If you put "http://localhost", you can intercept the request with the apache client – Makketronix Oct 21 '14 at 01:56

2 Answers2

0

You can redirect a user with PHP using header Like so:

<?php header('Location: http://localhost?someparameter=somevalue'); exit; ?>

Note: The header must be sent before any other output. E.g. an <html> tag before the header will generate an error.

Tim
  • 2,123
  • 4
  • 27
  • 44
  • I tried that but when I enter the address, I stay on the same page. I don't get redirected back to "my computer" – Makketronix Oct 21 '14 at 01:49
  • **NOTE**: You need to be aware that sending a header **will NOT** stop the execution of your script. If you want to redirect the user and not continue the request any further you should put an `exit;` after you declare the header. – Scopey Oct 21 '14 at 01:49
0

Ok, I found the issue.

I guess your response was correct. But, because I am using Godaddy, the server prevents me from writing my own headers and thus, redirection the way I wanted did not work.

What I was trying to do is a 302 redirect.

The solution was to use Godaddy's configuration and select the subdomain I would like to redirect with 301 or 302. This will change the .htaccess file.

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
Makketronix
  • 1,389
  • 1
  • 11
  • 31