473,386 Members | 1,708 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,386 software developers and data experts.

conditions on login code

anfetienne
424 256MB
hi

i have this code for login using a database

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $username="********";
  3. $password="********";
  4. $database="auctionTemps";
  5.  
  6. // Connect to server and select databse.
  7. $connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
  8.  
  9. mysql_select_db("$database") or die("Unable to select database!");
  10.  
  11. // username and password sent from form
  12. $myusername=$_POST['myusername'];
  13. $mypassword=$_POST['mypassword'];
  14.  
  15. // To protect MySQL injection (more detail about MySQL injection)
  16. $myusername = stripslashes($myusername);
  17. $mypassword = stripslashes($mypassword);
  18. $myusername = mysql_real_escape_string($myusername);
  19. $mypassword = mysql_real_escape_string($mypassword);
  20.  
  21. $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'";
  22. $result=mysql_query($sql);
  23.  
  24. // Mysql_num_row is counting table row
  25. $count=mysql_num_rows($result);
  26. // If result matched $myusername and $mypassword, table row must be 1 row
  27.  
  28. if($count==1){
  29. // Register $myusername, $mypassword and redirect to file "login_success.php"
  30. session_register("myusername");
  31. session_register("mypassword");
  32. header("location:tsandcs.php");
  33. }
  34. else {
  35. header("location:incorrect.php");
  36. }
  37. ?>
  38.  
the part of it that i want to ask about is the part i add to all my pages that redirects all users back to a certain page if they are not logged in is this code

Expand|Select|Wrap|Line Numbers
  1. <?
  2. session_start();
  3. if(!session_is_registered(myusername)){
  4. header("location:index.php");
  5. }
  6. ?>
  7.  
what i want to do is check if the username is in the database which it does already but also check if the email address that is stored with the username has been confirmed.

the system im building goes like this.

1. user clicks register
2. they enter user details email, password and username
3. then the enter their name and postal details which are passed to paypal.
4. they then enter their payment details for the subscription.
5. once completed paypal they are directed back to a page where they confirm their email address.
6. once confirmed they are able to login.

the aim is to make sure that people don't get access to the site without completing the full process as it's a subscription site
Apr 29 '09 #1
4 2872
Markus
6,050 Expert 4TB
WARNING! WARNING! The use of session_is_registered() and register_session is being dropped completely from PHP6 and deprecated from something like 5.3.

Instead, to set sessions, add them directly to the SESSION array, and to check if a session exists, use isset() on the session key.

Expand|Select|Wrap|Line Numbers
  1. $_SESSION['username'] = 'username';
  2.  
  3. if (isset($_SESSION['username']))
  4. {
  5.     // session is registered
  6. }
  7.  
You should have a flag in your database table, something like 'email_confirmed'. When the user confirms their email, you update this to '1' or 'y' or whatever you want, otherwise, the email remains unconfirmed.

Then, in your WHERE clause add "AND email_confirmed = 'y'"

Mark.
Apr 29 '09 #2
anfetienne
424 256MB
how do i do add for it to check not just the user name but if they email has been confirmed?

like 0=not confirmed 1=confirmed

also do i just simply swap the coding around?

changing register session for $_SESSION['username'] = 'username';

and if(!session_is_registered(myusername)){ for if (isset($_SESSION['username']))
Apr 29 '09 #3
Markus
6,050 Expert 4TB
@anfetienne
1. Add an extra bit to the WHERE clause.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM `tbl` WHERE `col1` = 'x' AND `col2` = 'y' AND `col3` = '1'
  2.  
2. Yes. But remember the ! in before your isset() call.
Apr 29 '09 #4
anfetienne
424 256MB
great ill test that now.....thanks markus
Apr 29 '09 #5

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

Similar topics

6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
7
by: Michael Bray | last post by:
I have an application that has a webservice, and the web service is utilizing Application variables to store login tokens for clients. However, the application variable seems to be disappearing on...
4
by: Freedolen | last post by:
Hi All, I had a perl script which is used to login in a web page, but it gives the error as "301 Moved Permanently". What does this means and how can it be rectified? Can anyone help on this? ...
1
by: mlgmlg | last post by:
Hello, I have a text box (on a Single Form) that I use to color code milestones based on a value. I use the “Conditional Formatting” tool to format four of the conditions, which works great! ...
12
by: =?ISO-8859-1?Q?Ren=E9?= | last post by:
Hi, is there a rule of thumb what is better/faster/more performant in SQL Server 2005? a) SELECT * FROM A INNER JOIN B ON B.ID = A.ID AND B.Cond1 = 1 AND B.Cond2 = 2 b) SELECT * FROM A INNER...
10
by: DavidPr | last post by:
When I logout as one user and log in under a different user, it opens with the last user's information. User 1 - Unsername: Davey Jones User 2 - Unsername: David Smith I log out from Davey...
0
by: moltendorf | last post by:
I've been trying to find a suitable method for preventing race conditions in my own code. Currently I'm using a file and the flock function to prevent code in other threads from executing at the...
4
by: Prashanth Kumar B R | last post by:
Hi, I have situation in C++ where in I'll have to add around 20-25 conditions <compare a variable against a number> to an if statement. Is there any limit on the number of expressions/conditions...
13
by: Apostle | last post by:
Hi all, after thinking for sometimes, I thought it will be great opportunity to learn if I will start from scratch and build my own register/login system. Here is the thread that I will be posting...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.