#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1

    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.

    PHP Code:
        <?php
        
    // Setting a cookie
        
    setcookie("username""John Carter"time()+30*24*60*60);
        
    ?>
    PHP Code:
        <?php
        
    // Verifying whether a cookie is set or not
        
    if(isset($_COOKIE["username"])){
            echo 
    "Hi " $_COOKIE["username"];
        } else{
            echo 
    "Welcome Guest!";
        }
        
    ?>
    PHP Code:
        //Print Cookie on Screen
        <?php 
        print_r
    ($_COOKIE);
        
    ?>
    PHP 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:

    PHP 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:

    PHP 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 UniqueIdeaMan; October 14th, 2017 at 06:59 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,350
    Rep Power
    630
    Search engines are your friend.

    https://www.tutorialrepublic.com/php...hp-cookies.php

    Comments on this post

    • UniqueIdeaMan agrees
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,814
    Rep Power
    4536
    You're not interacting with a user's hard drive with a server side scripting language.

    Go back to the books and learn how HTTP requests function and how PHP exposes cookies from those requests. The above link looks good.

    Comments on this post

    • UniqueIdeaMan agrees
    -- Cigars, whiskey and wild, wild women. --
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1
    Originally Posted by Sepodati
    You're not interacting with a user's hard drive with a server side scripting language.

    Go back to the books and learn how HTTP requests function and how PHP exposes cookies from those requests. The above link looks good.
    I've given gw1500se a rep for that link before I even checked it out. Gonna check it out now.
    I also gave you a REP because you did not criticize or swear in your reply, like you usually do. Keep up your manners like this and you'll get more REPS. Lol!

    As for learning about http. You're welcome to provide a recommended link.
    Take care!
    Last edited by UniqueIdeaMan; October 14th, 2017 at 07:39 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1
    gw1500se & Sedopati,

    https://www.tutorialrepublic.com/php...hp-cookies.php
    Ooops! Seems like I already checked-out that link tice before on other days. Infact, I opened a thread today about 8hrs ago mentioning the code from it:
    How To Grab Cookie Token From User Hdd ?
    Last edited by UniqueIdeaMan; October 17th, 2017 at 05:06 PM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,350
    Rep Power
    630
    Think about security. Is it reasonable to expect to be able to retrieve data directly from a client's HDD from a server or any remote computer? Take Sepodati's advice. It does no good to ask questions here if you do not understand the basics.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,112
    Rep Power
    4103
    Originally Posted by UniqueIdeaMan
    As for learning about http. You're welcome to provide a recommended link.
    Overview of HTTP
    HTTP Cookies

    You don't search for cookies, the browser determines what cookies you're allowed to read and sends them as part of the request. PHP makes these cookies available to you via the $_COOKIE array. There's no need to try and name your cookies in some way that lets you identify which are yours. Name them something that relates to the data being stored.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1
    Thanks for the links Kicken!
    Noted them.
  16. #9
  17. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,814
    Rep Power
    4536
    "Noted them" means you'll ****ing copy and paste whatever you find there. I the in the **** just so it's clear what I think of you.
    -- Cigars, whiskey and wild, wild women. --
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    318
    Rep Power
    1
    Originally Posted by gw1500se
    Think about security. Is it reasonable to expect to be able to retrieve data directly from a client's HDD from a server or any remote computer? Take Sepodati's advice. It does no good to ask questions here if you do not understand the basics.
    Yeah, I know! I'm not stupid like Sedopati thinks I am. I mean, let's face it, if I was stupid I would not know he thinks I am one. And, I'm wise enough to realize that, you don't think I'm stupid. You just think I either did not give thought to the issue properly or I did not use my common sense.

    I know it is not directly possible to grab any files from a client's hdd or everyone would be nicking data off of from everybody.
    But, I thought there is one exception and that is cookies. After-all, the cookie sits on the client's hdd somewhere even if it is inside MS OS system files, Or, in some files inside the browser's system files.
    The browser does reside in the client's hdd somewhere, and again, even if it is inside the MS OS system files somewhere as MS OS system files do reside physically in the client's hdd somewhere.
    Physically, everything (OS, Browser, etc.) are all housed in the client's hdd. Not in thin-air.
    And yes yes, before anyone starts any lecture, I know the OS or the browser by law and by internet security issue do not give the server any access to the client's hdd except to grab the cookie from whatever location they are housed at. Be it at one of the browser's files or OS's system files.

    Take care and thanks for being coniderate enough to write that post when you thought you might aswell show me some sense when you thought I was groping in the dark!
    Last edited by UniqueIdeaMan; October 14th, 2017 at 09:21 PM.
  20. #11
  21. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,814
    Rep Power
    4536
    Originally Posted by UniqueIdeaMan
    do not give the server any access to the client's hdd except to grab the cookie from whatever location they are housed at. Be it at one of the browser's files or OS's system files.
    No. Just, no... Stop pretending like you know what's going on when you obviously don't. If you had any understanding of how http works, you'd never write that.
    -- Cigars, whiskey and wild, wild women. --

IMN logo majestic logo threadwatch logo seochat tools logo