Click to See Complete Forum and Search --> : How can I transfer parameter with header function ?


Robert Chu
09-20-2005, 10:46 AM
Dear Sir,
I want to transfer a parameter in header function. The two php files are as following. But I get some error messages.

Fatal error: Function name must be a string in C:\Program Files\Apache Group\Apache2\htdocs\test2.php on line 2



test.php:

<?php
header("Location:test2.php?id='1'");
?>

test2.php

<?php
$id = $_GET('id');
echo $id;
?>

bokeh
09-20-2005, 11:59 AM
header("Location:") should be absolute and don't forget to exit after the redirect. In test2.php you need square brackets.

<?php // this is test.php
$id = '1';
header('Location: http://'.$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']).'test2.php?id='.$id);
exit;
?>



<?php // This is test2.php
$id = $_GET['id'];
echo $id;
?>

Robert Chu
09-20-2005, 07:43 PM
It works. Thanks.