473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

find a cookie by part of it's name

Hi all,

cookies are stored in an array called $HTTP_COOKIE_VARS right ?

Is it possible to find a cookie if you know part of it's name ?

For example the cookiename is firstname and I want to check all
cookies that start with "first" in there name.

I tried to work wih string and substrings, but that didn't seem
to work ?
May 9 '06 #1
3 2956
Ron Croonenberg wrote:
Hi all,
Hi,

cookies are stored in an array called $HTTP_COOKIE_VARS right ?
Sometimes, it is an 'old' array, possibly not available in future version of
PHP.

Use $_COOKIE instead if you can.

read more here:
http://nl3.php.net/manual/en/reserve...iables.cookies

Is it possible to find a cookie if you know part of it's name ?
Yes.
Try this:

<pre>
<?php print_r($_COOKIE); ?>
</pre>

That will output to html, nicely formatted, what is in the cookiestring the
clientbrowser send along the request to your page.

For example the cookiename is firstname and I want to check all
cookies that start with "first" in there name.
Just examine the output of the above, and you'll figure out a way to search
for substrings. If not, come back here with some samplecode.

I tried to work wih string and substrings, but that didn't seem
to work ?


Show us what you tried, along with the content of $_COOKIE your script
received.

Regards,
Erwin Moller
May 10 '06 #2
On Mon, 08 May 2006 20:53:38 -0400, Ron Croonenberg wrote:
Hi all,

cookies are stored in an array called $HTTP_COOKIE_VARS right ?
$_COOKIE is better.
Is it possible to find a cookie if you know part of it's name ?

For example the cookiename is firstname and I want to check all cookies
that start with "first" in there name.

I tried to work wih string and substrings, but that didn't seem
to work ?


The answer is easy, but this is sounding a bit like homework... Post the
code you have and we'll help more.

As a hint, use foreach to iterate the $_COOKIE array, look at the key for
each item and compare it using either substr or regular expressions.

That should have given you enough terms to Google your way through it.

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

May 10 '06 #3
Ron Croonenberg wrote:
Hi all,

cookies are stored in an array called $HTTP_COOKIE_VARS right ?

Is it possible to find a cookie if you know part of it's name ?

For example the cookiename is firstname and I want to check all
cookies that start with "first" in there name.

I tried to work wih string and substrings, but that didn't seem
to work ?


First of all, as others have said, use $_COOKIE instead.

Second, $_COOKIE is an array, so you can use the array functions to
find the cookie.

And since you're looking for the cookie *name*, array_search() and
array_keys() would be useful in this case. Like this:

$cookiename = array_search("firstname",array_keys($_COOKIE));

If the search turns up empty, then $cookiename = false, otherwise,
$cookiename will contain the name of the cookie. The value for the
cookie is then easily retrieved by $_COOKIE[$cookiename].

--
Kim André Akerĝ
- ki******@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
May 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan Stromberg | last post by:
If I wanted to write a python script that performs basic auth, gets a cookie, and then does an http POST using the cookie for authentication, what would be the best python API to write to? Does...
3
by: F | last post by:
It seems that document.cookie doesn't work both on Internet Explorer 5 for Mac (OS 9) and Opera 6 for PC... am I doing something wrong? Or does it just not work? I don't get an error message, the...
3
by: Karsten Grombach | last post by:
Hi, I'm trying the following: - Imitate a Logon using a Post with HttpWebRequest on remote Webserver (asp 3.0 page using https) - On success redirect to the page (encapsuled in an iframe)...
1
by: Randall Parker | last post by:
Looking at the fields for configuring a web site's security and I'm using Forms authentication. Saw the part about assigning a cookie name. I assume this is the cookie that gets set when a person...
4
by: Gridlock | last post by:
I'm trying to read the cookies using HttpContext.Current.Request.Cookies, but the only cookie that I get is the ASP.NET SessionId cookie. There are many cookies on the machine, why am I only...
4
by: MrL8Knight | last post by:
Hello, I am trying to build a simple php form based shopping cart using a cookie with arrays. I need to use 1 cookie because each order will have over 20 items. With that said, I realize I need to...
8
by: mutale82 | last post by:
I need to integrate a tracking system with a few clients, the clients agree to place <img src="....."tags but not to place a file on there servers. I need to set a cookie on the visitor computer...
5
by: mosscliffe | last post by:
I have the following code, which I thought would create a cookie, if one did not exist and on the html form being sent to the server, it would be availabe for interrogation, when the script is run...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.