开发者

php styleswitcher cookies not set in wordpress. why?

Update a day later: Cookies are now being set. I try to show the changes I needed to make with the edits in the code quoted below. There's still a problem. Now it's not applying the non-default stylesheets! The browser can find them, but not the switcher....

(original question:) I'm using Rob Ballou's v.2 Styleswitcher (robballou.com/switcher/v2/tutorial.php), in a WP3 blog (site is here). I've altered the stylesheet urls, so that WP knows where to find them:

from:

$ss->addStyle("default", "style.css", "", "", true);

to

$my_url = get_bloginfo('template_url');

$ss->addStyle("default", $my_url . '/style.css', "", "", true);

Judging by the document source, the style sheets are being found. So that's not the problem. However, the cookie just is not getting set. If I run the exact same scripts on a web page (eg molvray.com/testing/ss-example.php), it works, and when I check the cookies, cwStyle has been set. But as soon as it's in WP, no luck.

I'm guessing the problem is this line: $ss->cookieDomain = ".". $_SERVER['HTTP_HOST']; in switcher.php. I saw a post that suggested using HTTP_REFERRER instead, but that doesn't help. I've included switcher.php below. I haven't touched Styleswitcher.php itself.

Can anyone tell me what I'm doing wrong? I'm going nuts here!

Please be as dumbed-down as you can, so that I have a snowball's chance of following. I'm pretty useless at programming.

New: most of switcher.php is included in header.php instead of as a separate file.

in header.php:

<?php

require_once("Styleswitcher.php");

$ss = new Styleswitcher('/switcher/v2/');

if(!isset($reqPath)){ $reqPath = ""; }
require_once($reqPath ."Styleswitcher.php");
$my_url = get_bloginfo('template_url');
$ss = new Styleswitcher();

$ss->addStyle("default", $my_url . '/style.css', "", "", true);
$ss->addStyle("lowgraphics", $my_url . '/handheld.css');
$ss->addStyle("highcontrast", $my_url . '/highcontrast.css');

$ss->createSet("style");
$ss->addStyleToSet("style", "default", true);
$ss->addStyleToSet("style", "lowgraphics");
$ss->addStyleToSet("style", "highcontrast");

$ss->cookieDomain = ".". $_SERVER['HTTP_HOST'];
$ss->cookieName = "cwStyle";

$ss->start();

$ss->printStyles();
    ?>

the actual switcher.php is then just:

<?php
if(!isset($reqPath)){ $reqPath = $my_url; }
require_once("Styleswitcher.php");
$ss = new Styleswitcher('/switcher/v2/');
$ss->cookieDomain = ".". $_SERVER['HTTP_HOST'];
$ss->cookieName = "cwStyle";
$ss->start();
?>

form as used in the header.php of wordpress has "<_?php bloginfo('template_url'); ?>/switcher.php" instead of just "switcher.php"

<form action="<?php bloginfo('template_url'); ?>/switcher.php" method="post">

<_input type="hidden" name="referer" id="referer" value="" />

    <input type="hidden" name="inputStyle2" id="inputStyle2" value="style" />        
    &l开发者_如何学运维t;li><input type="submit" name="style" id="default" value="Default" <?php $ss->printSetInputChecked("style", "default"); ?>/></li>    
    <li><input type="submit" name="style" id="lowgraphics" value="Mobile" <?php $ss->printSetInputChecked("style", "lowgraphics"); ?>/></li>
    <li><input type="submit" name="style" id="highcontrast" value="High&nbsp;Contrast" <?php $ss->printSetInputChecked("style", "highcontrast"); ?>/> </li>
    </form>

The crucial bit, I think, was adding the php bloginfo('template_url') path to switcher.php in the form element. Now on to figuring out why it doesn't go to anything but the default style.


(continued response to The Dead Medic. I don't have the hang of the system here yet.)

I've also been looking around some more, and found something about a problem with WP registering global variables. http://wordpress.org/support/topic/wp-blog-headerphp-killing-sessions

I tried making a php.ini file in the blog root dir, with "register_globals Off" as suggested toward the end of that thread, but that didn't seem to do anything.

There's also this link, h_ttp://www.scratch99.com/2008/09/setting-cookies-in-wordpress-trap-for-beginners/ which talks about giving setcookie an explicit path, but I'm not clear how and where that would fit into my switcher.php above.

(To answer your last question: no, this isn't a plugin. WP is pathetic on styleswitchers, hence this odyssey :S )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜