Hi everyone, how are yall doing?
I am developing a system where upon login (valid username and password) a session is started.
$session = new CGI::Session("driver:File", undef, {Directory=>"/tmp"});
$cookie = $cgi->cookie(CGISESSID => $session->id);
print $cgi->header( -cookie=>$cookie );
I want to check at top of every page if the session is still valid or the user has logged out. If the user has logged out they should be redirected to the login.pl page.
$sid = $cgi->cookie("CGISESSID") || undef;
$session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
My concern is if someone has logged out, or the CGISESSID cookie is not set at all and if some one creates a cookie with name CGISESSID (using tools like firefox webdeveloper too) they could not be granted access.
I have been trying to fix this for 2-3 days but its just not happening
I would really apprecite if you could provide me with the script for creating session after successful login and validating this session at everypage.
Thankyou all for your prompt help and concern.
-Rakesh Gupta
|
Team Leader
|
![]() |
| 28Jul2006,17:58 | #2 |
|
Hi Rakesh,
Well, to block users from other IPs using a fake cookie we need to use use CGI::Session ( '-ip_match' ); Well, I've created a login page an index page, with login/logout capabilities, trying viewing the index page without logging in. login.pl Code: Perl
index.pl Code: Perl
I hope this solves your problem.
sundeep.kumar
likes this
|
|
Go4Expert Member
|
|
| 1Aug2006,20:56 | #3 |
|
Thank you pradeep,
The sessions are finally working for me.. -Rakesh |
|
Team Leader
|
![]() |
| 14Jun2007,17:01 | #4 |
|
Try upgrading CGI::Session to the latest version!
|
|
Go4Expert Member
|
|
| 17Dec2009,13:46 | #5 |
|
hi pradeep i am not able to get this working could you please give some explanation about the variables and i am also concerned about checking the inputs agains a MYSQL database ..
|
|
Go4Expert Member
|
|
| 18Dec2009,13:07 | #6 |
|
hi pradeep it would be very heklpful if you could explain about this block of code
if($usr ne '') { # process the form if($usr eq "demo" and $pwd eq "demo") { $session = new CGI::Session(); print $session->header(-location=>'index.pl'); } from login.pl ... please help me out ASAP .... |
|
Ambitious contributor
|
![]() |
| 18Dec2009,16:35 | #7 |
|
Quote:
Originally Posted by sundeep.kumar Suppose if some username has been typed, then it will be checked for authentication. In this code, the value "demo"(see part 2) is used for an example. In your case, you have to use the value that you get from the MySQL database. If the authentication is successful, then a session is created for that user and the page is redirected to the main index page using part 3.
sundeep.kumar
likes this
|
|
Go4Expert Member
|
|
| 19Dec2009,13:35 | #8 |
|
Thank you venami .. i am able to run the code the code it's working now ... thanks once again for helping me out
|
|
Go4Expert Member
|
|
| 9Jan2010,01:25 | #9 |
|
friends sorry to bother again i would like to know how one can create a web page where a user log's in and thereafter unless and untill users logs out or session gets expired there should be no login page ... just like in gmail or yahoo .. i would like to know regarding this ..
|
|
Ambitious contributor
|
![]() |
| 9Jan2010,08:53 | #10 |
|
Code:
if(cond) //Check whether user logged in, using the session variables.
{
Display the home page without the "log in" link.
}
else //means user has not logged in.
{
Display the log in page.
}
Please see the previous posts in this thread. Pradeep has given you the code itself.
Last edited by venami; 9Jan2010 at 08:56.. Reason: Added extra note. |



