justinede Posted May 1, 2008 Share Posted May 1, 2008 If anyone has some free time can they make a simple php MYSQL login script for me. All i want is page to login from. A page to register and a protected page using sessions. The protected page is the same for all the registered users and it need to be only for people who have logged in. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
mrdamien Posted May 2, 2008 Share Posted May 2, 2008 No, we don't do that. If you want someone to make everything for you, I suggest paying someone on the freelancing forum to do it. Quote Link to comment Share on other sites More sharing options...
dezkit Posted May 2, 2008 Share Posted May 2, 2008 http://www.phpeasystep.com/workshopview.php?id=6 Quote Link to comment Share on other sites More sharing options...
justinede Posted May 2, 2008 Author Share Posted May 2, 2008 ok thanks any way.. what do i change to this code to put on my index so if there loged in already it just goes to index1.html <? session_start(); if(!session_is_registered(myusername)){ header("location:index.html"); } ?> that makes it so if they try to go to index1 it send them to index to login. but if there already logged in what makes them go to index1.html Quote Link to comment Share on other sites More sharing options...
peranha Posted May 2, 2008 Share Posted May 2, 2008 <? session_start(); if(session_is_registered(myusername)){ header("location:index1.html"); } ?> Quote Link to comment Share on other sites More sharing options...
justinede Posted May 2, 2008 Author Share Posted May 2, 2008 thank you Quote Link to comment Share on other sites More sharing options...
justinede Posted May 2, 2008 Author Share Posted May 2, 2008 how would i say "hello (username). <a href="logout.php">Logout?</a> what so i put to show there user name again? Quote Link to comment Share on other sites More sharing options...
dezkit Posted May 2, 2008 Share Posted May 2, 2008 <?php echo "Hello $username"; ?> Basic PHP mang. Quote Link to comment Share on other sites More sharing options...
justinede Posted May 2, 2008 Author Share Posted May 2, 2008 lol... that dosnt seem to work should it be mysusername?? because of... <? session_start(); if(!session_is_registered(myusername)){ header("location:index.php"); } ?> ??? Quote Link to comment Share on other sites More sharing options...
dezkit Posted May 2, 2008 Share Posted May 2, 2008 lol, i stand corrected. Quote Link to comment Share on other sites More sharing options...
justinede Posted May 2, 2008 Author Share Posted May 2, 2008 it actually still dosnt want to work... :( Quote Link to comment Share on other sites More sharing options...
justinede Posted May 2, 2008 Author Share Posted May 2, 2008 maybe it dosnt work because myusername isnt declared on the page...??? Quote Link to comment Share on other sites More sharing options...
dezkit Posted May 2, 2008 Share Posted May 2, 2008 my guess is to do something sql SELECT idk im stupid in mysql. Quote Link to comment Share on other sites More sharing options...
firecat318 Posted May 2, 2008 Share Posted May 2, 2008 You need something like this. <?php $sql = mysql_query("SELECT users FROM users WHERE username = '$session'; $username = mysql_result($sql, 0); echo "Hello, $username"; ?> Just change "users" "users" and "username", unless your tables and rows are already called that. Then, you have to give your session a variable, something like.. <?php session_start(); $session = $_SESSION['username']; ?> And when they login, you have to log their username into a session. If all goes well, it should display their name depending on what is in the database. Quote Link to comment Share on other sites More sharing options...
justinede Posted May 2, 2008 Author Share Posted May 2, 2008 I already have this $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); now what? Quote Link to comment Share on other sites More sharing options...
firecat318 Posted May 2, 2008 Share Posted May 2, 2008 post all of your code so I can look over it and help more. Quote Link to comment Share on other sites More sharing options...
justinede Posted May 2, 2008 Author Share Posted May 2, 2008 ok. This is my check login.. <?php $host="localhost"; // Host name $username="ipod"; // Mysql username $password="admin"; // Mysql password $db_name="ipod"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:index1.php"); } else { echo "Wrong Username or Password"; } ?> Quote Link to comment Share on other sites More sharing options...
peranha Posted May 2, 2008 Share Posted May 2, 2008 Add a session line to create a session variable. <?php if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['username'] = $myusername; //Added line session_register("myusername"); session_register("mypassword"); header("location:index1.php"); } ?> on all pages where you want the user name to display put this code. <?php echo $_SESSION['myusername']; ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted May 2, 2008 Share Posted May 2, 2008 You need to have session_start() at the top of each page. Quote Link to comment 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.