473,394 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to automatically login after registration in php?

127 100+
how to automatically login after the user successfully completes registration.

now, the user after registration, need to enter username and password again to login. i don't want to enter username and password, he automatically loggged in after registration.

login.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("config.php");
  3. session_start();
  4.  
  5. if($_SERVER["REQUEST_METHOD"] == "POST")
  6. {
  7.     // username and password sent from form 
  8.  
  9. /*$myusername= ucfirst ($_POST['uname']); 
  10. $mypass=($_POST ['password']); 
  11. $mypassword=md5($mypass);*/
  12. $email = $_POST['email'];
  13. $password = $_POST['password'];
  14.  
  15. $sql="SELECT * FROM member WHERE email='$email' and password='$password'";
  16. $result=mysql_query($sql);
  17. /*$row=mysql_fetch_array($result);
  18. $active=$row['active'];*/
  19.  
  20. $count=mysql_num_rows($result);
  21.  
  22. // If result matched $myusername and $mypassword, table row must be 1 row
  23. if($count==1 and $email=="admin@reachmena.com")
  24. {
  25. session_register("admin");
  26. $_SESSION['login_user']=$email;
  27.  
  28. header("location: admin.php");
  29. }
  30. else if($count==1)
  31. {
  32. session_register("email");
  33. $_SESSION['login_user']=$email;
  34.  
  35. header("location: welcome_test.php");
  36. }
  37. else 
  38. {
  39. $error="Your Login Name or Password is invalid";
  40. }
  41. }
  42. ?>
lock.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include('config.php');
  3. session_start();
  4. $user_check=$_SESSION['login_user'];
  5.  
  6. $ses_sql=mysql_query("select mname from member where email='$user_check' ");
  7.  
  8. $row=mysql_fetch_array($ses_sql);
  9.  
  10. $login_session=$row['mname'];
  11.  
  12. if(!isset($login_session))
  13. {
  14. header("Location:home.php");
  15. }
  16. ?>
Jun 14 '13 #1
1 9271
Atli
5,058 Expert 4TB
Based on that code, whether or not the user is logged in is determined by checking if the $_SESSION['login_user'] element has a valid user email. So if you want your registration script to log the user in, put the email into that session variable.


On another note, the session_register() function has been obsolete for a long time, and has been removed from PHP altogether as of PHP 5.4. Do not use it! - See the manual entry on sessions for details on how to properly use sessions in modern PHP code.
Jun 14 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: A.M | last post by:
Hi, I have implemented forms authentication on my application, but I have to fill the login form every time i run the web app during debugging phases. I know that i can change the code to...
10
by: Victor | last post by:
hi guys. In my project, now I am using a asp.net login control and a customized membership provider to do the form authentication. Now I want some function that user can skip the login form and be...
2
by: sheaguevara | last post by:
This is my first post onto the forum. So first off, I'd like to say hello to everyone. I just started working on a login/registration system and I am trying to have a feature where the user will...
0
by: thupham | last post by:
I write code to login automatically by administrator right, language C#, the code no bug, but I can't write the key on registry. can you help me to find bug?. private void AutoLoginByAdmin()...
1
by: celery6541 | last post by:
Hi, I am trying to link to an image, but it is behind an https server so it asks me for a login and password every time I access the image. I have the login and password, but is there a way to...
1
by: carl2k2 | last post by:
Ok First I have a very simple way of entering data into a form and saving that into a text file, I made two text files for username(text1) and password(text2), I would like to make a simple login...
1
by: Rob Eventine | last post by:
hello, i really need this little problem solving... i have used the asp.net login / registration wizards to set up a secure area. everything works great but not when uploaded to the server....
2
by: dgbb | last post by:
Hi, I have read many posts and have tried many solutions to this problem. Simply enough, I can assign a role to a user programically during development, but when I publish to the 'web', the...
2
by: Kambehba | last post by:
I am trying to develop a C sharp application that I can click on different icons and automatically be logged in to the related web site to that icon. For example one of my credit cards website. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.