PHP variable in the header function

I am trying to pass variables through a URL using the header function as a way to redirect the page. But when the page is redirected, it passes the names of the actual variables, not the values ​​associated with the variables. I am new to PHP and do not fully understand the syntax, so any further explanation as to the correct way to do this would be greatly appreciated.

header('location: index.php?id=".$_POST[ac_id]."&err=".$login."');
+5
source share
6 answers

Do you want to:

header("Location: index.php?id=".$_POST['ac_id']."&err=".$login);

You have joined ', and "in this line, so he could not properly interpolate variables. In my example above, you strictly open the string with "and combine the variables with the string.

+17

. :

header('location: index.php?id=' . urlencode($_POST['ac_id']) . '&err=' . urlencode($login));

urlencode() URL-.

http_build_query(), , URL- .

header('Location: index.php?' . http_build_query(array(
    'id' => $_POST['ac_id'],
    'err' => $login
)));

, . , RFC. URL.

+2

SESSION. header . u genrate url. ( ": destination.php? 1 = 1 & 2 = 3' ); . SESSION. B4 (). @the recue page u , val isset() n! empty() ... ...

, .

+1
header('location: index.php?id='.$_POST['ac_id'].'&err='.$login);
-1

:

header("location: index.php?id=$_POST[ac_id]&err=$login");

PHP- .

-1

header("Location:abc.html?id=".$_POST['id']."id_2=".$var['id_2']);

, . .

-1

All Articles