php, login script -
i new in php , trying write registration script. problem when try sign in , can't see user`s menu. maybe problem sessions , cookies can't find it. here part of code:
config.php
<?php ob_start(); $con = mysql_connect("localhost","root","123"); if (!$con) { die('could not connect: ' . mysql_error()); } mysql_select_db("9gag", $con); $logged = mysql_query("select * users id='$_cookie[id]' , password = '$_cookie[password]'"); $logged = mysql_fetch_array($logged); ?>
login.php
<?php ob_start(); include("config.php"); if (!$logged[username]) { if (!$_post[login]) { echo("<center><form method=\"post\"> <table> <tr> <td align=\"right\"> user: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\"> </td> </tr> <tr> <td align=\"right\"> password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"password\"> </td></tr><tr> <td align=\"center\"> <input type=\"submit\" name=\"login\" value=\"sign in\"> </td></tr><tr> <td align=\"center\"> <a href=\"register.php\">sign up</a> </td></tr></table></form></center>"); } if ($_post[login]) { $username = $_post[username]; $password = $_post[password]; $info = mysql_query("select * users username = '$username'") or die(mysql_error()); $data = mysql_fetch_array($info); if($data['password'] != $password) { echo "wrong username or password!"; }else{ $query = mysql_query("select * users username = '$username'") or die(mysql_error()); $user = mysql_fetch_array($query); setcookie("id", $user['id'],time()+(60*60*24*5), "/", ""); setcookie("password", $user['password'],time()+(60*60*24*5), "/", ""); } } } else { echo ("<center>welcome <b>$logged[username]</b><br /></center> <a href=\"editprofile.php\">profile</a><br /> <a href=\"logout.php\">log out</a>"); } ?>
how said change coockie session, haven't understood table/columns layout i've tried make better code try :)
config.php
<?php $con = mysql_connect("localhost","root","123"); if (!$con) { die('could not connect: ' . mysql_error()); } mysql_select_db("9gag", $con); ?>
login.php
<?php session_start(); ob_start(); include("config.php"); if (!isset($_session['id'])) { if (!$_post['login']) { echo '<center><form method="post"> <table> <tr> <td align="right"> user: <input type="text" size="15" maxlength="25" name="username"> </td> </tr> <tr> <td align="right"> password: <input type="password" size="15" maxlength="25" name="password"> </td></tr><tr> <td align="center"> <input type="submit" name="login" value="sign in"> </td></tr><tr> <td align="center"> <a href="register.php">sign up</a> </td></tr></table></form></center>'; } if ($_post[login]) { $username = $_post['username']; $password = $_post['password']; $info = mysql_query("select * users username = '".$username."'") or die(mysql_error()); $data = mysql_fetch_array($info); if($data['password'] != $password) { echo "wrong username or password!"; }else{ $query = mysql_query("select * users username = '".$username."'") or die(mysql_error()); $user = mysql_fetch_array($query); $_session['username']=$user['username']; $_session['id']=$user['id']; $_session['password']=$user['password']; } } } else { echo "<center>welcome <b>".$_session['username']."</b><br /></center> <a href='editprofile.php'>profile</a><br /> <a href='logout.php'>log out</a>"; } ?>
Comments
Post a Comment