![]() |
|
I've problem with login.php - Printable Version +- LCKB (https://lckb.dev/forum) +-- Forum: ** OLD LCKB DATABASE ** (https://lckb.dev/forum/forumdisplay.php?fid=109) +--- Forum: Programmers Gateway (https://lckb.dev/forum/forumdisplay.php?fid=196) +---- Forum: Coders Talk (https://lckb.dev/forum/forumdisplay.php?fid=192) +---- Thread: I've problem with login.php (/showthread.php?tid=1952) |
- ReturnKratos - 08-07-2013 Now ive fixed the session problem. now it dont say me Welcome back "user". where "user" must contains $_SESSION[uid] = $r[user_id]; here the new login2.php <?php session_start(); if(isset($_SESSION["uid"])) { ?> <script type="text/javascript"> setTimeout("location.href=index.php",5000); </script> <?php } include includes/settings/Config.php; include includes/config.php; include includes/functions.php; If (isset($_POST[username])) { if (empty($_POST[username]) OR empty($_POST[password])) { echo "Error! One or more fields are empty. Youll be redirected in 5 seconds... Or click "; ?> <a href="register.php">here.</a> <script type="text/javascript"> setTimeout("location.href=login.php",5000); </script> <?php die; } $conn = new mysqli($ip,$sqluser,$sqlpw,$userdb); if (mysqli_connect_errno() == 0) { $user = $conn->real_escape_string(htmlspecialchars(clean_str(strtolower($_POST[username])))); $pass = $conn->real_escape_string(htmlspecialchars(strtolower($_POST[password]))); $qusr = "SELECT * FROM ".$Server[auth].".bg_user WHERE user_id = $user AND truepasswd = $pass"; $resusr = $conn->query($qusr); If ($resusr->num_rows > 0) { echo <img src="images/msg/succ.png" width="50" height="50" alt="Error"><br>; echo Logged Successfully ! You will be redirected in 2 seconds !; echo ; $_SESSION[utente]="ok"; $r = mysql_fetch_array( $result ); $_SESSION[uid] = (int)$r[user_code]; $_SESSION[pwd] = $r[truepasswd]; $_SESSION[name] = $r[user_id]; $User = $r[user_id]; $TRPWD = $r[truepasswd]; } else { echo <img src="images/msg/error.png" width="50" height="50" alt="Error"><br>; echo Username or password wrong ! Login Failed<br>; echo <meta http-equiv="refresh" content="10; url=index.php">; echo $qusr; } } } else { echo Username or Password is not setted.; } ?> and here the session check where $User contains username, but if i put in welcome back "user" the page will deface. <?php if (isset($User)) { echo > Welcome back .$_SESSION[name]..; } else { echo <a href="login.php"> > Login Page</a>; } ?> Someone can help me ? - ReturnKratos - 08-07-2013 Up, Someone can help me i need of this. - AdiH97 - 08-07-2013 <?php if (isset($User)){ echo "Welcome back $_SESSION[name]"; } else { echo <a href="login.php"> Login Page</a>; } ?> Try with this - ReturnKratos - 08-07-2013 <?php if (isset($User)){ echo "Welcome back $_SESSION[name]"; } else { echo <a href="login.php"> Login Page</a>; } ?> Try with this Same look : - ReturnKratos - 08-07-2013 oh yea ive fixed with login pdo (thanks google the best friend.) ive fixed with this : login.php <?php // Inialize session session_start(); // Include database connection settings include(includes/pdodb/database.php); // Retrieve username and password from database according to users input $stmt = $db->prepare("SELECT * FROM bg_user WHERE (`user_id` = :username) and (`truepasswd` = :password)"); $result = $stmt->execute(array(:username=>$_POST[username],:password=>$_POST[password])); $num_rows = $stmt->rowCount(); // Check username and password match if ( $num_rows > 0) { // Set username session variable $_SESSION[username] = $_POST[username]; // Jump to secured page header(Location: index.php); } else { // Jump to login page header(Location: login.php); } ?> database.php <?php $dsn = mysql:host=localhost;dbname=lc_db_auth; $username = root; $password = ; $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); try { $db = new PDO($dsn, $username, $password, $options); } catch (PDOException $e) { $error_message = $e->getMessage(); include errors/db_error_connect.php; exit; } function display_db_error($error_message) { global $app_path; include errors/db_error.php; exit; } ?> and now says : And thanks to AdiH97 for you help Here what i do ![]() - luoo - 08-20-2013 i think this was the problem $qusr = "SELECT * FROM ".$Server[auth].".bg_user WHERE user_id = $user AND truepasswd = $pass"; to $qusr = "SELECT * FROM ".$Server[auth].".bg_user WHERE user_id = ".$user." AND truepasswd = ".$pass.""; - Nymphetamine - 08-20-2013 Topic is marked as solved so. - Johnny5 - 08-20-2013 Topic Closed by a moderator. The reason why: Solved |