hello having issue whit log in script after log in when has go links provided sends me log in again , don`t understand why cause when had search script , not links work now, not .
<html> <head> <title>user login form - php mysql ligin system | w3epic.com</title> </head> <body> <h1>user login form - php mysql ligin system | w3epic.com</h1> <?php if (!isset($_post['submit']) || !isset($_session['username'])){ ?> <!-- html login form --> <form action="<?=$_server['php_self']?>" method="post"> username: <input type="text" name="username" /><br /> password: <input type="password" name="password" /><br /> <input type="submit" name="submit" value="login" /> </form> <?php } else { require_once("db_const.php"); $mysqli = new mysqli(db_host, db_user, db_pass, db_name); # check connection if ($mysqli->connect_errno) { echo "<p>mysql error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>"; exit(); } $username = $_post['username']; $password = $_post['password']; $_session['username'] = $_post['username']; $sql = "select * members username '{$username}' , password '{$password}' limit 1"; $result = $mysqli->query($sql); if (!$result->num_rows == 1) { echo "<p>invalid username/password combination</p>"; } else { echo "<table align=center><tr> <font color=#000000 face=arial, helvetica, sans-serif size=+2> <td align=center><p>logged in successfully</p></td></tr>"; echo "<tr><td align=center><p>welcome!</p></td></tr>"; echo "<tr><td align=center><p>what wood work whit today ". $username . "!</p></td></tr></table>"; echo "<table align=center><tr><td align=center><a href=adminsearch.php> <class\= color=#000000; face=arial black, gadget, sans-seri;style=”text-decoration:none; size=+2>admin</a></td>"; echo "<td align=center>↔</td>"; echo "<td align=center><a href=constructionsearch.php> <class\= color=#000000; face=arial black, gadget, sans-seri;style=”text-decoration:none; size=+2>construction</a></td>"; echo "<td align=center>↔</td>"; echo "<td align=center><a href=drivingsearch.php> <class\= color=#000000; face=arial black, gadget, sans-seri;style=”text-decoration:none; size=+2>driving</a></td>"; echo "<td align=center>↔</td>"; echo "<td align=center><a href=industrialsearch.php> <class\= color=#000000; face=arial black, gadget, sans-seri;style=”text-decoration:none; size=+2>industrial</a></td></font></table>"; } } ?>
the way script now, shows login form if form wasn't submitted. when navigate other links, form wasn't submitted, show form. need keep track of users have logged in, either using cookies or sessions. add code after username/password have been confirmed:
$_session['username'] = $_post['username']; and instead of this:
if (!isset($_post['submit'])){ use this:
if (!isset($_post['submit']) || !isset($_session['username']){
Comments
Post a Comment