Professional Web Applications Themes

PHP & Cookies order form - PHP Development

Hi chaps, I'm relatively new to the language, but I want to create a simple order form using PHP and cookies. Please let me know if there's a better way in this situation, database isn't availible. What I'm trying to get is this: 1) Variable(A) passed from HTML page to script. 2) Script checks for cookie. 3) If no cookie, script creates one, Variable(A) the value. 4) If cookie, script adds Variable(A) value. Then the script should produce an "order form" type page, listing the variables within the cookie. I'm new to PHP and I have no experience of cookies. ...

  1. #1

    Default PHP & Cookies order form

    Hi chaps,

    I'm relatively new to the language, but I want to create a simple order
    form using PHP and cookies. Please let me know if there's a better way
    in this situation, database isn't availible.

    What I'm trying to get is this:

    1) Variable(A) passed from HTML page to script.
    2) Script checks for cookie.
    3) If no cookie, script creates one, Variable(A) the value.
    4) If cookie, script adds Variable(A) value.

    Then the script should produce an "order form" type page, listing the
    variables within the cookie.

    I'm new to PHP and I have no experience of cookies. I may be going about
    this the wrong way, so please let me know!

    Many thanks for any help,

    - Daniel
    Daniel Ruscoe Guest

  2. #2

    Default Re: PHP & Cookies order form

    Tinkering with browser cookies directly is so...passe. Use PHP sessions
    instead:

    <?php

    session_start();

    if(is_array($_SESSION['orders'])) {
    $_SESSION['orders'] = array();
    }
    array_push($_SESSION['orders'], $a); // from your form

    ?>

    Uzytkownik "Daniel Ruscoe" <contactwebsite.plz> napisal w wiadomosci
    news:MPG.1a3c63123a95292b989767news.btopenworld.c om...
    > Hi chaps,
    >
    > I'm relatively new to the language, but I want to create a simple order
    > form using PHP and cookies. Please let me know if there's a better way
    > in this situation, database isn't availible.
    >
    > What I'm trying to get is this:
    >
    > 1) Variable(A) passed from HTML page to script.
    > 2) Script checks for cookie.
    > 3) If no cookie, script creates one, Variable(A) the value.
    > 4) If cookie, script adds Variable(A) value.
    >
    > Then the script should produce an "order form" type page, listing the
    > variables within the cookie.
    >
    > I'm new to PHP and I have no experience of cookies. I may be going about
    > this the wrong way, so please let me know!
    >
    > Many thanks for any help,
    >
    > - Daniel

    Chung Leong Guest

  3. #3

    Default Re: PHP & Cookies order form

    Daniel Ruscoe wrote:
    > Hi chaps,
    >
    > I'm relatively new to the language, but I want to create a simple order
    > form using PHP and cookies. Please let me know if there's a better way
    > in this situation, database isn't availible.
    >
    > What I'm trying to get is this:
    >
    > 1) Variable(A) passed from HTML page to script.
    > 2) Script checks for cookie.
    > 3) If no cookie, script creates one, Variable(A) the value.
    > 4) If cookie, script adds Variable(A) value.
    >
    > Then the script should produce an "order form" type page, listing the
    > variables within the cookie.
    Do you need a cookie? Do you need to know the value of the data beyond
    the order form page? Could you send data straight to the order form page
    using forms, and perhaps hidden form fields?

    If you do need to keep the data for several pages, then using PHP
    sessions may be useful. Sessions use a cookie to store a session key
    that points to a set of session data on the PHP server (though make sure
    to think about security of session variables and whether there's a risk
    of the session keys being intercepted over open connections). See the
    Session handling functions (chapter XCV) in the PHP user manual.

    If you need to store the data on the user's machine for more than
    several pages, e.g. for several hours, days, months, or years, then
    cookies are the way. Again, make sure to think about security of data
    being stored on the remote machine, and about transmitting the data over
    open (non-encrypted) connections.
    --
    Bob
    London, UK
    echo Mail fefsensmrrjyaheeoceoq\! | tr "jefroq\!" "obe.uk"
    Robert Downes Guest

  4. #4

    Default Re: PHP & Cookies order form

    In article <lbydnQGIEJY2bk6iRVn-gwcomcast.com>, Chung Leong says...
    > Tinkering with browser cookies directly is so...passe. Use PHP sessions
    > instead:
    >
    > <?php
    >
    > session_start();
    >
    > if(is_array($_SESSION['orders'])) {
    > $_SESSION['orders'] = array();
    > }
    > array_push($_SESSION['orders'], $a); // from your form
    >
    > ?>
    Thanks for that, I'm beginning to get the basics now. I've looked up
    sessions and I see how they work. Looks like the perfect solution.

    I'm stuck trying to figure out how I would add multiple items to a
    session.

    Say I want a form on one page, when the submit button is clicked 4
    variables are sent to a PHP script to be added to a session.

    Then I'd need that script to list them in an order form style:

    Title Title Title Title
    Variable1(A) Variable1(B) Variable1(C) Variable1(D)

    With the ability to add more sets of variables afterwards to give:

    Title Title Title Title
    Variable1(A) Variable1(B) Variable1(C) Variable1(D)
    Variable2(A) Variable2(B) Variable2(C) Variable2(D)

    Can anybody point a beginner in the way of some code?

    Thank you.

    - Dan
    Daniel Ruscoe Guest

Similar Threads

  1. Replies: 1
    Last Post: July 27th, 04:25 PM
  2. Set Tab order in PDF form
    By zulbat@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 0
    Last Post: May 27th, 01:28 AM
  3. Sessions, Cookies, DB, Form posts or all 4
    By Laphan in forum ASP Database
    Replies: 1
    Last Post: March 6th, 10:13 PM
  4. PHP order form
    By webmagic69 in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: February 15th, 05:08 AM
  5. Tab Order on a Form
    By Maggic in forum Microsoft Access
    Replies: 2
    Last Post: July 21st, 09:17 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139