1

i have downloaded last WAMP (32 bit) from website then i added my project and realized that redirect not working so i made a simple test and write file redirect.php and its not working here is my code :

<?php
error_reporting(E_ALL); 
ini_set('display_errors', 1);

header("Location : http://www.google.com");
?>

Thanks

Dinoel Vokiniv
  • 183
  • 3
  • 14

2 Answers2

3

This:

header("Location : http://www.google.com");

is wrong. It should be:

header("Location: http://www.google.com");

With no space between Location and the colon.

Mind you, you have error_reporting on E_ALL and display_errors on. If you make any mistake (even an E_NOTICE) before the header() call, PHP will output data and not be able to send headers, causing the redirect to fail.

More on that can be found here: How to fix "Headers already sent" error in PHP

Community
  • 1
  • 1
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
0

Add ob_start () at the very top.

Generally redirection does not happen because we are outputting some thing on browser.

ob_start () saves that output in a buffer. And thus helps redirection.

Pupil
  • 23,834
  • 6
  • 44
  • 66