G
G
greengarlic2011-11-28 18:19:14
PHP
greengarlic, 2011-11-28 18:19:14

PHP console application with session mechanism or how to identify a user?

It may seem like an idiotic idea, but somehow it needs to be done.
Let me explain the point. There is some kind of console application and there are a lot of services in it. The user calls services and they quietly perform something there. Then the user says "generate reports", they are created and we forget about this user. There may be many users.
How can I come up with a mechanism for sessions but without cookies, and I would very much like without passing a user some ID (read as sessions without cookies)
Thanks for any perverse way :3

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evengard, 2011-11-28
@greengarlic

I came up with only four ways:
1. Do not exit the program with each command. Micro interpreter.
2. Try to pull out the username and host of the computer for which the user works, from which environmental variables thread
3. Try to write the thread itself into environmental variables (instead of cookies) - delete it as soon as the session is over
4. Criat the / tmp file instead of cookies, respectively. At the end of the session, respectively delete

V
Vitaly Peretyatko, 2011-11-28
@viperet

session_id($_SERVER['USER']);
session_start();
and then we use the session as usual,
the main thing is to store the session in the database or so that all users have write access to the folder for the session files (unsafe)

G
greengarlic, 2011-11-28
@greengarlic

Thanks everyone!
I settled on 1 method that Evengard
suggested, it turned out something like this: So far, the pitfalls are only in the inconvenience of entering. And so nothing in general. Maybe I'm missing something that's not obvious, it would be nice to know.
<?php
$fp = fopen("php://stdin", "r");
$in = '';
$core = Core::getInstance();
while($in != "exit") {
echo "php> ";
$in=trim(fgets($fp));
$str = explode(' ', $in);
$_SERVER['argv'] = array();
foreach ($str as $s) {
$_SERVER['argv'][] = trim($s);
}
echo "\n";
$_SERVER['argc'] = count( $_SERVER['argv']);
$core->run();
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question