Cookies and PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James

    Cookies and PHP

    I am looking to store a cookie on a client (machine) and then when the
    client revisits, to populate part of the form with data held on my
    server (ok this is for a my course).

    A I will need to get the initial data from the client.
    B Store it on my server with an account number.
    C Create a copy on the host or alternatively an account number.
    D When the user logs back on I will need to populate the form with
    the data they already entered.

    Any pointers or help appreciated.

    J
  • Erwin Moller

    #2
    Re: Cookies and PHP

    James wrote:
    [color=blue]
    > I am looking to store a cookie on a client (machine) and then when the
    > client revisits, to populate part of the form with data held on my
    > server (ok this is for a my course).
    >
    > A I will need to get the initial data from the client.
    > B Store it on my server with an account number.
    > C Create a copy on the host or alternatively an account number.
    > D When the user logs back on I will need to populate the form with
    > the data they already entered.
    >
    > Any pointers or help appreciated.
    >
    > J[/color]

    Hi James,

    That is a real nice client/server assigment. :-)
    For details go to www.php.net

    Some pointers:

    Okay, so start by making a HTML page that contains a form.
    Let's say it contains two variables: name and age.
    (send.html)
    Make the action of the form some PHP-script on your server.
    (store.php)

    Code store.php so that it receives the form-data. Have a look at the
    $_POST["varnameher e"] or $_GET["varnameher e"]
    Use them to get the values your send.html sended.

    Now:
    1) store that received name and age on the server.
    You can do this by file or database. Be sure you 'invent' some unique number
    or something as filename or unique key.

    2) Put that unique number in a coockie you send back to the clientmachine.
    Have a look at www.php.net and study the cookie-functions for details.

    Now create one more PHP-script (can also be the same one you just coded, but
    that is confusing I guess in this stage)
    This script reads the coockie that the clientmachine sends (check again the
    cookie-routine on www.php.net) and uses the unique number to read the file
    with that name or queries the database based on that number.
    Output the result.

    Good luck.
    Erwin Moller

    Comment

    Working...