Page 1 of 1
checking to see if user is loged in?
Posted: Tue Jul 29, 2003 3:42 pm
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====================================
Posted: Tue Jul 29, 2003 4:16 pm
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.
Posted: Tue Jul 29, 2003 6:06 pm
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?)
Posted: Tue Jul 29, 2003 6:42 pm
by JPlush76
I came from coding asp to php and man am I glad I did. what a waste of coding time
Posted: Tue Jul 29, 2003 11:37 pm
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??
...
Posted: Wed Jul 30, 2003 12:49 am
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.
Posted: Wed Jul 30, 2003 8:56 am
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.
Posted: Wed Jul 30, 2003 2:19 pm
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?