Store Front Contact Us Projects Blog PHP Tutorials Community Forums Support Downloads Client Area Homepage Charlie Page - Home to the blog of myself! Dynasty Wizard - Free game dynasties, period. php cms reviews - find the right cms for you. 24 Quotes - Jack Bauer, Tony Almeida - Season 6 Bengals Chatter - The unofficial blog of the Cincinnati Bengals, recaping game by game along with opinion articles and community for Jungle fans to chat away. Political Yard - Talk about politics!
Insane Visions
Insane Visions
Insane Visions - Navigation

Favorites

Get Firefox!

PHP

MySQL

Affiliates

Realm of Gaming
Game Screenie
Video Game Cheats

AllConsoleGamers
TalkPHP
XBOX 360 News
Hilarious Videos
Free Myspace Stuff

[ Apply for Affiliation ]



Scripts.com

MaxTutorial.com - Best photoshop, flash and php tutorials


Your Link Here
Your Link Here
Your Link Here

Acceptance Mark
Insane Visions - Top Navigation


Insane Visions - Welcome to Cookies Tutorial :: Premium PHP Scripts - AdaptCMS, AdaptBB, OneCMS Welcome to Cookies at Oct 05, 07 - 9:21 pm
News Div
Post to Digg Post to Facebook Post to Furl Post to Netscape Post to Newsvine Post to Reddit Post to Simpy Post to Spurl Post to StumbleUpon

Views: 2,595
Type: PHP
Experience Level: Beginner

Welcome to the first tutorial here at Insane Visions. I'm going to kick it off with a tutorial on cookies, PHP cookies.

Cookies are just a basic aspect of PHP, but can be used in so many things. From logging in and out a user on your website to keeping the name of the skin they use on your website. Below I will explain how to set (add) a cookie, delete one and then display/check one. I will first show the PHP code and then explain it.

Add a Cookie

<?php
setcookie
("username"$_POST[textfieldname],
time()+3600*60*24*14);
?>

Firstly the "username" part is the name of the cookie you want it to have. Next up is simply the data you want that cookie set to, I have a POST so if you login you would use a POST variable to get the data the user put in as the username.

Delete a Cookie

<?php
setcookie
("username"""time()-3600*60*24*14);
?>

Yep the same PHP function. "username" as the name of the cookie, make sure it is the same name as when it was first set. We set the next value blank because we want to basically empty the cookie and then set the time minus all that time we originally set it to, deleting the cookie.

Displaying/Checking a Cookie

<?php
echo "Hello, welcome back ".$_COOKIE[username]."!";
?>

Pretty simple here, the COOKIE variable with the name of the cookie inside the brackets will display the data from that cookie.


<?php
if ($_COOKIE[username]) {
echo 
"Yes, I am logged in!";
} else {
echo 
"Nope, login please";

?>

As long as you understand if statements, then this is real simple. The code above means if the COOKIE named "username" has value, then it will say the "Yes, I am logged in!".

Conclusion

That about wraps it up. Above you can see how to add a cookie, delete a cookie and then print/check a cookie. Logging in and other things to expand moreso.

Download:

Rating:

Vote for Article:



Guest, May 08, 08 - 4:21 am
is great for novice class, thx


 email

 website







Username:
Password:
Insane Visions - Login Register

AdaptCMS

AdaptBB

OneCMS

Latest Tutorials

- Basic PHP Security
- Bot Detection with PHP
- PHP and Forms


Latest Blogs

- Starting on AdaptBB
- AdaptCMS 1.3 - June 13th
- AdaptCMS - v1.3 Features


Poll of the Month

Which forum software do you use?

SMF
InvisionPowerBoard
phpBB
Vbulletin
AdaptBB
Other
Results



Latest Posts

- Re: OneCMS v2.6 -
Ideas
- Re: Category
Templates?
- Re: Displaying Content
After Xth Number


Testimonials

I have dealt with many CMSes before. I have had my fair share of disappointments. At first, I had a rough time with OneCMS. Thanks to the awesome support with OneCMS, I am now gliding along easily. Even making modifications! I have never dealt with this level of support, especially on a free program, before. I think that Chuck shows great devotion, and props on the CMS.

- Scott Berlin, Founder/Webmaster, Wired-Gamers.com


Powered by AdaptCMS Pro
Insane Visions - Footer
Personal Loan - Loans - Homeowner Loans - Bad Credit Loans