0

I am writing a php-code which redirect me from localhost/login.php to localhost/index.page. I tried using the header('Location: index.php) method, but i keep receiving an error

Warning: Cannot modify header information - headers already sent by...

The error according to my search is due to a sort of output which is sent before the header() function. Unfortunately, after trying for hours, I could not figure out what is wrong with the code, so I am now looking for an alternative method.

Just another method, to redirect me from my "localhost/login.php" page back to my home page "localhost/index.php".

Sherif
  • 11,786
  • 3
  • 32
  • 57
moh19814
  • 133
  • 1
  • 1
  • 14
  • 1
    Well, whats wrong with the original code is that somewhere, there's something being output before `header()` is called. Could be something as simple as whitespace before ` – castis Aug 22 '16 at 20:47
  • Your currently solution is the way to go, you are just doing it wrong. – Luke Joshua Park Aug 22 '16 at 20:49
  • I have looked a lot for blank whitespace, even using Hex editor, but I could not find any. I just decide to walk around header() using for example Javascript or something else. – moh19814 Aug 22 '16 at 20:50
  • the rest of the error should say something like `(output started at /path/to/somefile.php:50)`. somefile.php is the file that is making the output and 50 is the line in the file where it happens. So just look that line of the file. – Cave Johnson Aug 22 '16 at 21:03

1 Answers1

1

Instead of using PHP to do the redirect, use a META refresh that causes your browser to follow it:

<meta http-equiv="refresh" content="0; url=http://example.com/">

Information on META redirects: Meta_refresh

Cagy79
  • 1,610
  • 1
  • 19
  • 25