?
Solved

what is wrong in this session id code?

Posted on 2002-05-08
9
Medium Priority
?
280 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
[X]
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
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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 200 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

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

771 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