Pandareen Posted December 26, 2011 Share Posted December 26, 2011 Hi!i've got a big problem...i've made a login form wich works but i don't know how to make a session to store user's username and display after login "Hello username!"Can u help me please? This are my pages: 1.login.php <?php session_start(); $_SESSION['logat'] = 0; $username = $_POST['username']; $password = $_POST['password']; $table = "xxx"; $name = "xxx"; $pass = "xxx"; $host = "xxx"; $user = "xxx"; $user_pass = "xxx"; $con = mysql_connect($host,$user,$user_pass); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("table", $con); if ($_SERVER['REQUEST_METHOD'] == "POST") { $query = sprintf("SELECT * FROM `$table` WHERE `$name` LIKE '%s' AND `$pass` LIKE '%s'", mysql_real_escape_string($username), mysql_real_escape_string($password)); $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result) > 0) { $_SESSION['logat'] = 1; } } if($_SESSION['logat'] == 0) { header("error.php"); } else { header("user.php"); } ?> 2.user.html <?php session_start(); if ($_SESSION['logat'] == 0){ header("location:http:/Proiect%20AW/loginerror.php"); } else echo ""; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>IntelliBook - Panou de Comanda</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> <link rel="icon" type="image/x-icon" href="resurse/favicon.png" /> </head> <body> <div id="header" title="IntelliBook v1.0"></div> <div id="spacer"></div> <div id="logat"> <p id="logat_text"><strong>Salut</strong>HELLO USER </p> <p id="logat_text">.... ...and where is HELLO USER i want to display the user wich is logged in... Quote Link to comment https://forums.phpfreaks.com/topic/253853-hello-username/ Share on other sites More sharing options...
Pikachu2000 Posted December 26, 2011 Share Posted December 26, 2011 $_SESSION works like any other array, except it is a persistent, superglobal array. Quote Link to comment https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301425 Share on other sites More sharing options...
Pandareen Posted December 26, 2011 Author Share Posted December 26, 2011 okeee, so can u give me a solution please? i'm kinda noob in PHP...but i need this :s Quote Link to comment https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301426 Share on other sites More sharing options...
Pikachu2000 Posted December 26, 2011 Share Posted December 26, 2011 Do you know how to store a value in an array, then echo it? Quote Link to comment https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301432 Share on other sites More sharing options...
Pandareen Posted December 26, 2011 Author Share Posted December 26, 2011 Actually no...but if u can tell me how , and what to put in login.php and then in user.html it will be great, again please Quote Link to comment https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301433 Share on other sites More sharing options...
Pikachu2000 Posted December 26, 2011 Share Posted December 26, 2011 $_POST is an array. You can echo a value from that right? Same thing with the $_SESSION array. Quote Link to comment https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301436 Share on other sites More sharing options...
Pandareen Posted December 26, 2011 Author Share Posted December 26, 2011 can u make an exemple from this? Quote Link to comment https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301437 Share on other sites More sharing options...
Pandareen Posted December 26, 2011 Author Share Posted December 26, 2011 anybodY? Quote Link to comment https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301450 Share on other sites More sharing options...
Pikachu2000 Posted December 26, 2011 Share Posted December 26, 2011 Don't bump threads. Read this: http://php.net/manual/en/language.types.array.php then try to do it on your own. If you have trouble, post the code you tried along with any errors or other problems you encountered. Quote Link to comment https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301451 Share on other sites More sharing options...
peter_anderson Posted December 26, 2011 Share Posted December 26, 2011 Where you have $_SESSION['logat'] = 1; Below, add $_SESSION['username'] = $_POST['username']; And on user.html, replace <p id="logat_text"><strong>Salut</strong>HELLO USER </p> with <p id="logat_text"><strong>Salut</strong><?php echo $_SESSION['username']; ?> </p> Although, it is not suggested you have HTML and PHP in the same file. Quote Link to comment https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301461 Share on other sites More sharing options...
Pandareen Posted December 26, 2011 Author Share Posted December 26, 2011 @Pikachu2000L: srry, i get it @peter_anderson: thnx a lot man, i'll try harder next time Problem Solved! Quote Link to comment https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.