Newbie Cookie Question
Moderator: General Moderators
Newbie Cookie Question
What to take the form's action from a Get Method response and put it in a Cookie.
How do I do that?
My purpose is to navigate to the URL (my found set) once I'm done editing one of the found records.
-Dave
How do I do that?
My purpose is to navigate to the URL (my found set) once I'm done editing one of the found records.
-Dave
first off, you should think about the size it can get to.
i suggest reading more here: http://us3.php.net/manual/en/function.setcookie.php
if you don't know how to access the post variables, i suggest using the search function on this site ot search for book reccommendations. it's at the beginning of every book i've seen.
and what i don't see is that netscape's original specification maxed at 4kb. that's what cookies are based on. that's better than the limitations of get, but may require multiple cookies for your purpose.All the arguments except the name argument are optional. You may also replace an argument with an empty string ("") in order to skip that argument. Because the expire and secure arguments are integers, they cannot be skipped with an empty string, use a zero (0) instead. The following table explains each parameter of the setcookie() function, be sure to read the Netscape cookie specification for specifics on how each setcookie() parameter works and RFC 2965 for additional information on how HTTP cookies work
i suggest reading more here: http://us3.php.net/manual/en/function.setcookie.php
if you don't know how to access the post variables, i suggest using the search function on this site ot search for book reccommendations. it's at the beginning of every book i've seen.
Code: Select all
<?php
$var = $_GET['var'];
$var = trim($var);
setcookie("variable", $var);
?>I might not have understood you but it sounds like you have a page with a list, you click a link to edit an item in the list page, then you want to redisplay the list.
You could add the url for the list page to the form in a hidden field and then, in the form processor, use a header call to return to that page.
If the form always returns to the same list, ie the url is constant, just add the header call in the form processor.
You could add the url for the list page to the form in a hidden field and then, in the form processor, use a header call to return to that page.
If the form always returns to the same list, ie the url is constant, just add the header call in the form processor.
Clarification
Page 1 has a form with a search textfield that holds the client's search entry. When the "Search" button is pressed the form sends the following get action to page 2.
On page 2 a list is supplied from this get action from the form on page 1. On each line on the list is a link that takes me to another page to do an update for that data, which then takes me to another page that tells me whether or not my update was successful.
From that page I want to have a link that will take me back to the list on page 2 so I can select another entry to edit and update.
That's why I believe I need to use a cookie. It appears then I need to use the $_Get function and have it to insert my form action command into a cookie.
-Dave
Code: Select all
index.php?laosSearch=<?php echo $row_rsLaosї'last'];?>From that page I want to have a link that will take me back to the list on page 2 so I can select another entry to edit and update.
That's why I believe I need to use a cookie. It appears then I need to use the $_Get function and have it to insert my form action command into a cookie.
-Dave
Got what I needed
Got what I needed using the $HTTP_GET_VARS predefined variable. For some reason $_GET didn't work.
Once I retrieved that data I put into a string that I then put into a cookie.
Not I can use that cookie's data and come back to my found set.
-Dave
Once I retrieved that data I put into a string that I then put into a cookie.
Not I can use that cookie's data and come back to my found set.
-Dave
Last edited by theoph on Thu Jul 31, 2003 4:40 pm, edited 1 time in total.
setcookie() has to be called before anything else
I've never been able to use $HTTP_POST_VARS or $HTTP_GET_VARS because you have to do something like this:
setcookie ("fname",$HTTP_GET_VARS["variable"],$expiry,"/","domain.com",0);
setcookie() doesn't work. However using $_SESSION["variable"] does. So I just store my variables in the session and pass them along like that.
Hope this helps.
btw, use $HTTP_POST_VARS. You can get more info in your form.
setcookie ("fname",$HTTP_GET_VARS["variable"],$expiry,"/","domain.com",0);
setcookie() doesn't work. However using $_SESSION["variable"] does. So I just store my variables in the session and pass them along like that.
Hope this helps.
btw, use $HTTP_POST_VARS. You can get more info in your form.
If $_SESSION works for you, guinness, then you're probably using PHP 4.2+
Don't use $HTTP_POST_VARS, use $_POST and $_GET or $_REQUEST - as demonstrated in this sticky.
Don't use $HTTP_POST_VARS, use $_POST and $_GET or $_REQUEST - as demonstrated in this sticky.
Saw that post earlier from Jason
Thanks. Yeah, saw that post from Jason after I posted my response.
Still Need Help with Cookie
I'm working on a web page using Dreamweaver MX where I'm using a form to do a search which redirects the result back to the same page. This it does fine. On each of the rows of the find, I have two links. One takes me to an Update page and the other takes me to a Delete page. Once I'm done editing for example, I have the page to take me to a third page where it shows the updated data for my review. It is from this page, I'm wanting to to have a link that take be back to my "found set" Search page. This is why I want to put the URL & query into a cookie, which can be access from the Update display page.
I using the following script to set my cookie on the Seach page:
Works fine when I click on the "Find" button on my Search page form, however, it is giving me my last URL address instead of the current. All I want is for the cookie to equal what is in the current URL address field of my browser.
Can anyone help this poor newbie?
I using the following script to set my cookie on the Seach page:
Code: Select all
<?php setcookie ("laostest",$PHP_SELF."?".$_SERVERї'QUERY_STRING']);?>Can anyone help this poor newbie?
Last edited by theoph on Thu Aug 07, 2003 12:42 pm, edited 1 time in total.
I would think that that might have to do with the nature of cookies. You can't write and read them on the same page (see manual:setcookie), but I might be wrong.
It depends entirely on how you have arranged the PHP-code and whether a page is a PHP-code page or an outputted page (created by the same PHP-code page).
It depends entirely on how you have arranged the PHP-code and whether a page is a PHP-code page or an outputted page (created by the same PHP-code page).