You may use the following approach:
<?php
$value=(time+1800)+"|"+$YourData;
SetCookie("YourCookie",$value);
?>
...
<?php
list($ExpTime,$YourVariable)=explode("|","YourCookie",2);
if($ExpTime<time()){
...
}
else{
...
}
?>