CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Aug 2017
    Posts
    17

    Question How To Grab Cookie Token From User Hdd ?

    Php Masters!

    Do you mind showing me an example of how to write the code to fetch the persistent cookie token from the user's hdd ? Because, If I do not know how to write code to do the fetching then I won't know what the token is to check against the db. I know how to query the db with php, though.

    While going through many tutorials that keep showing to write the Username & Password on the user's hdd, I grabbed these codes. I do understand what they mean. And no, I won't save the user's password on the cookie.

    Code:
        <?php
        // Setting a cookie
        setcookie("username", "John Carter", time()+30*24*60*60);
        ?>
    Code:
        <?php
        // Verifying whether a cookie is set or not
        if(isset($_COOKIE["username"])){
            echo "Hi " . $_COOKIE["username"];
        } else{
            echo "Welcome Guest!";
        }
        ?>
    Code:
        //Print Cookie on Screen
        <?php 
        print_r($_COOKIE);
        ?>
    Code:
        <?php
        // Deleting a cookie
        setcookie("username", "", time()-3600);
        ?>
    I am thinking of doing it like this ...
    I set the cookie's partial name with my site so it would be easy for the code to search for the cookie in the user's hdd by doing a search on the partial name (my site name). Else, the code won't know what keywords to search for when searching for the cookie in the user's hdd.
    Imagine my site is: mysite.com.
    Now, I can use this to set the cookie:

    Code:
        <?php
        // Setting a cookie
        setcookie("mysite.com", "token-blah-blah-blah", time()+30*24*60*60);
        ?>
    Then, when the user loads login.php or home.php, I can probably use this code to check whether the cookie & it's token exists or not:

    Code:
        <?php
        // Verifying whether a cookie is set or not
        if(isset($_COOKIE["mysite.com"])){
        /*HERE I NEED TO WRITE CODE FOR THE SCRIPT TO GRAB THE TOKEN in order to do 
        a db search for it. How to write that part of the code to grab the token ?
        */
        }
        ?>
    Last edited by coding_student; October 14th, 2017 at 05:59 AM.

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured