shahrahulb
asked on
cgi session
I have a page http://blah/test.cgi
there is a login button on this page
as soon as someone logins i want to change the page http://blah/test.cgi simply by ading couple of buttons.
how can i do that?
there is a login button on this page
as soon as someone logins i want to change the page http://blah/test.cgi simply by ading couple of buttons.
how can i do that?
ASKER
when i run 1.cgi, it is creating the file cgisess_sessionid in /u/uname/www/temp directory
when i do cat cgisess_1ea55e0535761d4361 c1c3abcf3f e092
$D = {"l_name" => "1ea55e0535761d4361c1c3abc f3fe092"," _SESSION_E XPIRE_LIST " => {},"_SESSION_REMOTE_ADDR" => "172.19.31.217","_SESSION_ ATIME" => "1124205645","_SESSION_CTI ME" => "1124205645","_SESSION_ID" => "1ea55e0535761d4361c1c3abc f3fe092"," _SESSION_E TIME" => undef};
how do i retrieve l_name in my other script 2.cgi
when i do cat cgisess_1ea55e0535761d4361
$D = {"l_name" => "1ea55e0535761d4361c1c3abc
how do i retrieve l_name in my other script 2.cgi
ASKER
does it always create the file with name cgises_sessionid
Did you see
perldoc CGI::Session::Tutorial
perldoc CGI::Session::Tutorial
ASKER
i have seen but i m stuck at 1 point:
in 1 script i m doing and passing $CGISESSID to script 2 using form parameters.
my $session = new CGI::Session("driver:File" , undef, {Directory=>'/u/uname/www/ temp/'});
my $CGISESSID = $session->id();
$session->param(-name=>'l_ name', -value=>$CGISESSID);
how do i retriev the session id value in my other script from the file so that i can compare that with sessionid of the form parameter
in 1 script i m doing and passing $CGISESSID to script 2 using form parameters.
my $session = new CGI::Session("driver:File"
my $CGISESSID = $session->id();
$session->param(-name=>'l_
how do i retriev the session id value in my other script from the file so that i can compare that with sessionid of the form parameter
ASKER
under the heading: ACCESSING STORED DATA
it says name = $session->param("my_name") ;
but how do i initialize session in script 2
it says name = $session->param("my_name")
but how do i initialize session in script 2
why do u have to initalize a new session in script2 ?as far as i underatnd, you want to maintain state between script1 and script2. In that case, in script 1, initialize a session and send the session id as a cookie to the client. In script2, do not initalize. Rather read the cookie and initalize the sesison by passing the second argument to the constructor as the cookie value obtained instead of undef.
Manav
Manav
ASKER
yes i want to maintain session between script 1 and script 2.
in script 1 i m initializing a session and saving in disk
my $session = new CGI::Session("driver:File" , undef, {Directory=>'/u/uname/www/ temp/'});
now in script 2, how do i retrieve this session id from disk so that i can compare this value with the session id passed thru the url as query parameter
i dont want to use cookies.
in script 1 i m initializing a session and saving in disk
my $session = new CGI::Session("driver:File"
now in script 2, how do i retrieve this session id from disk so that i can compare this value with the session id passed thru the url as query parameter
i dont want to use cookies.
Then you can pass it as a hidden field in any of your form.
ASKER
Here is what I am planning to do. Please let me know, if I am correct.
In my script 1, I will do
my $session = new CGI::Session("driver:File" , undef, {Directory=>'/u/uname/www/ temp/'});
my $CGISESSID = $session->id();
$session->param(-name=>'l_ name', -value=>$CGISESSID);
$session->expire('+5m');
what this does basically is, it creates a file in temp directory
> cat cgisess_1ea55e0535761d4361 c1c3abcf3f e092
$D = {"l_name" => "1ea55e0535761d4361c1c3abc f3fe092"," _SESSION_E XPIRE_LIST " => {},"_SESSION_REMOTE_ADDR" => "172.19.31.217","_SESSION_ ATIME" => "1124205645","_SESSION_CTI ME" => "1124205645","_SESSION_ID" => "1ea55e0535761d4361c1c3abc f3fe092"," _SESSION_E TIME" => 300};
Now from script 1 i go to page script 2 and pass the parameter, sid=1ea55e0535761d4361c1c3 abcf3fe092
In script 2, i will grab the parameter, $sid = param('sid')
then i will open the file cgisess_$sid and grab the paramter "_SESSION_ID" if this value matches with $sid, means the session is valid, otherwise invalid.
Does this makes sense?
The only problem how can i delete that session, if i don't delete, the file cgisess_1ea55e0535761d4361 c1c3abcf3f e092 will remain on the server forever. I can delete if someone hits logout button,but what if someone does not hit logout button and close the browser.
In my script 1, I will do
my $session = new CGI::Session("driver:File"
my $CGISESSID = $session->id();
$session->param(-name=>'l_
$session->expire('+5m');
what this does basically is, it creates a file in temp directory
> cat cgisess_1ea55e0535761d4361
$D = {"l_name" => "1ea55e0535761d4361c1c3abc
Now from script 1 i go to page script 2 and pass the parameter, sid=1ea55e0535761d4361c1c3
In script 2, i will grab the parameter, $sid = param('sid')
then i will open the file cgisess_$sid and grab the paramter "_SESSION_ID" if this value matches with $sid, means the session is valid, otherwise invalid.
Does this makes sense?
The only problem how can i delete that session, if i don't delete, the file cgisess_1ea55e0535761d4361
1)
Instead of setting sesion id as a session parameter(which sounds really confusing), pass it as a hidden value in the form. In script2, which is called by the above-mentioned form, access the hidden param using a CGI object.
Alternatively, you can set the hidden field name as CGISESSID in script1. In this case, you can directly pass the CGI object for initializing the session in script2.
$session_for_script_2 = new CGI::Session(undef, $cgi, {Directory=>"/u/uname/www/ temp/"}); ##in script2
This will automatically extract the session id as either the cookie or the hidden field. The session will be initialized with the same session id as the id obtaioned in script1. In script2, you need not access the file directly. The session so initialized can be used to fetch the session parameters set.
For example, if my_name was a session parameter set in script1, you can access it in script2 using
$my_new_name = $session_id_for_script2->p aram('my_n ame') ;
$session_delete() will clear the session from disk.
Instead of setting sesion id as a session parameter(which sounds really confusing), pass it as a hidden value in the form. In script2, which is called by the above-mentioned form, access the hidden param using a CGI object.
Alternatively, you can set the hidden field name as CGISESSID in script1. In this case, you can directly pass the CGI object for initializing the session in script2.
$session_for_script_2 = new CGI::Session(undef, $cgi, {Directory=>"/u/uname/www/
This will automatically extract the session id as either the cookie or the hidden field. The session will be initialized with the same session id as the id obtaioned in script1. In script2, you need not access the file directly. The session so initialized can be used to fetch the session parameters set.
For example, if my_name was a session parameter set in script1, you can access it in script2 using
$my_new_name = $session_id_for_script2->p
$session_delete() will clear the session from disk.
ASKER
this seems to be more clear. still what is $cgi in script 2
but what do u think, should i use session or can i use CGI::Cookie which is more simpler and no need o save data on the disk
but what do u think, should i use session or can i use CGI::Cookie which is more simpler and no need o save data on the disk
ASKER
also manav can u please answer https://www.experts-exchange.com/questions/21530161/expert-exchange-cookie-issue.html
i need to decide whether to go for CGI::Session or CGI::Cookie
i need to decide whether to go for CGI::Session or CGI::Cookie
> this seems to be more clear. still what is $cgi in script 2
$cgi is a CGI object
$cgi = new CGI ;
>but what do u think, should i use session or can i use CGI::Cookie which is more simpler and no
need o save data on the disk
Cookie is one of the method of handling CGI state sessions, the other being hidden fields.
It depends on
$cgi is a CGI object
$cgi = new CGI ;
>but what do u think, should i use session or can i use CGI::Cookie which is more simpler and no
need o save data on the disk
Cookie is one of the method of handling CGI state sessions, the other being hidden fields.
It depends on
ASKER
i guess even expert exchange works on cookie EELOGIN
ASKER
if i manually delete the cookie EELOGIn then i have to re login, if i disable cookie, it says, cookies should be eanbled. my question is how do i come to know whether clients browser is acception or rejecting cookies?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I was using the example given on CGI::Application to build a login page and display the user home. The login page does not seem to work and no errors occur, the login page keeps looping on to itself.
I have the template file using the "rm" to change the runmode to validating the login page, the sub validating the user input is looped back to the login page, exactly the way the example does.
the subsequent run methods are defined,
what could I have done is the design of the flow that could have caused this flaw. What are the usual mistakes most people commit.
thanks,
Rana
I have the template file using the "rm" to change the runmode to validating the login page, the sub validating the user input is looped back to the login page, exactly the way the example does.
the subsequent run methods are defined,
what could I have done is the design of the flow that could have caused this flaw. What are the usual mistakes most people commit.
thanks,
Rana
ASKER
my $session = new CGI::Session("driver:File"
my $CGISESSID = $session->id();
$session->param(-name=>'l_
how do i retriev the session id value in my other script