[英]Redirect to page using location header?
I have a function that is being run in a php file when a button is clicked on the users profile page. 当在用户个人资料页面上单击按钮时,我有一个正在php文件中运行的功能。 Once the function is complete I want the user to be redirected back to their profile page.
功能完成后,我希望将用户重定向回其个人资料页面。 Normally I know how to redirect but this requires including the user id to go to their specific profile.
通常,我知道如何重定向,但这需要包括用户ID才能转到其特定配置文件。 I have made the following piece of code and am attaching
err=1
at the end of it in hope to try and get a message displayed in their profile. 我编写了以下代码,并在其末尾附加了
err=1
,以期尝试在其个人资料中显示一条消息。
Hope this makes sense. 希望这是有道理的。
<?php
header('Location: http://localhost/ptb1/profile.php?id=echo $_SESSION['user_id']err=1');
?>
Read about string concatenation : 了解有关字符串串联的信息 :
<?php
session_start();
header('Location: http://localhost/ptb1/profile.php?id=' . $_SESSION['user_id'] . '&err=1');
You also need to call session_start()
before you try and use $_SESSION
variables. 在尝试使用
$_SESSION
变量之前,还需要调用session_start()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.