Johnny Lumberjack Johnny Lumberjack - 3 months ago 9
PHP Question

PHP - How to pass GET values through header?

I'm trying to pass the

$id
value through the
header()
function, but it seems to not work. because I can't get the value in the page redirecting to.

Here is the code snippet I'm working on:

$url = BASE_URL . 'send.php?id=' . $id;
header("Location: $url");
exit();


But when I try to get this value in the other file, doing
$id = $_GET['id']
I get a PHP Notice:

PHP Notice: Undefined index: id in (MY_FILE_PATH) on line 5


Can someone help me? Thanks.

Answer

You should have to use session:

session_start();
$_SESSION['id'] = $_GET['id'];
header('Location: $url');

and next page like:

session_start();
$id = $_SESSION['id'];
Comments