Jump to content

[SOLVED] help me please with save listing / save search


work_it_work

Recommended Posts

well, it still doesn't work

what i did:

erased all the cookies and everything from IE

went to temporary internet folder to see if it was empty, and it was

 

i executed the first ulr http://localhost/tataee/tatae/save_listing.php?id=3333335 cookie appear in temporary folder and had this content:

saved_announcement

3333335

localhost/tataee/tatae/

1536

312670464

30056191

2590556560

29982765

*

executed the second url: http://localhost/tataee/tatae/save_listing.php?id=555556

new cookie looks like this:

 

saved_announcement

555556

localhost/tataee/tatae/

1536

532670464

30056191

2806966560

29982765

*

 

why it's not working?

please note the cookie it's not named like a regular one ex:"cookie:[email protected]/" internet address is"cookie:[email protected]/"

it's named like this:"tatae/" and the internet address is "Cookie:admin@localhost/tataee/tatae/"

replace all your code with the following and copy and paste what you have on screen;

 

<?php
//adding another announcement
$new_a_id = $_GET['id'];
$year = (60*60*24*365);
echo 'Line 1: '.$_COOKIE['saved_announcements'].'<br />';
if(isset($_COOKIE['saved_announcements'])){
echo 'Line 2: it was set<br />';
   $a_ids = explode(",", $_COOKIE['saved_announcements']);
   forech($a_isd as $a_id_check) {
      if($new_a_id == trim($a_id_check)) {
         header("Location: a-page-because-that-announcement-is-already-saved.php");
         exit;
      }
   }
   $new_a_array = $_COOKIE['saved_announcements'].", $new_a_id";
   echo 'Line 3: '.$new_a_array;
   setcookie("saved_announcement", $new_a_array, time()-$year);
   setcookie("saved_announcement", $new_a_array, time()+$year);
} else {
echo 'Line 2: it wasn\'t set<br />';
setcookie("saved_announcement", $new_a_id, time()+$year);
?>

I think this has something to do with setting cookies on a local server. Also a cookie requires a page reload as it is sent in the HTTP header, I think this code will work in a live environment, I can't see why it won't work....

<?php
if (isset($_COOKIE['saved_announcement'])) {
$newCookie = $_COOKIE['saved_announcement'] . ", " . $_GET['id'];
setcookie('saved_announcement', $newCookie, time()+3600, "/", "yourdomain.com");
}else {
setcookie('saved_announcement', $_GET['id'], time()+3600, "/", "yourdomain.com");
}

echo "Cookie Contains: " . $_COOKIE['saved_announcement'];
die();
?>

 

Doing that outputs this after I ran that for id=1 and id=2 and id=3

 

Cookie Contains: 1, 2, 3

 

I do not know where your script is messing up, possible at the setcookie function, notice I added the path and domain to that.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.