 |
10-05-2006, 01:13 PM
|
Cookies...
|
Posts: 774
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
|
Just attempting to use cookies and i get...
Warning: Cannot modify header information - headers already sent by (output started at /home/thebulls/public_html/includes/functions/misc.php:162) in /home/thebulls/public_html/config.php on line 50
Config.php arround line 50
PHP Code:
if ($_COOKIE['nopops'] == "TRUE" && $nopops !== "STOP")
{
$nopops == "TRUE";
setcookie("nopops", "TRUE");
}
elseif ($nopops == "STOP")
{
setcookie("nopops", "FALSE");
}
elseif ($nopops == "TRUE")
{
setcookie("nopops", "TRUE");
}
misc.php
PHP Code:
<?php
function bwsaver($filename)
{
global $off, $contents;
//if home pc is on
if($off == "NO")
{
//use http://(loggedip)/filename assigned at point of execution
echo "http://" . $contents . "/" . $filename;
}
//error trapping, allways pull styleshet off webserver
elseif($filename == "style.css")
{
echo "style.css";
}
//see if script is executed by server, rather than user
elseif(strpos($_SERVER['REQUEST_URI'],"~thebulls"))
{
//if so, use ../~thebulls/filename to make sure path is correct
echo "../~thebulls/" . $filename;
}
//if home pc is off, just use webserver
else echo "../" . $filename;
}
$phrase = $_SERVER['SCRIPT_NAME'];
$healthy = array("/", ".htm", "category", "search", "index", "ply", ".php");
$yummy = array("", "", "", "", "", "", "");
$btbgames = str_replace($healthy, $yummy, $phrase);
function gamelink($gamename, $gameid)
{
global $btbgames;
$healthy = array(" ");
$yummy = array("-");
$new = str_replace($healthy, $yummy, $gamename);
if ($btbgames != "~thebulls")
{
echo "<a href='";
echo $gameid;
echo "-";
echo $new;
echo "'>";
}
else
{
echo "<a href='ply.htm?id=";
echo $gameid;
echo "'>";
}
}
function gamelink2($gamename, $gameid)
{
global $btbgames;
$healthy = array(" ");
$yummy = array("-");
$new = str_replace($healthy, $yummy, $gamename);
if ($btbgames != "~thebulls")
{
echo "<a class='nav' href='";
echo $gameid;
echo "-";
echo $new;
echo "'>";
}
else
{
echo "<a class='nav' href='ply.htm?id=";
echo $gameid;
echo "'>";
}
}
function smile($post)
{
$smilies=array(':)' => "<img src='../images/smile.gif' />",':(' => "<img src='../images/sad.gif' />",':p' => "<img src='../images/tongue.gif' />",';)' => "<img src='../images/wink.gif' />",';smirk' => "<img src='../images/smirk.gif' />",':blush' =>"<img src='../images/blush.gif' />",':angry' =>"<img src='../images/angry.gif' />",':shocked'=> "<img src='../images/shocked.gif' />",':ninja'=>"<img src='../images/ninja.gif' />",':cool'=>"<img src='../images/cool.gif' />",'(!)'=>"<img src='../images/exclamation.gif' />",'(?)'=>"<img src='../images/question.gif' />",'(heart)'=>"<img src='../images/heart.gif' />",':{blink}'=>"<img src='../images/winking.gif'>",'{clover}'=>"<img src='../images/clover.gif'>",':[glasses]'=>"<img src='../images/glasses.gif'>",':[barf]'=>"<img src='../images/barf.gif'>",':[reallymad]'=>"<img src='../images/mad.gif'>",':[evil]'=>"<img src='../images/melkor.gif'>");
$post=str_replace(array_keys($smilies), array_values($smilies), $post);
return $post;
}
function file_put_contents2($filename, $data, $flags = 0, $f = FALSE)
{
if(($f===FALSE) && (($flags%2)==1)) $f=fopen($filename, 'a'); else if($f===FALSE) $f=fopen($filename, 'w');
if(round($flags/2)==1) while(!flock($f, LOCK_EX)) { /* lock */ }
if(is_array($data)) $data=implode('', $data);
fwrite($f, $data);
if(round($flags/2)==1) flock($f, LOCK_UN);
fclose($f);
}
function file_put_contents1($filename, $data, $flags = 0, $f = FALSE)
{
if(($f===FALSE) && (($flags%2)==1)) $f=fopen($filename, 'a'); else if($f===FALSE) $f=fopen($filename, 'w');
if(round($flags/2)==1) while(!flock($f, LOCK_EX)) { /* lock */ }
if(is_array($data)) $data=implode('', $data);
fwrite($f, $data);
if(round($flags/2)==1) flock($f, LOCK_UN);
fclose($f);
}
function MakeImage($cookie, $count = 0)
{
// Creation of image with GD
if ($cookie == 1)
{
$text = "Admin";
$im = imagecreate(50,20);
}
elseif ($cookie == 2)
{
if ($count == 0)
{
$length = 1;
}
else
{
$length = 1+intval(log($count)/log(10));
}
$size = 14+($length-1)*9;
$im = imagecreate($size,20);
$text = "$count";
}
elseif ($cookie == 3)
{
$text = "Count";
$im = imagecreate(50,20);
}
else
{
$text = "";
$im = imagecreate(1,1);
}
$black = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);
imagefill($im,0,0,$black);
ImageString($im,5,3,2,$text,$white);
if (function_exists("imagegif"))
{
@header("Content-type: image/gif");
imagegif($im);
}
elseif (function_exists("imagepng"))
{
@header("Content-type: image/png");
imagepng($im);
}
elseif (function_exists("imagejpeg"))
{
@header("Content-type: image/jpeg");
imagejpeg($im, "", 0.8);
}
elseif (function_exists("imagewbmp"))
{
@header("Content-type: image/vnd.wap.wbmp");
imagewbmp($im);
}
else
{
die("No image support in this PHP server");
}
ImageDestroy($im);
}
function backstr($haystack, $needle)
{
return substr($haystack, 0, strlen($haystack) - strlen(strstr($haystack,$needle)));
}
?>
Idea is this disables popup window for requests if people say they have a popup blocker. This bit works fine using address bar, but i wish for it to save what the users preference is for returining visits.
|
|
|
|
10-05-2006, 01:37 PM
|
Re: Cookies...
|
Posts: 481
|
It's exactly as the error says: you can't have ANY output to the browser before sending headers. Setting a cookie is sending a header and so you need to do this before ANY output.
Even a newline at the end of the ?> in an included file is output.
|
|
|
|
10-05-2006, 02:43 PM
|
Re: Cookies...
|
Posts: 774
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
|
no way of getting arround this? setting cookies using html for example?
|
|
|
|
10-05-2006, 03:31 PM
|
Re: Cookies...
|
Posts: 481
|
You could do it with Javascript, I guess, but definitely not HTML by itself.
Alternatively, use a PHP session. Again, you'll have to start the session before any output to the browser, but at least you won't have to assign any values right then and there...
|
|
|
|
10-06-2006, 12:19 PM
|
Re: Cookies...
|
Posts: 774
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
|
Off to look for a session tutorial!
EDIT:
Managed to get cookies working...
PHP Code:
if ($nopop == 2) { setcookie("nopops", 2, time() + 10); } elseif ($nopop == 1) { setcookie("nopops", 1, time() + (86400*365)); } elseif ($_COOKIE['nopops'] == 1) { $nopop = 1; setcookie("nopops", 1, time() + (86400*365)); } else $nopop = 2;
Taken me since I originaly posted at 17:19 GMT till 20:21 GMT
Last edited by mad_willsy : 10-06-2006 at 03:21 PM.
|
|
|
|
|
« Reply to Cookies...
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|