gpt4 book ai didi

PHP header() 不工作?

转载 作者:行者123 更新时间:2023-12-05 08:55:55 25 4
gpt4 key购买 nike

<分区>

由于某种原因,我正在努力解决这个问题 header("Location:http://corocloud.com/index.php/");不工作,我已经尝试了文件的其他路径但没有工作,header("Location:index.php");, header("index.php");, header("./index.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();
// this will trigger when submit button click
if(isset($_POST['sub'])){

$db = new mysqli("localhost","user","password","db");

// create query
$query = "SELECT * FROM users WHERE user='".$_POST['uname']."' AND password='".sha1($_POST['pass'])."'";

// execute query
$sql = $db->query($query);
// num_rows will count the affected rows base on your sql query. so $n will return a number base on your query
$n = $sql->num_rows;

// if $n is > 0 it mean their is an existing record that match base on your query above
if($n > 0){
$_SESSION['username'] = $_POST['uname'];
$_SESSION['password'] = $_POST['pass'];
$_SESSION['userobj'] = mysql_fetch_assoc($query);
header("Location: index.php");
exit();
} else {

echo "Incorrect username or password";
}
}
?>
</body>
</html>

我知道代码正在执行,因为每个 $_SESSION 变量都在获取值,为什么 header 不起作用?

顺便说一下,我要重定向的文件位于同一文件夹中。

编辑:不要运行代码段,因为它有 PHP

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com