简体   繁体   中英

php urlencode in header location different from default urlencode in html anchor tag

Am trying to redirect users from two different pages with a pair of similar variables.one page uses the HTML anchor tag while the other uses php header location.The one using anchor tag works fine but the one using header location does not work.Source codes are as shown below:

header("Location: Play.php?urlencode(vid_name='".$filehead."'&&uploader='".$uploader."')");

and

echo "<a href='Play.php?vid_name=".$songname." && uploader=".$uploader."'>";

am using the get method to use this variables. How can I sort this out so the recipient page can access the variables from header location?

Functions dont run inside a double quoted string, but $variables are expanded

Try like this

header("Location: Play.php?" . urlencode("vid_name=$filehead&uploader=$uploader"));

and

echo "<a href='Play.php?vid_name=$songname&uploader=$uploader'>";

Or as @Victor suggested

$data = array(
    'vid_name' => $filehead,
    'uploader' => $uploader
);

echo header('Location: Play.php?' . http_build_query($data)  );

And

$data = array(
    'vid_name' => $songname,
    'uploader' => $uploader
);

echo "<a href='Play.php?" . http_build_query($data) . "'>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM