Actual value of a session UID?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skylark2
Forum Commoner
Posts: 32
Joined: Wed Jun 16, 2010 6:00 am

Actual value of a session UID?

Post by skylark2 »

I suspect this must be obvious, but Googling "UID" and "PHP" isn't very easy...

I have a PHP script which calls an executable which needs a whole bunch of values saved from call to call. This would logically be a session, however, it's going to be a major job to extract all the values from the exe to use the session functions in the PHP. So I thought what I'd do is set up a session in the PHP, pass its UID to the executable, and use it as a filename to read and write the (several hundred, maybe more) required values inside the executable. That way, if and when we move to a more modern setup, I can add to the PHP session rather than having to rewrite the entire logic.

So, having called session_start(), is there a variable just sitting somewhere which contains the value of the UID which that session has been allocated? Or did I miss something and it's up to me to compute the UID? I got the impression that it's generated automatically.

Apologies for newbie question if this is obvious.
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

Re: Actual value of a session UID?

Post by Gargoyle »

kurbot
Forum Newbie
Posts: 18
Joined: Tue Jul 20, 2010 2:20 pm

Re: Actual value of a session UID?

Post by kurbot »

Are you looking to return the auto generated session_id that session_start generated?

if so you could call it like so

Code: Select all


session_start();

$sessionIdVar = session_id();
echo $sessionIdVar;

If your looking to be able to recall a SESSION id that may of bee auto generated a while ago, you would need to store these session_ids as they where generated in a Database or a FileDB..

An Example of this would be:

Code: Select all


session_start();

$sessionIdVar = session_id();
echo $sessionIdVar;

// Write the session_id() to a mySQL DB
// Setup a Tabel That looks like

// ID | DateCreated | SessionID 
// And have the Session write to it everytime its created

// You can then recall this later down the road by ID and use the SessionID the database holds to get to your file.
skylark2
Forum Commoner
Posts: 32
Joined: Wed Jun 16, 2010 6:00 am

Re: Actual value of a session UID?

Post by skylark2 »

session_id is exactly what I need. Many thanks guys - I think I was failing to find it because everything else I'd read referred to the ID with a U on the front.

I don't even need to recover old sessions. Just to know what the current one is.

I must say, this is a super-helpful forum.
Post Reply