duanhan5388 2015-11-11 15:09
浏览 30

使用表单在每个页面上显示用户名,直到用户注销

I am currently creating a website that will allow the user to log in using a username only, no password is required. Once the user has typed their name into the form, their name should then be placed on all of the pages they then visit until they log out.

I am having problems with this as it, 1) Not showing in the browser correctly (I will provide images below) 2) Not forwarding me to the Home Page.

<?php
session_save_path("/aber/sec17/public_html/cs25010/tmp");
session_start();
if ($username == NULL) {
if (isset($_POST['submit'])) {
    $_SESSION["username"] = $_POST["username"];
    header("Location: home.php");
}
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Sean Coyne's Food Shop</title>
    <link href="style.css" type="text/css" rel="stylesheet"/>
    <link rel="icon" type="image/x-icon" href="images/favicon.ico" />
    <meta name="description" content="Welcome to Sean Coyne's Food Shop" />
</head>

<body>
    <div id="page">
        <div id="logo">
            <img src="images/logo.jpg" alt="Sean Coyne's Food Shop" 
title="Sean Coyne's Food Shop" width="400px" height="70px"/>

</div>

        <div id="nav">
            <div id="menu">
                <ul>
                <li><a href="home.php">Home</a></li>
                <li><a href="database.php">Products</a></li>
                <li><a href="drink.php.html">Offers</a></li>
                <li><a href="about.php">About Us</a></li>
                <li><a href="findus.php">Where to find us</a></li>
                <li><a href="contact.php">Contact</a></li>
                </ul>
            </div>
        </div>



        <div id="main">
            <h1>Welcome to Sean Coyne's Food Shop</h1>
            <h2>Please Log In below:</h2>
            <br></br>
            <div id="login">
                <?php
                    echo '<form action="home.php" method"post"> 
                    <input type="text" name="username" text="input username"
                    placeholder="Username" required> 
                    <input type="submit" name="submit" value="submit" /> 
                    </form>';
                ?>
            </div>  
        </div>
    </div>
</body>
</html>

Here is a screenshot of the login page:

Screenshot of the log in page

  • 写回答

2条回答 默认 最新

  • dongxie3352 2015-11-11 15:24
    关注

    Needless to introduce the form labels "php" change this;

    <?php
        echo '<form action="home.php" method"post"> 
        <input type="text" name="username" text="input username"
        placeholder="Username" required> 
        <input type="submit" name="submit" value="submit" /> 
        </form>';
    ?>
    

    For this:

    <form name="form" action="" method="POST"> 
            <input type="text" name="username" text="input username" placeholder="Username" required /> 
            <input type="submit" name="submit" value="submit" /> 
    </form>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)