Jump to content

php within a header redirect


runnerjp

Recommended Posts

how comes my redirect echos out index.php?page=message&forum=$forum&id=$forumpostid&pagenum=last and not the php output... well i cant think of the word lol but the output of $forum is what i mean lol minds gone blank

 

header('Location: index.php?page=message&forum=$forum&id=$forumpostid&pagenum=last');

Link to comment
https://forums.phpfreaks.com/topic/166348-php-within-a-header-redirect/
Share on other sites

The loaction header must contain an absolute URI!!

See note above "Note: HTTP/1.1 requires an absolute URI as argument to » Location".

 

Thus:

<?php header("Location: /home.php"); ?>

is wrong, but most browsers will follow it correctly (hence the common mistake).

 

This is correct:

<?php

    header("Status: 301"); # 301 Moved Permanently

    header("Location: http://{$_SERVER['SERVER_NAME']}/home.php");

    exit;

?>

You are trying to iterate variable values inside single quotes. Either use double quotes or concatenate it.

 

header('Location: http://mydomain.com/index.php?page=message&forum=$forum&id=$forumpostid&pagenum=last');

 

SHOULD/COULD BE

 

header('Location: http://mydomain.com/index.php?page=message&forum=' . $forum . '&id=' . $forumpostid . '&pagenum=last');   

 

OR

 

header("Location: http://mydomain.com/index.php?page=message&forum=$forum&id=$forumpostid&pagenum=last");

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.