php - Not Reading Database Even Without Hash -
i trying figure out why script runs "login faileda" , quits. technically know why(no match,but there match). thought maybe issue password hash, i've removed test password. i've tried manually place password , username within database match. there other reason not working? these scripts i'm running.
signin.php
<?php include_once("includes/check_login_status.php"); // if user logged in, header weenis away if($user_ok == true){ header("location: user.php?u=".$_session["username"]); exit(); } ?><?php // ajax calls login code execute if(isset($_post["e"])){ // connect database include_once("includes/db_conx.php"); // gather posted data local variables , sanitize $e = mysqli_real_escape_string($db_conx, $_post['e']); $p = mysqli_real_escape_string($db_conx, $_post['p']); // user ip address $ip = preg_replace('#[^0-9.]#', '', getenv('remote_addr')); // form data error handling if($e == "" || $p == ""){ echo "login_failed"; exit(); } else { // end form data error handling $sql = "select id, username, password transactions email='$e' , activated='1' limit 1"; $query = mysqli_query($db_conx, $sql); $row = mysqli_fetch_row($query); $db_id = $row[0]; $db_username = $row[1]; $db_pass_str = $row[2]; if($p != $db_pass_str){ echo "login_faileda"; exit(); } else { // create sessions , cookies $_session['userid'] = $db_id; $_session['username'] = $db_username; $_session['password'] = $db_pass_str; setcookie("id", $db_id, strtotime( '+30 days' ), "/", "", "", true); setcookie("user", $db_username, strtotime( '+30 days' ), "/", "", "", true); setcookie("pass", $db_pass_str, strtotime( '+30 days' ), "/", "", "", true); // update "ip" , "lastlogin" fields $sql = "update transactions set ip='$ip', lastlogin=now() username='$db_username' limit 1"; $query = mysqli_query($db_conx, $sql); echo $db_username; exit(); } } exit(); } ?> <?php include_once("./includes/site-opener.php");?> <title>sign in</title> <script src="js/main.js"></script> <script src="js/ajax.js"></script> <script> function emptyelement(x){ _(x).innerhtml = ""; } function login(){ var e = _("email").value; var p = _("password").value; if(e == "" || p == ""){ _("status").innerhtml = "fill out of form data"; } else { _("loginbtn").style.display = "none"; _("status").innerhtml = 'please wait ...'; var ajax = ajaxobj("post", "signin.php"); ajax.onreadystatechange = function() { if(ajaxreturn(ajax) == true) { if(ajax.responsetext == "login_failed"){ _("status").innerhtml = "login unsuccessful, please try again."; _("loginbtn").style.display = "block"; } if(ajax.responsetext == "login_faileda"){ _("status").innerhtml = "next one"; _("loginbtn").style.display = "block"; } else { window.location = "user.php?u="+ajax.responsetext; } } } ajax.send("e="+e+"&p="+p); } } </script>
check_login_status.php
<?php session_start(); include_once("db_conx.php"); // files inculde file @ top not require // connection database or session_start(), careful. // initialize vars $user_ok = false; $log_id = ""; $log_username = ""; $log_password = ""; // user verify function function evalloggeduser($conx,$id,$u,$p){ $sql = "select ip users id='$id' , username='$u' , password='$p' , activated='1' limit 1"; $query = mysqli_query($conx, $sql); $numrows = mysqli_num_rows($query); if($numrows > 0){ return true; } } if(isset($_session["userid"]) && isset($_session["username"]) && isset($_session["password"])) { $log_id = preg_replace('#[^0-9]#', '', $_session['userid']); $log_username = preg_replace('#[^a-z0-9]#i', '', $_session['username']); $log_password = preg_replace('#[^a-z0-9]#i', '', $_session['password']); // verify user $user_ok = evalloggeduser($db_conx,$log_id,$log_username,$log_password); } else if(isset($_cookie["id"]) && isset($_cookie["user"]) && isset($_cookie["pass"])){ $_session['userid'] = preg_replace('#[^0-9]#', '', $_cookie['id']); $_session['username'] = preg_replace('#[^a-z0-9]#i', '', $_cookie['user']); $_session['password'] = preg_replace('#[^a-z0-9]#i', '', $_cookie['pass']); $log_id = $_session['userid']; $log_username = $_session['username']; $log_password = $_session['password']; // verify user $user_ok = evalloggeduser($db_conx,$log_id,$log_username,$log_password); if($user_ok == true){ // update lastlogin datetime field $sql = "update users set lastlogin=now() id='$log_id' limit 1"; $query = mysqli_query($db_conx, $sql); } } ?>
when
$db_id = $row[0]; $db_username = $row[1]; $db_pass_str = $row[2];
does table structure have in order? in
[ id | username | password ]
or can
[ id | email | username | password ]
how output variables see whats coming out?
i've included
$query = mysqli_query($db_conx, $sql); $row = mysqli_fetch_row($query); var_dump($row['username']);
where output? i'm being taken message.php page means going user.php page, no longer allowing output display on page
a breakthrough!!
well able run thought. problem had manually change both email , password work. guess start , mean problem isn't here after all. maybe within area data posted? ideas or theories on issue can try tackle it.
mysql or php won't magically insert field.
guess having unexpected data in db.
i not @ php shouldn't 1 able $row['username'] ?
Comments
Post a Comment