NOTE: this tutorial will either work in IE, and not FireFox, or in FireFox and not IE. When I get spare time, I will try and fix this, where it'll work in IE and FF! However, until then, remember that this is not cross-browser. Gah.. I hate IE......This tutorial was created by Klark Kent, aka pr0nslave of
http://TheCodingZone.com |
Redistribute only if you've left all content in, and have not edited or added to it. |
------------------------------------------------------------------------------------------------------
First off, a user ID is the number someone was at registration. For example, say Robert registered, then Kenny and finally Tom. Robert's user ID would be 1, Kenny's would be 2 and Tom's would be 3. Why are some IDs "skipped"? Well, they're not -- it just looks that way because an admin has chosen to delete a member.
For example, say Kenny was being mean -- and Robert (member #1, thus, administrator) decided to delete him -- it would leave only users #1 and #3 left, because #2 had been deleted.
Anyhow, enough with that! Let's get to the code.
First, the user ID is stored in a cookie (to my knowledge). Four+ cookies are set by each board, that are named *boardname*session_id, *boardname*member_id, *boardname*pass_hash, and *boardname*forum_read
Here are their values:
*boardname*session_id is the session ID
*boardname*member_id is the member ID
*boardname*pass_hash is the password hash
*boardname*forum_read tells something about if you've read each post in a forum
This is where *boardname* denotes the name the board was registered under, ie.: not the title -- but hxxp://zX.invisionfree/*BOARDNAME*
Now, the only cookie we need is *boardname*member_id
This cookie holds the user ID of the person currently logged in (ie.: if TCZ was an IF board, my *boardname*member_id value would be 1393, because that's my member ID).
Off to fetch it via JS!
First of all, you should know
document.cookie will display all cookies set by that domain, for example, on my test board, putting
<script>
document.write(document.cookie);
</script
in footers would yield...
pr0ntestsession_id=189f...2a0319f; pr0ntestmember_id=1; pr0ntestpass_hash=d4bc6f5...ddf05c3; pr0ntestforum_read=a%3A1%3...1717%3B%7D
(note the '...' is for security reasons, as I don't want my password hash or session ID to be cracked [hash] or hijacked [session])
Now, let's split this up to get the cookie we want...
var cookiez=document.cookie.split('; ');
Which makes the variable
cookiez an array, that holds:
cookiez[0] = *boardname*session_id=*session id*
cookiez[1] = *boardname*member_id=*member id*
cookiez[2] = *boardname*pass_hash=*password hash*
cookiez[3] = *boardname*forum_read=*forum read info*
Since we want the value only, and the value of *boardname*member_id only, let's split cookiez[1] up.
var tehchef=cookiez[1].split('=');
Which makes
tehchef an array, that holds:
tehchef[0] = *boardname*member_id
tehchef[1] = *boardname*member_id's value
So, the user ID is now stored in
tehchef[1]Full code:
<script>
var cookiez=document.cookie.split('; ');
var tehchef=cookiez[1].split('=');
var userid=tehchef[1];
alert(userid);
</script>
Hope I helped, and note that there are other ways of doing this, but imo, this is the simplest way that teaches the most (you could have learned about split, arrays, etc. while reading this, lol)