|
-
Oct 10th, 2002, 09:59 AM
#1
Thread Starter
Frenzied Member
Reading a cookie (Need to brush up this one :D)
Hey ya,
I'm writing a (simplish) php / MySQL pop up exchange to use on my site.
I want the user to be able to store their username and password in a cookie, And so, IF they provide the correct details,
The cookie gets set like so:
PHP Code:
// User ID - Username - Password (MD5)
$userinfo = base64_encode("$user_id:$username:$password");
setcookie("usercookie","$userinfo",time()+2592000);
Any how, so far, i have got by just editing my php nuke site, to include the login, password ETC thats needed (Genious huh)
Well any how, I want this site to be totally indipendant from my nuke site, (For the main reason, it dont go anything with my nuke site).
Any how,
How do i get the cookie READ into the php script?
Like make it into a variable called "$userinfo" When they call my index.php / login.php / member.php?
From php nuke (lol) I have been able to find out how i READ it into the user id / username / password
WHEN i have it as a variable ($userinfo):
PHP Code:
$user = base64_decode($userinfo);
$cookie = explode(":", $user);
$user_id = $cookie[0];
$username = $cookie[1];
$md5_password = $cookie[2];
// Login stuff goes here IF the cookie is correct,
// Else
// setcookie("usercookie");
this is basically a MUST have thing for my "Exchange" as i really doubt users wanna have to login every page etc.
Ne one help plz?
TNX
-
Oct 10th, 2002, 10:04 AM
#2
Thread Starter
Frenzied Member
OH ALSO:
How do i set a cookie for 24 hours?
I want the usercookie to be for a month +,
But i want to (soon - like before i release my "Exchange Program") make the referals "Cookie Based" cuz people who sign up "Downlines" are given 0.5 credits for every referal's Credit earned, etc..
And if some1 gave the person a first sight, they should get "Referal Dibs" for 24 hrs (be fair etc )
-
Oct 11th, 2002, 06:41 AM
#3
New Member
For read cookie:
setcookie("x","1");
At any page now $x==1 - read as much, as you need
For 24 hour:
setcookie("usercookie","$userinfo",time()+86400);
86400 - sec. in 1day
If no time-
setcookie("usercookie","$userinfo");
cookie will work until you don't close your browser.
Sincerely,
Sergey Booyny
AlarIT programmer
http://www.AlarIT.com
-
Oct 11th, 2002, 02:58 PM
#4
Stuck in the 80s
Originally posted by serg4444
For read cookie:
setcookie("x","1");
At any page now $x==1 - read as much, as you need
As of PHP 4.2, register_globals is off by default.
It is now the standard to access cookies as: $_COOKIE['x'] rather than the assumed global of $x.
-
Oct 11th, 2002, 02:58 PM
#5
Stuck in the 80s
$_COOKIE variables are also superglobals, meaning they don't have to be setup using the global keyword for use in functions.
-
Oct 12th, 2002, 03:56 PM
#6
Thread Starter
Frenzied Member
-
Oct 12th, 2002, 04:13 PM
#7
Thread Starter
Frenzied Member
Is there any problems which could be caused with this php?
(I tried
PHP Code:
// Cookie of the referer's username is "$_COOKIE['referer']"
// Referer's username which is called by : &ref=*ReferersUserName*
// $refer: Used later when the person signs up to the "Service".
if(!isset($_COOKIE['referer'])
{
if($ref !=""){
setcookie("referer",$ref,time()+3600);
$refer=$ref;
}
} else {
$refer=$_COOKIE['referer'];
}
But it wouldn't for the hell of god knows wot,
Set the cookie with this:
So i tried:
PHP Code:
if ($_COOKIE['referer']==""){
if($ref !=""){
setcookie("referer",$ref,time()+3600);
$refer=$ref;
}
} else {
$refer=$_COOKIE['referer'];
}
And this will work.
So before i even :think: of releasing my "site", i jst wanna make sure this wont cause problems?
Tnx
-
Oct 12th, 2002, 09:27 PM
#8
Thread Starter
Frenzied Member
Another Quick Question,,,
I dont want someone (dunno if ppl do this) Sitting @ their site, refreshing their page, for ages, showing their pop up window, And getting credits for it,
BUT i want them to get like 1 credit for every visitor page view (which im guessing is about 30 seconds, at leaste?)
What you you guys say the average visitors stay on a single page is?
Cuz im thinking, i set a cookie when they view a pop up,
setcookie("lastad","Active:".$uid,time()+30);
and if i get "$_COOKIE['lastad']" and it is "Active:$uid" i simply dont give em credit for the ad view,
So, i wanna know the "Average" page view time you guys guess is "Going on" for a "average joe's" site?
THANKS
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|