我希望如果用户使用他的登录详细信息登录,他的ID应该通过,并且应该在链接栏中显示?id = 000就像这样。 我很努力,但无法解决它,请帮助我们......
Dim anon = New With {.data = New List(Of Model) From {model}}
Dim json As String = JsonConvert.SerializeObject(anon, Formatting.Indented)
答案 0 :(得分:0)
您不必从POST或GET发送user_id,在登录时在会话中设置user_id。并从你需要它的会话中获取它..这是最好的解决方案..
OR
您可以在表单中将其作为隐藏输入发送
<input type="hidden" name="id" value="{$id}">
答案 1 :(得分:0)
为什么要在URL中显示id?登录后,您可以从用户会话中访问它。如果您仍然想要,那么这里是代码。
<pre>
$query = "SELECT id FROM art WHERE email='$email' and pwd='$pwd'";
$result = mysqli_query($connection, $query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if($rows==1){
$data = mysql_fetch_assoc($result);
$_SESSION['email'] = $email;
header("Location:Recruiter/dashboard.php?id=".$data['id']);
}else{
echo "<script>alert('Incorrect user id and password')</script>";
}
}
}
</pre>
答案 2 :(得分:0)
以下是您需要完成的代码修改。如果凭据有效,您需要从表中提取id
并将id
附加到网址:
$query = "SELECT id FROM register WHERE email='$email' and pwd='$pwd'";
$result = mysqli_query($connection, $query) or die(mysql_error());
$rows = mysqli_fetch_array($result);
if(isset($rows['id']) && $rows['id'] > 0){
$_SESSION['email'] = $email;
header("Location:Employee/dashboard.php?id=" . $rows['id']);
答案 3 :(得分:0)
您可能会从之前的答案中得到答案,但我将此答案添加为将会话用于此类活动的最佳做法。
开始会话,您需要在页面顶部或在调用会话代码session_start();
在会话中添加用户ID以跟踪登录$_SESSION['user'] = $user_id;
的用户。然后检查是否有人登录。
if (isset($_SESSION['user'])) {
// if logged in
} else {
// if not logged in
}
查找登录的用户ID $_SESSION['user']
。
答案 4 :(得分:0)
重定向使用此功能:
<pre>
$array = ['coke.','fanta.','chocolate.'];
print_r($array);
echo "<pre>";
$next_merge = "";
foreach ($array as $key => $value) {
if($next_merge == $value){
continue;
}
if (strlen($value)<6) {
$new[] = $value." ".$array[$key+1];
$next_merge = $array[$key+1];
} else {
$new[] = $value;
}
}
print_r($new);
</pre>
在function redirect($url){
if (headers_sent()){
die('<script type="text/javascript">window.location.href=\'' . $url . '\';</script>');
}else{
header('Location: ' . $url);
die();
}
}
中保存用户ID并更改您的代码:
$_SESSION['id'] = $_POST['user_id'];
用户登录后检查网址,如果您想要点击,如果if($rows==1){
$_SESSION['email'] = $email;
redirect(SITE_URL.'Employee/dashboard.php?id='.$_SESSION['id']); //here if user successfully log in his user id should be also visible in url bar
}
不存在,则再次重定向:
id