我这个问题苦苦挣扎,因为某些原因header("Location:http://corocloud.com/index.php/");
不工作,我已经尝试过其他路径的文件,但没有工作, header("Location:index.php");
,header("index.php");
,header("./index.php/");
PHP标题()不工作?
没有这些工作,我的代码是这样的:
<!DOCTYPE html>
<html>
<head>
<title>CoroCloud</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./js/material.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.pink-indigo.min.css" />
<style>.mdl-layout{align-items:center;justify-content:center;}.mdl-layout__content{padding:24px;flex:none;}</style>
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-color--grey-100">
<main class="mdl-layout__content">
<div class="mdl-card mdl-shadow--6dp">
<div class="mdl-card__title mdl-color--primary mdl-color-text--white">
<h2 class="mdl-card__title-text">CoroCloud</h2>
</div>
<div class="mdl-card__supporting-text">
<form method="POST">
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="text" name="uname" />
<label class="mdl-textfield__label" for="uname">Username</label>
</div>
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="password" name="pass"/>
<label class="mdl-textfield__label" for="pass">Password</label>
</div>
<div class="mdl-card__actions">
<input type="submit" class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect" name="sub">
</div>
</form>
</div>
</div>
</main>
</div>
<?php
session_start();
\t // this will trigger when submit button click
\t if(isset($_POST['sub'])){
\t \t $db = new mysqli("localhost","user","password","db");
\t \t // create query
\t \t $query = "SELECT * FROM users WHERE user='".$_POST['uname']."' AND password='".sha1($_POST['pass'])."'";
\t \t // execute query
\t \t $sql = $db->query($query);
\t \t // num_rows will count the affected rows base on your sql query. so $n will return a number base on your query
\t \t $n = $sql->num_rows;
\t \t // if $n is > 0 it mean their is an existing record that match base on your query above
\t \t if($n > 0){
$_SESSION['username'] = $_POST['uname'];
$_SESSION['password'] = $_POST['pass'];
$_SESSION['userobj'] = mysql_fetch_assoc($query);
\t \t \t header("Location: index.php");
\t \t \t exit();
\t \t } else {
\t \t \t echo "Incorrect username or password";
\t \t }
\t }
?>
</body>
</html>
我知道正在执行的代码,为每$ _SESSION变量被获得价值,为什么标题不起作用?
我试图重定向的文件的方式是在同一个文件夹中。
编辑: 不要运行该代码段,因为它有PHP
尝试'标题( “位置:的index.php”);' 注意**的路径之间的空间**和**: ** – Dash
在调用'header'之前,你有任何输出吗? – user2890234
如果您在标题之前输出某些内容,它将不起作用 – Icewine