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 Adapt Software Political Yard - Talk about politics!
Insane Visions
Insane Visions
Insane Visions - Navigation

Favorites

Get Firefox!

PHP

MySQL

Affiliates

Software Reviews

ApocalypticTomorrow

Tutorials Garden
AllConsoleGamers
TalkPHP
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 - 10: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: 4,950
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 - 5: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

- AdaptBB 1.0 - Backend Revealed
- AdaptCMS 1.4 - September 17th
- AdaptBB - 1.0 Features


Poll of the Month

What is your budget for a CMS?

$100+
$25-$50
$10-$25
$50-$100
Free Only
Results



Latest Posts

- AdaptCMS Lite 1.5 Beta Released
- AdaptBB 1.0 Beta - Released
- AdaptCMS Lite v1.1 - Released


Testimonials

I use OneCMS as the backend of my site, VisionPS3.com. Why? Because OneCMS is the best content management system that I have ever used, it is also very easy, extremely customizable, and has a very small learning curve. In addition, it comes backed by one of the most knowledgeable programmers that I know, which is Chuck, the creator of OneCMS. He never hesitated to get hands-on with the small amounts of problems I ran into, as he knows the CMS like the back of his hand. A big thanks goes out to the creator of OneCMS for creating, managing, and helping with the greatest CMS on the web!

|||||4 - Jesse Wingert, Founder/Owner, VisionPS3.com


Powered by AdaptCMS Pro
Insane Visions - Footer

Page processed in 0.103 seconds.