Hi php kenner,

Foutmelding check www.gebarentolk.net/site als je 2x ophetzelfde link klikt onder "normale mode" krijg ik:

Warning: Invalid argument supplied for foreach() in /var/www/html/site/switcher.php on line 23

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/site/switcher.php:23) in /var/www/html/site/switcher.php on line 43

switcher.php script:

<?php
/***********************************************
* sets a cookie with values taken from the accessibility options
************************************************/
// This array lists the "acceptable" styles
$accept = array('default','larger', 'colour_option1', 'colour_option2'); /*ADD YOUR OPTIONS HERE*/
// add more styles separated by commas

// Get style from a query string (e.g. from a link),
// or from a form.
if(isset($_REQUEST['set'])){
$style = trim(strip_tags($_REQUEST['set']));
} else if(isset($_POST['set'])){
$style = trim(strip_tags($_POST['set']));
} else {
// Unknown request
$style = false;
}

// Check if the requested stylesheet is "acceptable"
if(($style !== false) && (in_array($style, $accept))){
if ($style == 'default') {
foreach($_COOKIE['sitestyle'] as $style) {
setcookie("sitestyle[$style]", "", time()-86400, '/');
}
} else {
setcookie("sitestyle[$style]", $style, time()+86400, '/');//day
}
}

if(isset($_REQUEST['ref']) || (isset($_POST['ref']))){
if(isset($_REQUEST['ref'])){
$ref = $_REQUEST['ref'];
}
else {
$ref = $_POST['ref'];
}
header("Location: $ref");
exit;
}
else if(isset($_SERVER['HTTP_REFERER'])){
// Send the user back to the refering page
header("Location: ". $_SERVER['HTTP_REFERER']);
exit;
}
else {
// No HTTP referrer, send them back to the home page
header("Location: http://www.gebarentolk.net/site";); /*ADD YOUR SERVER HERE*/
exit;
}
?>

PHP in header:

/***********************************************
* reads a cookie to get values for the accessibility options
* these are stored in an array in the cookie as:
* sitestyle('default', 'larger', 'colour_option1') etc...
************************************************/
if(isset($_COOKIE['sitestyle'])){
foreach($_COOKIE['sitestyle'] as $style) {
$css_tag = "<link type=\"text/css\" rel=\"stylesheet\" ";
$css_tag .= "href=\"stylesheet.php?";
$css_tag .= "name=$style\" media=\"screen\">";

echo $css_tag;
}
}

PHP switcher button:

/***********************************************
* Writes the accessibility menu
************************************************/
echo "<ul>";
echo "<li><a href=\"switcher.php?set=default\">Default Text/Colour</a></li>";/*ADD YOUR OPTIONS HERE*/
echo "<li><a href=\"switcher.php?set=colour_option1\">Colour option 1</a></li>";
echo "</ul>";

----------------------

Iemand idee wat ik fout doe?? Hij werkt prima als je perongeluk 2x klik op hetzelfde link krijg ik een melding!

Alvast bedank!

Gr.Sebas

Reageren