Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

what is wrong in this session id code?

Posted on 2002-05-08
9
267 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

856 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