/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Sessions… how do UIDs work?

Hey All,
I’m thinking of using sessions with php. In all the tutorials, I’ve been told this:

1) Start the session, so that you can create a UID.
2) Use the session.
3) Close the session (or the user navigates away).

Nowhere can I find any info on creating UIDs or how they work!

Can anyone give me an explanation of how to use UIDs for sessions, or refer me to a tutorial that will explain it?

Thanks a bunch,
StPretz

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@mUKMay 16.2008 — <?php

//start session

session_start();

// session ID

$x=session_id();

echo $x;

$login="mUK";

$_SESSION['USER_AUTH'] = True;

$_
SESSION['USER_LOGIN'] = $login;

//destroy session

session_destroy();

?>
Copy linkTweet thisAlerts:
@auxoneMay 17.2008 — This is a really awesome tutorial on managing users with sessions, but it requires mySQL. http://www.sitepoint.com/article/users-php-sessions-mysql

A more simplified version of the other guys post (which should work):

[code=php]session_start(); // required on every page you use $_SESSION

// $_SESSION is just an associative array that is loaded on session_start();

$_SESSION[uid] = 'BobtheUser'; // we can set it
$username = $_SESSION[uid]; // or get it, if it was set before (even on another page).

unset($_SESSION[uid]); // this unsets (deletes)

// after an unset isset($_SESSION[uid]) would be false[/code]


You won't be able to access anything from $_SESSION until you call session_start(). Even if you just had a page to log the users out, the PHP would look like:

[code=php]
session_start();
unset($_SESSION['uid']); // sometimes i put single quotes. preference.
unset($_SESSION['pwd']);[/code]


BTW, uid can be username or whatever you want.
Copy linkTweet thisAlerts:
@saintpretz59authorMay 18.2008 — Thanks for everything so far. So, are there any pre-defined members of the $_SESSION array? Or could I, if I wanted, user a variable $_SESSION['theKrazayCoolUserIDizzle'] if I wanted to?

I think that simple answer may clear up my confusion. Thanks.
Copy linkTweet thisAlerts:
@mUKMay 18.2008 — you can use whatever you want
Copy linkTweet thisAlerts:
@saintpretz59authorMay 18.2008 — Okay, thanks. I read that sitepoint tutorial, which help a lot. I now understand (I think!) that the functionality of SESSIONS doesn't come from the values in the $_SESSION array. Rather, it comes from cookies (or other sources), ALLOWING the $_SESSION array to be correctly populated. At first, I thought that I needed to do a bunch of work to ensure that the PHP server would use sessions correctly. Silly me!

Thanks for helping me through this little adventure!

Regards,

SaintPretz
×

Success!

Help @saintpretz59 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...