How To Grab Cookie Token From User Hdd ?

sunny_pro

New member
Joined
Jun 18, 2017
Messages
86
Points
0
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 ?
    */
    }
    ?>
 
Older threads
Latest threads
Recommended threads
Replies
1
Views
2,052
Replies
53
Views
46,834
Replies
12
Views
6,511

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top