WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder



Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Simple Cookie example
Categories : PHP, Beginner Guides, Cookies Click here to Update Your Picture
tedd sperling
Date : Mar 03rd 2006
Grade : 2 of 5 (graded 7 times)
Viewed : 42129
File : 4350.zip
Images : No Images for this code example.
Search : More code by tedd sperling
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

The below code is a simple example of Cookies.

Once the cookie is set, you may read the cookie by accessing cookie2.php for up to 24 hours. After that, the cookie will expire.

To see the example at work, please review:

http://www.xn--ovg.com/cookie <-- set cookie
http://www.xn--ovg.com/cookie/getcookie.php <-- read cookie

tedd


--- copy below and save as cookie1.php -----
<?php

    $user
$_POST['user'];
   
$color = $_POST['color'];
   
$self $_SERVER['PHP_SELF'];

    if( (
$user != null ) and ( $color != null ) )
        {
         
setcookie( "firstname", $user , time() + 86400 );        // 24 hours
         
setcookie( "fontcolor", $color, time() + 86400 );
         
header( "Location:cookie2.php" );
          exit();
        }
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
    <title>Stuff by tedd</title>       
</head>

<body>

    <h1>tedd's cookie stuff</h1>

    <hr>

    <form action ="<?php echo( $self ); ?>" method = "post">
   
    Please enter your first name:
    <input type = "text" name = "user"><br><br>
   
    Please choose your favorite font color:<br>
    <input type = "radio" name = "color" value = "Red">Red
    <input type = "radio" name = "color" value = "Green">Green
    <input type = "radio" name = "color" value = "Blue">Blue
    <br><br>
    <input type = "submit" value = "submit">
    </form>

    <br/>
    <hr>   

</body>
</html>
</html>


--- copy below and save as cookie2.php -----
<?php
   
if (isset($_COOKIE['firstname']))
        {
       
$user = $_COOKIE['firstname'];
       
$color= $_COOKIE['fontcolor'];
        }
    else
        {
       
$user $_POST['user'];
       
$color = $_POST['color'];
        }
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
    <title>Stuff by tedd</title>       
</head>

<body>

    <h1>tedd's show cookie stuff</h1>
    <hr>
   
    <h2>Hello: <?php echo( $user ); ?> </h2>
    <h2>Your color: <?php echo( $color ); ?> </h2>
   
    <hr>
   
    <br/>
     <?php
   
// Another way to debug/test is to view all cookies

   
echo ("<br/>");
    echo (
"<pre>");
    echo (
"Cookie info:\n");
   
print_r($_COOKIE);
    echo(
"</pre>");
               
   
?>
    <p>
        <a><input type="button" value="back" onclick="history.go(-1)"></a>
    </p>
   
</body>
</html>



A very simple PHP single password cookie based login without usernames.
Categories : PHP, Cookies, Security, Beginner Guides
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
Store, retrieve and delete cookies using JavaScript.
Categories : Java Script, Cookies, Beginner Guides, Cookies
Simple PHP cookie counter
Categories : PHP, Cookies, Beginner Guides
Validating a URL with preg_match
Categories : PHP, Regexps, Beginner Guides, Data Validation
Simple Session example
Categories : PHP, Beginner Guides, Sessions
a PHP Function to Get only the filename (remove the extension) using regular expressions.
Categories : PHP, Regexps, Beginner Guides
Newbie Notes #9 - Hyperlinking a post
Categories : PHP, Java Script, HTML and PHP, Beginner Guides
Link Submition - Allow your visitors to submit links to the site.
Categories : PHP, Arrays, Filesystem, Beginner Guides
Upload Via FTP - an alternative to move_uploaded_file
Categories : PHP, FTP, Beginner Guides
How to display any array in several rows and columns of a table. Not just in one column or in alternate rows. This example shows a nice color table generated with PHP, but can be used with any array values(e.g. Database)
Categories : Arrays, PHP, Miscellaneous, Beginner Guides, Graphics
Easy alert box pop-up function
Categories : PHP, Java Script, Beginner Guides
Db_lib - practical example usage of database abstraction and form validation.
Categories : PHP, Form Processing, PHP Classes, Data Validation, Beginner Guides
How to update selected fields only
Categories : PHP, Databases, Beginner Guides
Beginners Array Functions
Categories : PHP, Beginner Guides, Arrays