You are here: Re: GET form method and accessing its value into a cookie « PHP Language « IT news, forums, messages
Re: GET form method and accessing its value into a cookie

Posted by J Johanson on 07/21/05 18:37

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

> 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 .= "<tr class=\"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=paul.bradley@eriding.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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация