Note that there are some explanatory texts on larger screens.

plurals
  1. POEmpty data from database
    text
    copied!<p>HI i have this code here ,, it's For Login system :</p> <pre><code>elseif($_GET['action'] == "login"){ if(!empty($_GET['user_name']) &amp;&amp; !Empty($_GET['password'])){ session_name('Huemix|Studio'); session_set_cookie_params(2*7*24*60*60); sec_session_start(); $user = sql_safe($_GET['user_name']); $pass = sql_safe($_GET['password']); $rem = sql_safe($_GET['rememberMe']); if(!count($err)){ $sql = sprintf("SELECT loginid FROM login WHERE username='%s' AND password = '%s'",$user,md5($pass)); $query = mysql_query($sql); $row = mysql_fetch_assoc($query); if(!$query){ echo mysql_error(); }else{ echo $row["username"]; echo $row["loginid"]; //echo $user; // echo $pass; } if($row['username']){ $sql = sprintf("UPDATE login SET last_login='".time()."' WHERE username = '%s' AND password = '%s' ",$user,md5($pass)); $query = mysql_query($sql); if($query){ $_SESSION['username'] = $row['username']; $_SESSION['id'] = $row['loginid']; $_SESSION['rememberMe'] = $rem; setcookie("HuemixRemember",$rem); header("Location : index.php"); } echo '&lt;p style="color: #ff0000;"&gt;Error in Login system ,, Please Call The Programmer !&lt;/p&gt;'; }else{ echo '&lt;p style="color: #ff0000;"&gt;Error in Username and/or Password !&lt;/p&gt;'; } } }else{ echo '&lt;p style="color: #ff0000;"&gt;All Fields are Required !&lt;/p&gt;'; } </code></pre> <p>}</p> <p>now i did some safety function to my script and they are : sec_session_start(); And sql_safe(); Here is there codes : sec_session_start();</p> <pre><code>function sec_session_start() { $session_name = 'sec_session_id'; // Set a custom session name $secure = false; // Set to true if using https. $httponly = true; // This stops javascript being able to access the session id. ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies. $cookieParams = session_get_cookie_params(); // Gets current cookies params. session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly); session_name($session_name); // Sets the session name to the one set above. session_start(); // Start the php session session_regenerate_id(true); // regenerated the session, delete the old one. </code></pre> <p>}</p> <p>And sql_safe():</p> <pre><code>function sql_safe($value){ if ( $value ){ $value = strip_tags($value); $value = htmlspecialchars($value); $value = trim($value); $value = stripslashes($value); $value = mysql_real_escape_string($value); return $value; } else{ return false; } </code></pre> <p>}</p> <p>Now My problem is in the line <code>echo $row["username"];</code> There is no data printed ,, and i'm sure that there is a data in database and the connection works fine with the database and i tried to do <code>echo $user;</code> to see if the error from the values that Interred from the input box ,, but the output was the same as i interred !</p> <p>So i really i don't know what happened !!! Always showing the error <code>Error in Login system ,, Please Call The Programmer !</code> that caused by the if statement <code>if($row['username']){</code> !!</p> <p>another question please : Can you please tell me a tips or codes to secure my script ,, in everything " login, logout, sessions, cookies ... etc "</p> <p>And thanks ^_^</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload