user3265615
user3265615

Reputation: 1

php header does not work properly

i have the following function

function redirect_to( $location = NULL ) {
  if ($location != NULL) {
   header("Location: {$location}");
    exit;
  }

then I use it to redirect with an argument

$id = $photo->id; // integer 
redirect_to("photovietnam.php?id=$id");

This work fine on my local system with wamp. on the server the correct url is displayed in the head ,but it appears to lack a return

did anybody had the sam experiance ?

Upvotes: 0

Views: 70

Answers (1)

Samuel
Samuel

Reputation: 6490

Check the docs: http://de3.php.net/manual/en/function.header.php, you might need to have an absolute path to the resource.

Note:

HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:

<?php
/* Redirect to a different page in the current directory that was requested */
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'mypage.php';
header("Location: http://$host$uri/$extra");
exit;
?>

Upvotes: 1

Related Questions