Page 1 of 1

Re: Can i retrieve id without using session_id() function?

Posted: Tue Aug 16, 2011 12:32 pm
by phphelpme
I dont understand what you are trying to accomplish here?

To store information in a session that you can use in your application, or specific user information, you do the following:

Code: Select all

session_start();  
$_SESSION['firstname'] = $fname ;  
$_SESSION['lastname'] = $lname ;  
$_SESSION['usercity'] = $city ;  
$_SESSION['address'] = $addr ; 
To retrieve this information on another page, we do the reverse, at the top of the file, like so:

Code: Select all

session_start();  
$fname = $_SESSION['firstname'] ;  
$lname = $_SESSION['lastname'] ;  
$city = $_SESSION['usercity'] ;  
$address = $_SESSION['address'] ; 
This will retrieve the session ID from the cookie on the user's computer, and using that session ID, connect to the $_SESSION array for that particular user.

Best wishes

Re: Can i retrieve id without using session_id() function?

Posted: Tue Aug 16, 2011 1:05 pm
by phphelpme
So you mean you want to use something like setcookie() instead of using session_id() yeah? Forgive me if I dont get you but its been a long day for me... lol :)

Best wishes

Re: Can i retrieve id without using session_id() function?

Posted: Tue Aug 16, 2011 1:37 pm
by phazorRise
if you're tired of using session_id() every time then, for ease ; define it as constant.

Code: Select all

<?php
session_start();
define('PHPSESSID',session_id());
echo PHPSESSID;
?>

Re: Can i retrieve id without using session_id() function?

Posted: Tue Aug 16, 2011 2:02 pm
by phphelpme
Ahh yeah, did not think about that one... lol I agree with you phaserrise but I am still not sure whether its a case of not wanting to use session_id() full stop and replace with something else or as you say just tired of using session_id() so assign a constant.

Best wishes

Re: Can i retrieve id without using session_id() function?

Posted: Tue Aug 16, 2011 2:37 pm
by phazorRise
as far my knowledge, i don't think there's any alternative to get session ids apart from original session_id().
This method is meant to return the id.

Yes, this not alternative method anyhow but if someone want to use session id again n again then making it as constant will be good way.

Re: Can i retrieve id without using session_id() function?

Posted: Tue Aug 16, 2011 2:48 pm
by phphelpme
Yes, it does make it so much easier to work with sessions by making it constant.

Would setcookie() not be an alternate option instead of using session_id() altogether?

That way you assign an id string and save to cookie and recall that string value. Just a thought I had earlier thats all because I am not sure what the objective is yet.

Best wishes

Re: Can i retrieve id without using session_id() function?

Posted: Tue Aug 16, 2011 2:59 pm
by phazorRise
I guess it's not good idea.
Sessions are much safer than cookies as sessions are stored at server. While cookies are stored at client machine and possibly can be edited also.
Someone might steal your cookie and can have access to your site as he just got your session id.

Re: Can i retrieve id without using session_id() function?

Posted: Tue Aug 16, 2011 3:04 pm
by phphelpme
That is so true, again just throwing ideas out there.

If by assigning a constant to a session_id() are you not decreasing the security anyway because you are assigning the session_id() to a variable that can be passed around each page which can been seen through headers anyway?

Again just elaborating on this subject :)

Best wishes

Re: Can i retrieve id without using session_id() function?

Posted: Tue Aug 16, 2011 3:21 pm
by phazorRise
i haven't tried it anyway up till now.
But my quick answer would be, if you see most famous cms or forums out there, they store sensitive details like database host, username, password, database name etc in a file as constants. And there details are also passed on each page.

So i guess it fair enough to make our work much easier with constants.

Re: Can i retrieve id without using session_id() function?

Posted: Tue Aug 16, 2011 3:23 pm
by phphelpme
hahaha, I could not of put it better myself. :)

The rule of thumb is if it is sensitive then use a secure server anyway I guess (HTTPS)

Best wishes

Re: Can i retrieve id without using session_id() function?

Posted: Tue Aug 16, 2011 3:31 pm
by phazorRise
yes, if you're talking one on one with a language you both know only then there are less chances someone else would listen and understand what's going on in between you. :P