Solved

what is wrong in this session id code?

Posted on 2002-05-08
9
257 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 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

15 Experts available now in Live!

Get 1:1 Help Now