如果用户已登录,如何重定向 [英] How to redirect if user already logged in
本文介绍了如果用户已登录,如何重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个登录脚本执行此操作:
I have a login script that does this:
$_SESSION['username']=$username;
$_SESSION['password']=$password;
如果用户成功登录。
所以我编辑了注册页面来执行此操作:
If the user logged in succesfully. And so I edited the signup page to do this:
<?php
function redirect() {
header(' URL= index.php');
}
?>
<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" id="jmtoday" class=" no_js">
<head>
<link href='icon.jpg' rel='icon' type='image/jpg'/>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-language" content="en" />
<LINK REL=StyleSheet HREF="Mainstyles.css" TYPE="text/css"></link>
<Title>Sign up | JMToday</title>
</head>
<body>
<?php
if(isset($_SESSION['username'])){
redirect();
}
?>
但是当我使用我创建的帐户登录时,它不会重定向用户。为什么?
But it doesn't redirect the user when I logged in with my account that I created. Why is that?
推荐答案
function redirect() {
header('location:index.php');
}
这篇关于如果用户已登录,如何重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文