Author |
Message |
xGSTQ
Involved
![Involved Involved](modules/Forums/images/ranks/4stars.gif)
![](modules/Forums/images/avatars/gallery/blank.gif)
Joined: Feb 03, 2006
Posts: 269
|
Posted:
Wed Jan 25, 2012 4:24 am |
|
This one had me stumped, I mean I have tried and failed miserably
What I was trying to achieve was letting someone choose / select a theme via a link
Now I know there was/is a theme preview block, a submit form and I know you can do it from Your Account
But I wanted to allow a user or even a non user to simply click a link and it would load the site with a specific theme
I dont think its been done before, maybe it was done on phpthemes.net but that site is now gone so I cant recall how they did it exactly
Ped |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Palbin
Site Admin
![](modules/Forums/images/avatars/Dilbert/Dilbert_-_Dogbert_King.gif)
Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania
|
Posted:
Wed Jan 25, 2012 5:56 am |
|
Are you looking to permanently change the theme for a user or just set a cookie for users/non-users to temporarily change the theme? |
_________________ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
xGSTQ
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Wed Jan 25, 2012 6:44 am |
|
Hey Palbin,
I guess set a cookie until they change it again... that would be the ideal situation |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Palbin
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Wed Jan 25, 2012 8:17 am |
|
Are you doing this for an RN site or another nuke variant. I just need to know so I know what to give you. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
xGSTQ
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Wed Jan 25, 2012 11:26 am |
|
Erm, its for myself TBH... Ive just installed RN2.5 so if you wanted to do it for that
Is it that complex :-/
Cheeers |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Guardian2003
Site Admin
![](modules/Forums/images/avatars/125904890252d880f79f312.png)
Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam
|
Posted:
Wed Jan 25, 2012 3:55 pm |
|
When your done with that, I want mine to change telepathically to save me the 2 mouse clicks ![Wink](modules/Forums/images/smiles/icon_wink.gif) |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Palbin
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Wed Jan 25, 2012 5:04 pm |
|
Here is a quick example. It is important to note that when you set the cookie it will not be available until the next page load. So you will need to use $_GET['theme'] on the first page load if you need it. It will be very important to escape this value if you are using it in a DB call.
If you need a more specific help with a certain implementation let me know.
Code:
<?php
if (!empty($_GET['theme'])) {
$theme = $_GET['theme'];
/**
* This is set to expire in 30 days. Change the 30 to the numbr of days required.
*/
$themeExpire = time()+60*60*24*30;
setcookie('theme', $theme, $themeExpire, '/', 'www.YourDomain.com', false, false);
} else {
$theme = '';
}
if (!empty($_COOKIE['theme'])) {
echo 'The theme cookie is set to ' , $_COOKIE['theme'] , '.';
} else {
echo 'The theme cookie is not set.';
}
echo '<br /><br />';
echo '<a href="?theme=theme1">Theme 1</a><br />';
echo '<a href="?theme=theme2">Theme 2</a><br />';
echo '<a href="?theme=theme3">Theme 3</a><br />';
?>
|
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
xGSTQ
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Thu Jan 26, 2012 2:23 am |
|
Guardian2003 wrote: | When your done with that, I want mine to change telepathically to save me the 2 mouse clicks |
haha who rattled your cage !!! lmao
Its for visitors actually (so before there registered)... I want them to view the site in the preferred theme, so they click a link (game) and it takes them to the site viewing the games theme..
made me chuckle though ![Very Happy](modules/Forums/images/smiles/icon_biggrin.gif) |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
xGSTQ
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Thu Jan 26, 2012 2:25 am |
|
Sweet thanks Palbin
I have to shoot out now for a few hours but I will try it out this evening
I would have never ever had been able to come up with something like that, I would love to learn some new stuff |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
xGSTQ
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Thu Jan 26, 2012 3:12 am |
|
I couldn't resist having a go... im using it on localhost would that matter ?
I cant seem to get it to work, doesn't want to set the cookie
I just threw the code into a test.php in the root and changed the themes and domain name to http://localhost/ravens_250
Im presuming its the domain name, I dont have a live install to play on at the moment but I can install one later today, right got to shoot out !!!
hehe |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Palbin
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Thu Jan 26, 2012 5:45 am |
|
I will try local tonight, but I would try dropping the http:// and only making it "localhost/ravens_250". |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Guardian2003
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Thu Jan 26, 2012 11:12 am |
|
You know that in RN 2.5 you can set 2 themes - one for anonymous and one for registered users? Just thought I'd mention it ![Smile](modules/Forums/images/smiles/icon_smile.gif) |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
spasticdonkey
RavenNuke(tm) Development Team
![](modules/Forums/images/avatars/48fb116845dfecf66294c.gif)
Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA
|
Posted:
Thu Jan 26, 2012 11:45 am |
|
Can't you just exclude those extra values when using setcookie?
setcookie('theme', $theme, $themeExpire); |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
xGSTQ
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Thu Jan 26, 2012 11:46 am |
|
Guardian2003 wrote: | You know that in RN 2.5 you can set 2 themes - one for anonymous and one for registered users? Just thought I'd mention it |
Yeah i saw that nice feature |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Palbin
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Thu Jan 26, 2012 12:03 pm |
|
spasticdonkey wrote: | Can't you just exclude those extra values when using setcookie?
setcookie('theme', $theme, $themeExpire); |
This would probably be better for testing locally. I have read about problems with certain browsers and using localhost as a domain in a cookie. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
|