checking to see if user is loged in?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
robmann
Forum Newbie
Posts: 2
Joined: Tue Jul 29, 2003 3:42 pm

checking to see if user is loged in?

Post by robmann »

Below is the code that I sed when my pages were in ASP to check to see if the user was loged in before opening the page, how would I need to change so that it works with PHP?
Thanks

'===========================VERIFY USER============================

dim userid, username,level

userid = session("userid")
username = session("username")
level = session("level")

if userid = "" THEN
response.redirect("../error.htm")
elseif level >= 0 THEN
Dim dbconn, res
Set dbconn=Server.CreateObject("ADODB.Connection")
dbconn.open("suspension")
Set res = DBConn.Execute("SELECT * FROM members WHERE id = '" & userid & "'")
else
response.redirect("../error.htm")
end if
'==============================END====================================
graphicmd
Forum Newbie
Posts: 8
Joined: Mon Jul 28, 2003 11:37 pm

Post by graphicmd »

It is really easy in PHP. This is a simple version of how I do it.

Code: Select all

if (isset($_SESSIONї'username'] || $_COOKIEї'username'])) {
  $logged = 1;
}else{
  $logged = 0;
}
You know if a session is set, or a cookie has been set, the username has already been verified.
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

Post by mikusan »

Boy if that is really all the code it takes to identify a user in ASP i am definitely glad that i have chosen the path of PHP. And no offense to the OP, ASP seems to be some pretty ugly code (was that an oxymoron right there?)
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

I came from coding asp to php and man am I glad I did. what a waste of coding time
cj2000
Forum Newbie
Posts: 7
Joined: Wed Jul 23, 2003 8:01 am

Post by cj2000 »

Hi,

just an extension to the previous question. The previous code checks if a particular user is logged onto the web site. But how do I display the TOTAL number of users/people browsing the page now??
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post by kettle_drum »

You need to store the IP addresses of people visiting your page, along with the time they visited. Then you can manipulate this data to show that say 5 people have been on your site in the last 5 mins.

If you also have registered users then do the same sort of thing but store the username.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Note that the OP included code for connecting to the database and checking for a paticular user. I know ASP provided session-like variables and application-wide variables, so I suspect the OP'er was doing those checks for a reason. Therefore the provided PHP code should not be viewed as an appropriate translation.
robmann
Forum Newbie
Posts: 2
Joined: Tue Jul 29, 2003 3:42 pm

Post by robmann »

Thanks
but can not seem to get it to work,
How about we only check to see if user is logged in, get that working then maybe I can work on the other. Do I need to set a session varable when they do login? If so how would I do that?
Post Reply