Page 1 of 2

Newbie Cookie Question

Posted: Wed Jul 30, 2003 5:26 pm
by theoph
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

Posted: Wed Jul 30, 2003 6:07 pm
by m3rajk
first off, you should think about the size it can get to.
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
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.

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.

Posted: Wed Jul 30, 2003 7:37 pm
by m3mn0n

Code: Select all

<?php
$var = $_GET['var'];
$var = trim($var);
setcookie("variable", $var);
?>
Reference material: http://www.php.net/setcookie , http://www.php.net/trim , & http://www.php.net/manual/en/reserved.v ... iables.get

Posted: Wed Jul 30, 2003 10:29 pm
by McGruff
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.

Clarification

Posted: Wed Jul 30, 2003 10:53 pm
by theoph
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.

Code: Select all

index.php?laosSearch=<?php echo $row_rsLaos&#1111;'last'];?>
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

Posted: Wed Jul 30, 2003 11:09 pm
by m3rajk
he was using get as an example.

i'm getting the feeling you've never accessed the arrays before.

try looking up that stuff in your books. it should help.

there's not much we can do witout seeing more

Posted: Thu Jul 31, 2003 2:31 am
by m3mn0n

Got what I needed

Posted: Thu Jul 31, 2003 1:27 pm
by theoph
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

Posted: Thu Jul 31, 2003 2:19 pm
by m3rajk
what version of php? if you're using $HTTP_GET_VARS instead of $_GET then it's most likely pre 4.1, so you should talk to the host about upgrading to a newer version... some of the upgrades since then have been security related

setcookie() has to be called before anything else

Posted: Tue Aug 05, 2003 3:41 pm
by guinness
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.

Posted: Tue Aug 05, 2003 6:31 pm
by patrikG
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.

Saw that post earlier from Jason

Posted: Wed Aug 06, 2003 1:40 pm
by guinness
Thanks. Yeah, saw that post from Jason after I posted my response.

Posted: Wed Aug 06, 2003 3:22 pm
by m3rajk
umm... warning about $_REQUEST[]
it uses the last thing that has something by that ame sot he order of Environment, Get, Post, Cookies, Server matters

Still Need Help with Cookie

Posted: Thu Aug 07, 2003 11:59 am
by theoph
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:

Code: Select all

<?php setcookie ("laostest",$PHP_SELF."?".$_SERVER&#1111;'QUERY_STRING']);?>
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?

Posted: Thu Aug 07, 2003 12:10 pm
by patrikG
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).