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. Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/ 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. Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531387 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 Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531388 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 Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531390 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"); } ?> Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531410 Share on other sites More sharing options...
justinede Posted May 2, 2008 Author Share Posted May 2, 2008 thank you Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531412 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? Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531413 Share on other sites More sharing options...
dezkit Posted May 2, 2008 Share Posted May 2, 2008 <?php echo "Hello $username"; ?> Basic PHP mang. Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531423 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"); } ?> ??? Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531424 Share on other sites More sharing options...
dezkit Posted May 2, 2008 Share Posted May 2, 2008 lol, i stand corrected. Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531425 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... :( Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531427 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...??? Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531433 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. Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531436 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. Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531442 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? Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531447 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. Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531449 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531458 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']; ?> Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531686 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. Link to comment https://forums.phpfreaks.com/topic/103794-need-help-with-simple-php-login/#findComment-531690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.