Professional Web Applications Themes

GET form method and accessing its value into a cookie - PHP Development

Hi I have a page which generates 'edit' links (used to edit user details). The code snippet on the 'list_user.php' page is; --- $print_rows .="<trclass=\"stdtablecells\">\n". "<td>{$details['name']}</td>\n". "<td>{$details['mail']}</td>\n". "<td>{$details['quota']}</td>\n". "<td><a href=\"edit_user.php?user={$user_list[$i]['uid'][0]}\">edit</a></td> \n". "</tr>\n"; --- The line in question really is this one; <a href=\"edit_user.php?user={$user_list[$i]['uid'][0]}\">edit</a></td> \n". As you can see this creates a link to the 'edit_user.php' page with a GET parameter generated by a php array. The 'edit_user.php' page contains this script (before any headers are generated) which is designed to put the GET value into a cookie; --- if (! isset($_COOKIE['yhgfluseruid'])) { $useruid=$_REQUEST['user']; setcookie('yhgfluseruid',$useruid); } ...

  1. #1

    Default GET form method and accessing its value into a cookie

    Hi

    I have a page which generates 'edit' links (used to edit user details). The
    code snippet on the 'list_user.php' page is;

    ---
    $print_rows .="<trclass=\"stdtablecells\">\n".
    "<td>{$details['name']}</td>\n".
    "<td>{$details['mail']}</td>\n".
    "<td>{$details['quota']}</td>\n".
    "<td><a
    href=\"edit_user.php?user={$user_list[$i]['uid'][0]}\">edit</a></td> \n".
    "</tr>\n";
    ---

    The line in question really is this one;

    <a href=\"edit_user.php?user={$user_list[$i]['uid'][0]}\">edit</a></td> \n".

    As you can see this creates a link to the 'edit_user.php' page with a GET
    parameter generated by a php array.

    The 'edit_user.php' page contains this script (before any headers are
    generated) which is designed to put the GET value into a cookie;

    ---
    if (! isset($_COOKIE['yhgfluseruid'])) {
    $useruid=$_REQUEST['user'];
    setcookie('yhgfluseruid',$useruid);
    }
    ---

    What happens when actually viewing the pages in a browser, is that the url
    is generated (seemingly) correctly, for example;
    http://localhost/emailadmin/src/edit_user.php?user=net

    The only problem is the $user variable doesn't seem to read the cookie, or
    the cookie doesn't get generated before the rest of the page is generated
    and the users details are blank. BUT if I refresh the page, everything is
    fine. Also, if I go back to the 'list_user.php' page, and try editing a
    different user, although the URL suggests that it's passing the correct
    parameters, I end up seeing the details of the previous user?

    Help please (sorry for the long description - I am just trying to be
    accurate)

    Regards
    Steve
    Steve Guest

  2. #2

    Default Re: GET form method and accessing its value into a cookie

    Steve wrote: 
    [cut]
    different user, although the URL suggests that it's passing
    the correct 

    Your $_COOKIE is set only once, I think you have to do
    unset() somewhere in the script while begining another user
    edition.

    AG
    Andrzej Guest

  3. #3

    Default Re: GET form method and accessing its value into a cookie

    Steve,

    Here's a snippet from the PHP manual:
    "Once the cookies have been set, they can be accessed on the next page load with
    the $_COOKIE or $HTTP_COOKIE_VARS arrays."

    All you dowith setcookie() is sending a cookie to the browser. This doesn't mean
    the value is also stored in the $_COOKIE array at that time. That doesn't happen
    until the next request when the server receives back the cookie from the
    browser. That's why when you refresh the page everything seems to be suddenly
    working.

    What are you trying to achieve by setting the cookie in the edit_user.php script
    if you want to use that data in the same page anyway? The data is already
    available to your script from the $_REQUEST array (and, in this case, from the
    $_GET array).

    fetch
     
    J Guest

Similar Threads

  1. Problem accessing results from DataService fill method
    By New Flex Guy in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: June 30th, 12:53 AM
  2. accessing java method; lucene
    By cfpaperboy in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: April 24th, 08:43 AM
  3. Replies: 0
    Last Post: May 24th, 07:35 PM
  4. Replies: 2
    Last Post: December 23rd, 02:57 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