not sure if this is possible,
i have a session variable started with PHP

$_SESSION[username] = $username;

i want to output that session variable into my cgi script...

is that possible?

example...

in my cgi file i have

$PREF{uploaded_files_dir} = '/upload/files';

i want that to be:

$PREF{uploaded_files_dir} = '/upload/files/PHP SESSION USERNAME';

    One way to do this would be to mimick the basic functionality of the PHP session engine. Think about how it works and do the same thing in your CGI script, namely:

    1. Check if a cookie (or a parameter in the query string) shares the same name as your PHP session (default is PHPSESSID however it can be changed in php.ini, .htaccess, inside a PHP script, etc.).

      If such an entity exists, use its value for the session ID. If such an entity can't be found, then you've got a problem.

    2. Use that session ID to locate the session data. Again, this can be modified (drastically) from the default behavior (e.g. via the PHP directives session.save_handler and session.save_path). However, hopefully you'll know how PHP is configured and can discern this on your own.

      If following the default behavior, the save_path will point to the directory where session files are stored on the server. Open the file which shares its name with the session ID determined above (prefixed with "sess_") inside that directory.

    3. Parse the file format that PHP incorporates. Look at a session file to see what this is. Quick example... this:

      $_SESSION['foo'] = 'bar';
      $_SESSION['hello'] = array('world', '!');

      will result in this:

      foo|s:3:"bar";hello|a:2:{i:0;s:5:"world";i:1;s:1:"!";}

      in the corresponding session file.

    EDIT: Another way would be to convert the CGI script to a PHP script so that this whole problem is avoided.

    Yet another solution would be to modify the CGI script so that it can be called/executed on the CLI. That way, you could instead redirect the user to the PHP script itself which would then invoke the CGI script and pass in the necessary bits of session data as arguments on the command line.

      Write a Reply...