Creating a very simple 1 username/password login in php

后端 未结 5 1081
甜味超标
甜味超标 2020-12-04 22:52

I want to make a single login for just 1 user without storing in a database but I can\'t seem to get this to work.

My code: login.php


&         


        
5条回答
  •  遥遥无期
    2020-12-04 23:11

    Firstly, you need to put session_start(); before any output to the browser, normally at the top of the page. Have a look at the manual.

    Second, this won't affect your results, but these lines aren't being used anywhere and should be removed:

    $usr = "admin";
    $psw = "password";
    $username = '$_POST[username]';
    $password = '$_POST[password]';
    

    ...and the last two lines there wouldn't work, you need to put the quotes inside the square brackets:

    $username = $_POST['username'];
    

    If you put session_start() at the top of your page (i.e. before the tag etc), this should work fine.

提交回复
热议问题