header()的问题;

时间:2017-10-19 21:09:10

标签: php

编写并测试此文件后,header("location: url");将无效...我不知道该怎么做...这里是代码:

HTML文件

<!doctype html>
<html>
    <head>
        <title>Program</title>
        <link rel="stylesheet" href="../../../../style.css">
    </head>
    <body>
        <div id="main">
            <center>
                <br><br><br><br>
                <a id="question">10a + 4b + 9a + 1b</a>
                <br><br><br><br>
                <form action"php/q1.php" method="post">
                    <input type="text" name="a" placeholder="00">a + <input type="text" name="b" placeholder="00">b<br>
                    <input type="submit" value"Next" id="start">
                </form>
                <br><br><br><br>
            </center>
        </div>
    </body>
</html>

PHP文件

<?php
    $a = $_POST['a'];
    $b = $_POST['b'];
    $final = $a .. "a + " .. $b .. "b";
    if ($final = "19a + 5b") {
        setcookie("score", 1);
    } else {
        setcookie("score", 0);
    }
    header("location: http://www.example.com/go/algabra/simplifying/easy/q2.php");
    exit();
?>

请不要问我这个代码的用途是什么! 我试图弄清楚,我已经研究了各种不同的网站,我找不到任何东西。

PHP版本:PHP 7.1

1 个答案:

答案 0 :(得分:3)

在到达标题行之前可能会出错。

$final = $a .. "a + " .. $b .. "b";

应该是

$final = $a . "a + " . $b . "b";

您可能也希望进行此修复:

if ($final = "19a + 5b") {

if ($final == "19a + 5b") {

此外,您在html表单中的单词操作后错过了一个等号。

相关问题