this question has answer here:
- how fix “headers sent” error in php 11 answers
i'm struggling if doesn't mind helping me. i'm no php master showing sure!
i'm trying make log in system using php/sessions/cookies etc, seem far error whenever try log in (it's meant log in hello "user" along log out button. i'll try attach/reduce can.
thanks in advance!
index.php(main log in page log in button)
<?php include('includes/sessions.inc.php'); ?> <?php /////////////////////////// conditional includes here if(isset($_session['login'])){ include('includes/session-logout.inc.php'); }else{ include('includes/session-login.inc.php'); } ?>
session-login.php
<div id="login"> <?php error_reporting(e_all|e_strict); ini_set('display_errors', true); if($_session['count'] > 0 && $_session['count'] <= 3 ){ echo "<p class=\"error\">sorry incorrect</p>"; } if($_session['count'] > 3){ echo "<p class=\"error\">too many attempts</p>"; }else{ // don't forget close } after html form ?> <form id="loginform" name="loginform" method="post" action="logic/checklogin.php"> <label for="username">username</label> <input name="username" type="text" id="username"> <label for="password">password</label> <input name="password" type="password" id="password"> <input type="submit" name="submit" value="login"> </form> <?php } ?> </div>
sessions.inc.php
<!doctype html><?php ////////////////////// start session here /////////////////////////// session_set_cookie_params(0, '/~b4019635', 'homepages.shu.ac.uk', 1, 1); session_start(); ?></html>
checklogin.php
<?php error_reporting(e_all|e_strict); ini_set('display_errors', true); // check login , create session , count attempts include('../includes/sessions.inc.php'); //check login / password combination if ($_post['username'] == "admin" && $_post['password'] == "letmein"){ $_session['login'] = 1; }else{ if(!isset($_session['count'])){ // first fail $_session['count'] = 1; }else{ // 2nd or more fail $_session['count']++; } } // redirect browser header("location: ".$_server['http_referer']); ?>
i feel session_start(); has in inspector cookie isn't created?
place session_start(); before <!doctype html>
tag. ensure there no other output before it.
Comments
Post a Comment