1

How do I obtain the asp cookie's name and value using PHP so i may assign it to a variable? PHP and ASP are on the same domain.

Classic Asp Create Cookie

response.cookies("apple")("red")="reddelicious"
response.cookies("apple")("yellow")="gingergold"
response.cookies("apple")("green")="grannysmith"
response.cookies("apple").expires = dateadd("d",2,Now())

Classic ASP Read Cookie

strRed = request.cookies("apple")("red")
strYellow = request.cookies("apple")("yellow")
strGreen = request.cookies("apple")("green")

Reading The ASP cookies with PHP echo

echo $_COOKIE["apple"];

In firebug, after expanding the 'apple' cookie within the console, 'echo $_COOKIE["apple"]' outputs:

red=reddelicious&yellow=gingergold&green=grannysmith 

Tried:

$strRed = $_COOKIE["apple"]["red"]; //doesn't work
Patriotec
  • 1,104
  • 4
  • 22
  • 43

2 Answers2

2

You could use the parse_str function in php

<?php

parse_str($_COOKIE["apple"], $apple);

echo($apple["red"]);

?>
Flakes
  • 2,422
  • 8
  • 28
  • 32
0

To get the string red=reddelicious&yellow=gingergold&green=grannysmith to the format of a multi dimensional array try this:

$itemArray = explode('&', $_COOKIE['apple']);  // Split variables at '&'
foreach($itemArray as $item){ // for each variable pair 'key=value'
    $itemParts = explode('=', $item); // split string to '[key, value]'
    $apple[$itemParts[0]] = $itemParts[1]; // set each item to $apple[key] = value; 
}

Then you can use the variable like this:

$strRed = $apple["red"]; //should work :)
Patrick Murphy
  • 2,311
  • 14
  • 17