Solved

what is wrong in this session id code?

Posted on 2002-05-08
9
263 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

809 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