Solved

what is wrong in this session id code?

Posted on 2002-05-08
9
260 Views
Last Modified: 2013-12-25
hi
Im new to cgi/perl .
something is wrong with the following code to create sessions.
it is working fine in console and creating session ids too.but not when we try it on Konquerer.

#!/usr/bin/perl

use CGI;
use Apache::Session::File;

my $query = new CGI;
my %session;
my $id = undef;

$id = $query->cookie(-name=>"sess");

tie %session, 'Apache::Session::File', $id,
      { Directory => "/tmp/",
      LockDirectory => "/tmp/"};

if ($id == undef) {
   $cookie = $query->cookie( -name=>'sess',
         -value=>$session{_session_id},
         -expires=>'+1y',
         -path=>'/session');
   print $query->header(-cookie=>$cookie);
   print "Assigned session ID<br>";
} else {
   print $query->header();
   print "Not assigned session ID<br>";
}

$id = $session{_session_id};

print "<html>";
print " Your session ID is $id";
print "</html>";

-------------------------------------------
2)when we try to create simple session ids (using random numbers)and store it in cookies
using
print "Set-Cookie:........ etc
it  works in konquerer too .

can u find what is wrong with the code?

0
Comment
Question by:dinas
  • 4
  • 3
9 Comments
 
LVL 15

Expert Comment

by:samri
ID: 6997959
Perhaps there must be something to do with Konquerer.  I do not have much experience with Konquerer but try to test with other Browsers; Netscape, IE, Opera, etc.  It it works for other, then work on Konquerer.  There must be some setting that needs to be enable/disable there.

just a thought.

cheers
0
 

Author Comment

by:dinas
ID: 6998131
thank you samri,

it worked when i replaced the $query->header() part with just the ordinary
 print "Set-Cookie:sesn=$session{_session_id}......

but can u tell me how the session id assigned in one page can b retrieved in another page for checking when we r using  Apache::Session::File .i dont want to use cookie .
is it possible?
0
 
LVL 15

Expert Comment

by:samri
ID: 6998168
dinas,

I do not have much experience with Apache::Session perl modules.  I would try to look for information, but I can't guarantee that I could respond fast.

cheers.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 15

Expert Comment

by:samri
ID: 6998172
Perhaps you could take a look at the following site.

http://aspn.activestate.com/ASPN/CodeDoc/Apache-Session/Session.html
0
 

Author Comment

by:dinas
ID: 6998208
thanks samri

i did take a look at the site, and many other sites too which explain Apache::Session::File, but every site contains the same explanation as is given in the Documentation of the module.

every where it says

Tie a session to Apache::Session.
Get the ID number.
Store the ID number in a cookie.
End of Request 1.
 
  (time passes)
 
  Get the cookie.
Restore your hash using the ID number in the cookie.
Use whatever data you put in the hash.
End of Request 2.
 

can this b used without using a cookie?

please take ur time.
but do try to help.


0
 
LVL 15

Accepted Solution

by:
samri earned 50 total points
ID: 6998331
The only way that I can think of is to have your user to go thru an authentication process (username/email etc.).  Once it's done, keep track of the user session in some kind of database.

This way you should be able to track user session within your websites.  Depending on what you want to track, you should be able to use the Environment Variable (if you use BASIC AUTHENTICATION), and update the database for any activities you wish (like visiting certain pages for example).

I personally never tried (haven't come to work on such), but logically it should work, since, it works almost the same way, except by using cookie, it would be transparent to the client (browser).

I would (personally) feels that the cookie method is best, but regardless of how good the method, once you're stuck, it's better to work on the alternatives.

0
 

Author Comment

by:dinas
ID: 7000539
thanks samri

i'll try and let u know if something goes wrong........

 
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now