![]() |
Login and Logout using Sessions and Cookies
1 Attachment(s)
This is a very simple code and hardly requires any explanations. :eek: If you need any put the post here.
functions.php PHP Code:
PHP Code:
PHP Code:
|
Re: Login and Logout using Sessions and Cookies
Hello Mr. Shabbir
I m grateful for this code but can you help me learning php more.. i have joined a forum www.tufat.com/foums and found it very helpful. but i need your guidence to learn more about php. Regards |
Re: Login and Logout using Sessions and Cookies
Quote:
|
Re: Login and Logout using Sessions and Cookies
Thanks and great job :P
|
Re: Login and Logout using Sessions and Cookies
Hello Mr. Shabbir
The code works well, but after logging out, somebody could hit the back button and see any data on the pages. How difficult would it be to prevent anyong seeing the pages after a logout just like the web sites for all the banks? |
Re: Login and Logout using Sessions and Cookies
For that probably you need to be clearing the cache because thats not the actual page but the cache version and applying some metas can even prevent that.
|
Re: Login and Logout using Sessions and Cookies
does anyone know how to add mutiple accounts to this script?
|
Re: Login and Logout using Sessions and Cookies
*ps. if mutiple accounts are allowed, is it possible to have an echo that shows who is logged in right now? thank you very much, Ted.
|
Re: Login and Logout using Sessions and Cookies
Multiple sessions cannot be added to this script, only one user per session/per browser can be logged in at a time.
|
Re: Login and Logout using Sessions and Cookies
oh, okay thanks!
|
Re: Login and Logout using Sessions and Cookies
by the way, where do I place my html code?
|
Re: Login and Logout using Sessions and Cookies
Place the HTML preferably after the session PHP code.
|
Re: Login and Logout using Sessions and Cookies
<?php
ob_start(); session_start(); ?> ********** You mean here? ********** <? require_once ("functions.php"); if (checkLoggedin()) echo "<H1>You are already logged in - <A href = \"login.php?do=logout\">logout</A></h1>"; else echo "<H1>You are not logged in - <A href = \"login.php\">login</A></h1></h1>"; ?> |
Re: Login and Logout using Sessions and Cookies
Yeah, right! But you may need to include or require your files before that, you can include your files, before the session code.
|
Re: Login and Logout using Sessions and Cookies
okay, ive solved that problem, now, if i want to store username and password in another txt file, what would i have to put in the main php page codes?
eg. Code:
if(file('logindata.txt')) |
Re: Login and Logout using Sessions and Cookies
It would be something like this
Code: PHP
|
Re: Login and Logout using Sessions and Cookies
where do i paste this in?
<?$username = $_SESSION['usr'];$pwd = $_SESSION['pwd'];$h = fopen("userdata.txt");fwrite($h,"$username\n$pwd\n \n");fclose($h);?> and what do the "\n" stand for? |
Re: Login and Logout using Sessions and Cookies
oh no, sorry, i think i didn't say it clearly, what i wish is to extract the information of username and password FROM the text file, not store them into the txt files. Thanks for understanding.
|
Re: Login and Logout using Sessions and Cookies
\n stands for newline. Visit http://in2.php.net/types.string for more escape sequences.
|
Re: Login and Logout using Sessions and Cookies
Well then you have to store the data in text files, in a specific format say user:location:age OR user#ocation#age, so that the data retrieval becomes easy.
All you have to do is to read the text file line by line, and split it by the separator you have chosen (: or #) and then check the username part for a match. Bingo! you got your record. |
Re: Login and Logout using Sessions and Cookies
can you write an eg. and send the file to me with zip?
|
Re: Login and Logout using Sessions and Cookies
i just want a simple example. With the username and age in the text file and the codes that you have to include in the php page, thanks so much.
|
Re: Login and Logout using Sessions and Cookies
spiderman, you not there...? HELP ASAP
|
Re: Login and Logout using Sessions and Cookies
Try this out, hope you got the point!
Code: PHP
Sample text file: Code:
pradeep#g4e#Kolkata |
Re: Login and Logout using Sessions and Cookies
hey, thanks a lot. it finally worked :) :cool:
|
Re: Login and Logout using Sessions and Cookies
hi, again.
As i got this to work, things got more complicated, here PHP Code:
|
Re: Login and Logout using Sessions and Cookies
Code: PHP
|
Re: Login and Logout using Sessions and Cookies
oh, so you dont separte the data?
|
Re: Login and Logout using Sessions and Cookies
Can you give me another example please?
I cant get it to work ps. please do include the txt file as well, a big "pre"thanks! |
Re: Login and Logout using Sessions and Cookies
Good script, got a question though, if we have multiple servers with various configurations in load balancing, and we try to maintain a session, that session will be lost when either round robin on next connection is in effect, so sessions is not an option due to persistence issues, and we don't want to enable persistence through the firewall, as it is not under our control. so we would need to rely on the cookie credentials for every page call to validate the user log in!
also, due to distributed database architecture, we can not maintain credentials in the database either. So we would need to take the cookie credentials and validate on every page. and pass other data via http header. What is the modification to this script if sessions are not available, but still maintain security? |
Re: Login and Logout using Sessions and Cookies
i need more explanation about that code..please help me
|
Re: Login and Logout using Sessions and Cookies
The code snippet provided is quite self-explanatory, what exactly are you failing to understand?
|
Re: Login and Logout using Sessions and Cookies
I am attemptin gto modify your script to work on my server as a session / user manager authenticator. Logically i can follow th eprogram flow, but I am running in to 2 issues which i hope you are able to assit me with. Any help would be appreciated.
1.) Inside "function confirmUser" i have added the following text to connect to my database and get the information i want to verify (tested this portion alone in a test.php file and i get success when echoing "SUCCESS" on return true) <----- BEGIN CODE SNIPPET Code:
//Connecting, selecting database^----- END CODE SNIPPET 2. Inside login.php, the section as below is not passing errors when username/pword are blank <------ BEGIN CODE SNIPPET Code:
case "login": The page index.php correctly passes me to login.php, i enter a username password, and get returned to the login UName PWord boxes with no error output. Thanks for any assistance and nice elegant code that was easy to follow barring this issue. Qaladien |
Re: Login and Logout using Sessions and Cookies
Try writing
Code: PHP
As Code: PHP
|
Re: Login and Logout using Sessions and Cookies
the password is stored in the database as MD5 not in raw form so i can drop the MD5 you have in the variable right?
|
Re: Login and Logout using Sessions and Cookies
yeah right!
|
Re: Login and Logout using Sessions and Cookies
Hi, am I right in seeing that login.php calls confirmUser() with a plaintext password but if a cookie is present and its called from the checkloggedin() function the password is sent to confirmuser() in MD5 format?
|
Re: Login and Logout using Sessions and Cookies
Quote:
|
Re: Login and Logout using Sessions and Cookies
Quote:
In login.php just change it to: if(confirmuser($username,md5($password))) works since the session and cookie stored password is MD5 always. |
Re: Login and Logout using Sessions and Cookies
I have rectified the error.
|
| All times are GMT +5.5. The time now is 04:44. |