这是将复选框值提交到validatepreferences.php。
的表单<form action="validatepreferences.php" method="post"> <fieldset>
<legend>
Widgets
</legend>
<input type="checkbox" name="checkwidget[]" value="weather"> Hamilton Weather<br>
<input type="checkbox" name="checkwidget[]" value="nzherald"> NZ Herald
</fieldset>
<input type="submit" value="Save Changes">
这是validatepreferences.php
文件,我在其中设置了cookie值。 (这段代码一切正常,但我还没有弄清楚如何获得两个cookie值的数组)
<?php
if (isset($_POST['checkwidget'])) {
$checkwidget = $_POST['checkwidget'];
if ($checkwidget == "weather" || $checkwidget == "nzherald") {
setcookie("widget", $checkwidget, time() + 31536000 , "/");
}
}
header('Location: homepage.php');
?>
这是我用来为变量赋值以隐藏和显示小部件的PHP代码
<?php
$widgetchoice = "";
if (!isset($_COOKIE['widget'])) {
$widgetchoice = "weather" && "nzherald";
} else {
$widgetchoice = $_COOKIE['widget'];
}
?>
这是这个代码的问题我无法根据首选项中设置的cookie来设置和消失这些小部件(帮助我卡住)
<div id="columnright">
<!-- BEGIN NZHERALD PREGENERATED WIDGET BLOCK -->
<script type="text/javascript" src="http://www.nzherald.co.nz/apps/js/ReaderWidget/ReaderWidget.js"></script>
<script type="text/javascript" src="http://www.nzherald.co.nz/apps/js/JsonFeeder/JsonFeeder.js"></script>
<script type="text/javascript">
if (<?php echo $widgetchoice?> == 'nzherald'){
var feedsource = new JsonFeeder("http://www.nzherald.co.nz/json/rss/", {
"feedLink" : "http://www.nzherald.co.nz/",
"name" : "NZ Herald Up To The Minute"
});
var feedreader = new ReaderWidget("readerDiv", feedsource, 6);
window.onload = function() {
feedreader.run();
}
</script>
<br>
<div align="center">
<!-Weather in Hamilton, New Zealand on your site - HTML code - weatherforecastmap.com -->
<script>
if (<?php echo $widgetchoice?> == 'weather'){
< src="http://www.weatherforecastmap.com/weather2.php?zona=new-zealand_hamilton">
</script>
</div>