1

Please note that I'm not very good with PHP, and I did browse the web to find my answer, and I was unable to find it, so I decided to ask it here!

I have two CSS files: black.css and white.css ; the default one is black.css, and I want to be able to change to the white and back if needed. This is my link to the stylesheet:

<link rel="stylesheet" type="text/css" media="screen" title="User Defined Style" `href="<?php echo (!$sitestyle)?'black':$sitestyle ?>.css" />`

This is my HTML code: (Found in index.php)

<a href="switcher.php?set=white">
click here to change to WHITE style!</a>

This is my PHP code: (Found in switcher.php)

<?php
setcookie ('sitestyle', $set, time()+31536000, '/', 'mydomain.com/', '0');
header("Location: $HTTP_REFERER");
?>

When attempting to switch styles, it gives me an error saying 'The page isn't redirecting properly'.

4

2 回答 2

0

我建议您不要参考其他页面,而是在同一页面上执行所有操作:

//index.php

<?
   if(isset($_GET['set']))
       setcookie ('sitestyle', $_GET['set'], time()+31536000, '/', 'mydomain.com[Censored :P]/', '0');
?>

 <link rel="stylesheet" type="text/css" media="screen" title="User Defined Style"    href="<?php echo (!$sitestyle)?'black':$sitestyle ?>.css" />

单击此处更改为白色样式!

并使用更好的 $_SESSION[''] 代替 cookie。)

于 2012-12-01T10:31:12.070 回答
0

尝试:

<?php
setcookie ('sitestyle', $_GET['set'], time()+31536000, '/', 'mydomain.com[Censored :P]/', '0');
header("Location: $_SERVER[HTTP_REFERER]");
?>
于 2012-12-01T10:15:57.827 回答