Jump to content


Pass value from function to cookie

  • Please log in to reply
No replies to this topic

#1 rossh

  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 13 September 2006 - 09:19 PM

Hi i have this code which takes lines in a text file puts it in an array and then prints the first array value.  Once the user refreshes the screen we move onto the next array element.

I want to put this into a function so i can use it for different text files, but i don't know how to handle the cookies and return the current $iQuoteNum to the cookie outside the function.  I've figured i can't have the setcookie function inside the function as i'm getting the headers already sent error?

Any help would be appreciated.


            $filename = "advert.txt";
$a_advert = array();
$file = fopen($filename, "r");

$aQuotes[] = fgets($file, 4096);

$iQuoteNum = $_COOKIE["quotes"];

if($iQuoteNum == "" || $iQuoteNum >= sizeof($aQuotes)-1)
$iQuoteNum = 0;
setcookie ("quotes");
setcookie("quotes", $iQuoteNum);

$banner = $aQuotes[$iQuoteNum];
return $banner;

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users