[PHP] Re: mediator between PHP and Perl (with sessions)

2005-02-15 Thread Eli
It's quite easy to pass the session variables to the script. The problem 
with sessions and shell PHP scripts, is that PHP doesn't support 
sessions on that mode (CLI mode it is called). So, I would have to 
manualy read the session file and parse it. If anyone knows what is the 
exact function that is used to unserialize the session file, please 
tell.. and it's not the unserialize() function in PHP.

I guess that using a shell PHP script with sessions is not the solution. 
Is anybody familiar with another way to use sessions??? but not through 
web, since the script returns sensitive data.

-thanks, Eli
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: mediator between PHP and Perl (with sessions)

2005-02-15 Thread Richard Lynch
Eli wrote:
 It's quite easy to pass the session variables to the script. The problem
 with sessions and shell PHP scripts, is that PHP doesn't support
 sessions on that mode (CLI mode it is called). So, I would have to
 manualy read the session file and parse it. If anyone knows what is the
 exact function that is used to unserialize the session file, please
 tell.. and it's not the unserialize() function in PHP.

 I guess that using a shell PHP script with sessions is not the solution.
 Is anybody familiar with another way to use sessions??? but not through
 web, since the script returns sensitive data.

I THINK you MIGHT be able to use some session functions to set the session
name and session file when you do session_start() and get PHP to do all
the work of the reading/writing the files.  You just need to pass in the
session ID to session_name() or session_start() or something like that.  I
forget how to do this, but I did it once when I couldn't get trans-sid to
work, and it was a one-line solution.  Try to find it.  Maybe session_id()
takes an optional argument.

If that fails, then here's option 2:

There is sample code for storing your session data in MySQL on the
web-site in the manual.

You could easily take that code and swap out the MySQL bits to just
read/write your own session files, or go ahead and use MySQL if it's okay
security-wise, or put the data anywhere you feel appropriate for your
application.


If that's not auitable, to answer your original question :-) is Option 3:

I think the session files consist of a series of variable names and
serialized values separated by semi-colons or something like that.

So to read/write the session files would be something not unlike:
$data = file($session_file);
$elements = explode(';', $data);
while (list(, $element) = each($elements)){
  list($var, $serialized) = explode(':', $element);
  $$var = unserialize($serialized);
}

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: mediator between PHP and Perl (with sessions)

2005-02-15 Thread Warren Vail
Eli,

Sessions work just fine with CLI (Command Line Interpreter), although there is 
little need for them as a CLI script, since once started the script does not 
wait on user clicks of a browser for it's next set of input, therefore no need 
to use sessions for passing information.  Most CLI scripts are started via a 
cron process, and if started from a webpage, the items passed to the script can 
be passed via command line parameters, or if passed as session variables, the 
session key needs to be passed to the CLI script, since CLI scripts don't have 
access to cookies.  One advantage of using session variables when starting a 
CLI script, is that the session may be able to pass bigger values than can be 
contained in a command line. (Command line variables can be accessed in the 
argc/argv array like in c) and once passed this way the sessions are no 
longer needed since your CLI script will run to completion.

If your server is a NIX box, you may have access to the  character after the 
command name that will cause it to run as a separate shell script, but you will 
need to set the timeout to allow it to run long enough, and if you do not use 
the  separate shell character, the script will be interruptible by the user 
who started it by clicking a button like stop on his browser.

The unserialize function is indeed used for sessions, but with most newer 
releases of PHP register variables is turned off, which means the variables 
are not restored automatically (you will find them in the $_SESSION array).  
Sections of the manual you may want to reread are as follows;

http://www.php.net/manual/en/ref.session.php
http://www.php.net/manual/en/function.session-set-save-handler.php (good 
illustrations of what happens in sessions)
http://www.php.net/manual/en/function.session-register.php (notice the notes on 
register variables).
http://www.php.net/manual/en/function.session-id.php
http://us3.php.net/manual/en/function.set-time-limit.php to allow script to run 
longer.
http://us3.php.net/manual/en/function.shell-exec.php for starting a cli script 
(don't forget to start php).

hope this helps,

Warren Vail

 -Original Message-
 From: Eli [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, February 15, 2005 7:07 AM
 To: php-general@lists.php.net
 Subject: [PHP] Re: mediator between PHP and Perl (with sessions)
 
 
 It's quite easy to pass the session variables to the script. The problem 
 with sessions and shell PHP scripts, is that PHP doesn't support 
 sessions on that mode (CLI mode it is called). So, I would have to 
 manualy read the session file and parse it. If anyone knows what is the 
 exact function that is used to unserialize the session file, please 
 tell.. and it's not the unserialize() function in PHP.
 
 I guess that using a shell PHP script with sessions is not the solution. 
 Is anybody familiar with another way to use sessions??? but not through 
 web, since the script returns sensitive data.
 
 
 -thanks, Eli
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: mediator between PHP and Perl (with sessions)

2005-02-15 Thread Eli
Hi..
Thanks for your help. I searched a bit more, combined with your data, 
tested, and found a solution. :-)

#!/usr/local/bin/php -q
?php
//initialize parameters:
if ($argc2)
   exit(ERROR: session id must be provide as parameter.\n);
$sid=$argv[1];
//initialize session:
ini_set(session.use_cookies,0);  //use no session cookies
session_cache_limiter(null);  //use no session cache limiter
session_id($sid);  //set the session id as got from parameter 1
//read the session variables:
echo $_SESSION[name];
?
-thanks, Eli
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: mediator between PHP and Perl (with sessions)

2005-02-15 Thread Eli
Eli wrote:
Hi..
Thanks for your help. I searched a bit more, combined with your data, 
tested, and found a solution. :-)
Oops.. forgot the most important line..

#!/usr/local/bin/php -q
?php
//initialize parameters:
if ($argc2)
   exit(ERROR: session id must be provide as parameter.\n);
$sid=$argv[1];
//initialize session:
ini_set(session.use_cookies,0);  //use no session cookies
session_cache_limiter(null);  //use no session cache limiter
session_id($sid);  //set the session id as got from parameter 1
session_start();  //start the session
//read the session variables:
echo $_SESSION[name];
?
-thanks, Eli
-thanks, Eli
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php