Results 1 to 10 of 24

Thread: Day 10 - Let's Eat Cookie - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2005
    Posts
    46,704

    Default

    http://php.flashwebhost.com/mini/cookie.php

    Code:
    <?php
    if (isset($_COOKIE['Yoga_name'])) {
    echo $_COOKIE['Yoga_name'] . ', Welcome to Free Online Yoga Videos';
    exit;
    }
    
    if (isset($_POST['Yoga_name']) && strlen($_POST['Yoga_name']) > 3) {
    setcookie('Yoga_name',$_POST['Yoga_name'], time() + 7200);
    echo 'Cookie Set. Close the browser. Revisit this page, I will remember your name';
    } else {
     echo '
            What is your name ?
            <form method="post" action="">
            <input type="text" name="Yoga_name">
            <button type="submit" name="submit">Enter Web Site</button>
            </form>
        ';
    }

  2. #2
    Join Date
    Oct 2003
    Location
    Kochi, Kerala, India
    Posts
    21,389

    Default

    Can somebody explain this portion of the script ?

    Code:
    setcookie('phpExpertName', $_POST['phpExpertName'], time()+3600);
    Why phpExpertName and $_POST['phpExpertName'] mentioned together ?

  3. #3
    Join Date
    Oct 2003
    Location
    Kochi, Kerala, India
    Posts
    21,389

    Default

    I do understand that it is the syntax of cookie. Hope I am right.

    http://php.flashwebhost.com/vineesh/...set_cookie.php

    PHP Code:
    <?
    if(isset($_COOKIE['userName'])) {
    echo '<h2 style="color:red">Hi ' . $_COOKIE[userName] . '!, welcome back.</h2>';
    exit;
    }


    if(isset($_POST['userName']) && strlen($_POST['userName']) > 3) {
    setcookie('userName', $_POST['userName'], time() + 3600);
    echo '<h3 style="color:red">You may close the browser and re-login, I will remember your Name. </h3>';
    } else {

    echo '
    <html>
    <body style="background-color:#D9D9D9">
    <form method="POST" action="">
    <input type="text" name="userName">
    <button type="submit">Click here</button>

    </body>
    </html>

    ';
    }

  4. #4
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by vineesh View Post
    Can somebody explain this portion of the script ?

    Code:
    setcookie('phpExpertName', $_POST['phpExpertName'], time()+3600);
    Why phpExpertName and $_POST['phpExpertName'] mentioned together ?
    That is how cookie is set. First phpExpertName is name of the cookie. $_POST['phpExpertName'] is the data PHP get when user submit HTML form page using POST method.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  5. #5
    Join Date
    Jan 2008
    Location
    india,kerala-god's own country
    Posts
    14,007

    Default

    DAY 10 PHP PROGRAMMING

    http://php.flashwebhost.com/ramesh/day-10/cookie_2.php

    PHP Code:
    <?php
    if(isset($_COOKIE['userName'])) {
    echo 
    '<h2 style="color:blue">Hi ' $_COOKIE[userName] . '!, welcome back.</h2>';
    exit;
    }


    if(isset(
    $_POST['userName']) && strlen($_POST['userName']) > 3) {
    setcookie('userName'$_POST['userName'], time() + 3600);
    echo 
    '<h3 style="color:green">You may close the browser and re-login, I will remember your Name. </h3>';
    } else {

    echo 
    '
    <html>
    <body style="background-color:#000">
    <form method="POST" action="">
    <input type="text" name="userName">
    <button type="submit">Click here</button>

    </body>
    </html>

    '
    ;
    }

  6. #6
    Join Date
    Jan 2008
    Location
    india,kerala-god's own country
    Posts
    14,007

    Default

    Can we start php using '<?' only instead of '<?php'.

    I had seen this post in which the code working and executing successfully.

  7. #7
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 10 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/day_10_ex_1.php

    PHP Code:

    <?php
    if (isset($_COOKIE['clientName'])) {
    echo 
    'Hello ' $_COOKIE['clientName'] . ' Welcome to Our WebSite';exit;
    }
    if (isset(
    $_POST['clientName']) && strlen($_POST['clientName']) > ){
    setcookie('clientName'$_POST['clientName'], time()+3600);
    echo 
    ' Cookie Set. Close the browser. Revisit this page, I will remember your name';
    } else {
    echo
    '
    What is Your Name?
    <form method="POST" action=""><input type="text" name="clientName"><button type="submit" name="whatever">Enter</button></form>
    '
    ;
    }

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •