Jump to content

Archived

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

rossh

Pass value from function to cookie

Recommended Posts

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.

Thanks

Ross
            $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;

Share this post


Link to post
Share on other sites

×

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.