rossh Posted September 13, 2006 Share Posted September 13, 2006 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.ThanksRoss $filename = "advert.txt"; $a_advert = array(); $file = fopen($filename, "r"); while(!feof($file)) { $aQuotes[] = fgets($file, 4096); } $iQuoteNum = $_COOKIE["quotes"]; if($iQuoteNum == "" || $iQuoteNum >= sizeof($aQuotes)-1) { $iQuoteNum = 0; } else { $iQuoteNum++; } setcookie ("quotes"); setcookie("quotes", $iQuoteNum); $banner = $aQuotes[$iQuoteNum]; return $banner; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.