» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Online Users: 64
0 members and 64 guests
No Members online
Most users ever online was 611, 03-21-2008 at 10:10 PM.
» .::.
Web Hosting - web hosting, dedicated servers and web design services
Online Degree - search for 1000+ online degrees, online colleges & online universities.
tattoo - we are a group of tattoo enthusiasts
Gexa Energy - your absolute best choice in electric service
Texas electricity - save on electric rates
buy Rimonabant - Help dieters achieve significant weight loss without having to slog in the gym

Register Now! Contact Us

About this Page
This is a discussion on How to use cookie data in a custom module? within the Nuke 7.x - Modules forums, part of the PHP-Nuke 7.x category; I have a standalone application which uses session_register to handle it's authentication. This application has previously been "sort ...



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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-17-2004, 06:11 PM
Junior Member
 
Join Date: Oct 2004
Posts: 9
How to use cookie data in a custom module?
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
  #2 (permalink)  
Old 10-18-2004, 03:39 AM
Moderator
 
Join Date: Oct 2004
Posts: 260
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
  #3 (permalink)  
Old 10-18-2004, 07:52 PM
Junior Member
 
Join Date: Oct 2004
Posts: 9
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
  #4 (permalink)  
Old 10-19-2004, 04:57 AM
Moderator
 
Join Date: Oct 2004
Posts: 260
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.
__________________
read me before posting
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-05-2004, 05:05 PM
Junior Member
 
Join Date: Oct 2004
Posts: 9
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 11:19 AM
Data Base Problem AsE Site design 0 10-29-2004 05:41 AM
Could not insert data into users table SureFire Purged Topics 5 08-03-2003 01:08 AM
Cookie Names....Maybe they are just a little important. Dauthus Open topics 0 05-05-2003 07:49 PM
Right Blocks not giving data... Tylaric Purged Topics 0 11-09-2002 04:26 PM


All times are GMT -5. The time now is 05:58 PM.


Design by Vjacheslav Trushkin, color scheme by ColorizeIt!.

LinkBacks Enabled by vBSEO 3.1.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