Tatsuhiko Miyagawa > PHP-Session-0.27 > PHP::Session

Download:
PHP-Session-0.27.tar.gz

Dependencies

Annotate this POD

Related Modules

Apache::ASP
CGI::Application
HTML::FillInForm
Data::Dumper
CGI::Lite
more...
By perlmonks.org

CPAN RT

New  5
Open  2
View/Report Bugs
Module Version: 0.27   Source  

NAME ^

PHP::Session - read / write PHP session files

SYNOPSIS ^

  use PHP::Session;

  my $session = PHP::Session->new($id);

  # session id
  my $id = $session->id;

  # get/set session data
  my $foo = $session->get('foo');
  $session->set(bar => $bar);

  # remove session data
  $session->unregister('foo');

  # remove all session data
  $session->unset;

  # check if data is registered
  $session->is_registered('bar');

  # save session data
  $session->save;

  # destroy session
  $session->destroy;

  # create session file, if not existent
  $session = PHP::Session->new($new_sid, { create => 1 });

DESCRIPTION ^

PHP::Session provides a way to read / write PHP4 session files, with which you can make your Perl application session shared with PHP4.

If you like Apache::Session interface for session management, there is a glue for Apache::Session of this module, Apache::Session::PHP.

OPTIONS ^

Constructor new takes some options as hashref.

save_path

path to directory where session files are stored. default: /tmp.

serialize_handler

type of serialization handler. Currently only PHP default serialization is supported.

create

whether to create session file, if it's not existent yet. default: 0

auto_save

whether to save modification to session file automatically. default: 0

Consider cases like this:

  my $session = PHP::Session->new($sid, { auto_save => 1 });
  $session->set(foo => 'bar');

  # Oops, you forgot save() method!

If you set auto_save to true value and when you forget to call save method after parameter modification, this module would save session file automatically when session object goes out of scope.

If you set it to 0 (default) and turn warnings on, this module would give you a warning like:

  PHP::Session: some keys are changed but not modified.

EXAMPLE ^

  use strict;
  use PHP::Session;
  use CGI::Lite;
  my $session_name = 'PHPSESSID'; # change this if needed

  print "Content-type: text/plain\n\n";
  
  my $cgi = new CGI::Lite;
  
  my $cookies = $cgi->parse_cookies;
  if ($cookies->{$session_name}) {
     my $session = PHP::Session->new($cookies->{$session_name});
     # now, try to print uid variable from PHP session
     print "uid:",Dumper($session->get('uid'));
  } else {
     print "can't find session cookie $session_name";
  }

NOTES ^

TODO ^

AUTHOR ^

Tatsuhiko Miyagawa <miyagawa@bulknews.net>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO ^

Apache::Session::PHP, WDDX, Apache::Session, CGI::kSession

syntax highlighting: