Nukemods Forum  
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Online Users: 78
8 members and 70 guests
cus3cttombeatsb, cycwcwlinlt2gti, defkm6ensivpyb3, drasnkeikoo9xwn, lednec4lhm6zwan, minena6oritozm3, ronssypaulsuppo, ttdwncras
Most users ever online was 611, 03-21-2008 at 11:10 PM.
» .::.
tattoo fonts
http://www.checkoutmyink.com/category/tattoo-fonts-tattoo

Go Back   Nukemods Forum > PHP-Nuke 7.x > Nuke 7.x - Modules

Reply
 
LinkBack Thread Tools Display Modes
How to use cookie data in a custom module?
Old
  (#1 (permalink))
Junior Member
 
Status: Offline
Posts: 9
Join Date: Oct 2004
How to use cookie data in a custom module? - 10-17-2004, 07:11 PM

I have a standalone application which uses session_register to handle it's authentication.

This application has previously been "sort of" integrated into 'Nuke - I say sort of because the user table is still seperate.

I would like to have this application integrate more tightly into Nuke.

I want to use Nuke's own user-table [adding around 6 extra fields of data - essentially access levels - to the user table] and I expect that if I am going to do this I will need to use the cookies to hold the "extra" variables that my application makes use of.

I have read a lot of the documentation - and I have tried to read the code - but I am not completely sure how the cookie/ login process works.

Can somebody please tell me how I will get the cookie to store up to 6 extra fields of information about a user - and make that information available to the scripts?

kilt
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#2 (permalink))
Moderator
 
Status: Offline
Posts: 260
Join Date: Oct 2004
10-18-2004, 04:39 AM

You may wish to make a simillar function to the nuke's
Code:
function docookie($setuid, $setusername, $setpass, $setstorynum, $setumode, $setuorder, $setthold, $setnoscore, $setublockon, $settheme, $setcommentmax) {
    $info = base64_encode("$setuid:$setusername:$setpass:$setstorynum:$setumode:$setuorder:$setthold:$setnoscore:$setublockon:$settheme:$setcommentmax");
    setcookie("user","$info",time()+2592000);
}
this is used to set the user_id, username, password, news numbers in home, mode/order/thold/score in news comments, custom user block, theme and comment max.
You may want to make somethine like

Code:
function docookie($var1, $var2, $var3, $var4, $var5, $var6) {
    $info = base64_encode(" $var1:$var2:$var3:$var4:$var5:$var6");
    setcookie("mycookie","$info",time()+2592000);
}
In nuke's code you can get the cookies back with cookiedecode($user); and cookie[0] is user_id, $cookie[1] is the username etc.
so we have
Code:
function cookiedecode($user) {
    global $cookie, $prefix, $db, $user_prefix;
    $user = addslashes($user);
    $user = base64_decode($user);
    $cookie = explode(":", $user);
    $result = $db->sql_query("SELECT user_password FROM ".$user_prefix."_users WHERE username='$cookie[1]'");
    $row = $db->sql_fetchrow($result);
    $pass = $row['user_password'];
    if ($cookie[2] == $pass && $pass != "") {
	return $cookie;
    } else {
	unset($user);
	unset($cookie);
    }
}
u will need to make a simillar function like
Code:
function myfuction($mycookie) {
global $user;
if (is_user($user)) {
$mycookie = base64_decode($mycookie);
$mycookie = explode(":", $mycookie);
return $mycookie;
} else {
unset($mycookie);
}
}
Thats a bit too much don't u think? Theres a more simple way to do with $userinfo, but u asked how to do it with cookies so :P
note: code hasn't been tested, made this while typing this reply.
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#3 (permalink))
Junior Member
 
Status: Offline
Posts: 9
Join Date: Oct 2004
10-18-2004, 08:52 PM

Quote:
Originally Posted by xero51
Thats a bit too much don't u think? Theres a more simple way to do with $userinfo, but u asked how to do it with cookies so :P
note: code hasn't been tested, made this while typing this reply.
Thank you very much for this - I don't mind so much if I don't use the cookie - could you tell me more about the $userinfo?

kilt
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#4 (permalink))
Moderator
 
Status: Offline
Posts: 260
Join Date: Oct 2004
10-19-2004, 05:57 AM

it's very simple, if you make the 6 rows in the (prefix)_users then u can get them by using.
Code:
getusrinfo($user);
$userinfo['myvar1'];
$userinfo['myvar2'];
I preffer this way because is more fast and it doesn't need all those functions to get the cookies etc. Like i did in my project one global getusrinfo($user); so it won't need it all the time and i'm setting the $userinfo array as global.
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#5 (permalink))
Junior Member
 
Status: Offline
Posts: 9
Join Date: Oct 2004
11-05-2004, 06:05 PM

Quote:
Originally Posted by genoxide
I preffer this way because is more fast and it doesn't need all those functions to get the cookies etc. Like i did in my project one global getusrinfo($user); so it won't need it all the time and i'm setting the $userinfo array as global.
After some delay I am working on this again

So I now have another question that I hope someone can help with...

I am now getting this error message:
Code:
Fatal error: Call to undefined function: getusrinfo() in /home/kdp008/public_html/modules/GenAdmin/checklogin.php on line 6
In essence - My app has some processing scripts which do not act within the "nuke" environment. BUT they have need for some of the user variables - so maybe I do need to be do this using the cookie?

I am thinking I would like to add some extra information to the cookie that is used by nuke & then I xan possibly use the "cookiedcode" function almost as a standalone to pull data out of the current cookie...

Even after looking at the code above I am not sure of how to add extra fields to be stored in the cookie - does anybody have some ideas?

kilt
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
cookie lammat Nuke 7.x - General 1 12-01-2004 12:19 PM
Data Base Problem AsE Site design 0 10-29-2004 06:41 AM
Could not insert data into users table SureFire Purged Topics 5 08-03-2003 02:08 AM
Cookie Names....Maybe they are just a little important. Dauthus Open topics 0 05-05-2003 08:49 PM
Right Blocks not giving data... Tylaric Purged Topics 0 11-09-2002 05:26 PM




vBulletin Skin developed by: vBStyles.com


LinkBacks Enabled by vBSEO 3.3.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31