Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's
Author Message
xGSTQ
Involved
Involved


Joined: Feb 03, 2006
Posts: 267
Location: UK

PostPosted: Wed Jan 25, 2012 4:24 am Reply with quote

This one had me stumped, I mean I have tried and failed miserably Embarassed

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
 
View user's profile Send private message Send e-mail Visit poster's website
Palbin
Site Admin


Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Wed Jan 25, 2012 5:56 am Reply with quote

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. 
View user's profile Send private message
xGSTQ
PostPosted: Wed Jan 25, 2012 6:44 am Reply with quote

Hey Palbin,

I guess set a cookie until they change it again... that would be the ideal situation
 
Palbin
PostPosted: Wed Jan 25, 2012 8:17 am Reply with quote

Are you doing this for an RN site or another nuke variant. I just need to know so I know what to give you.
 
xGSTQ
PostPosted: Wed Jan 25, 2012 11:26 am Reply with quote

Erm, its for myself TBH... Ive just installed RN2.5 so if you wanted to do it for that Wink

Is it that complex :-/

Cheeers
 
Guardian2003
Site Admin


Joined: Aug 28, 2003
Posts: 6793
Location: Ha Noi, Viet Nam

PostPosted: Wed Jan 25, 2012 3:55 pm Reply with quote

When your done with that, I want mine to change telepathically to save me the 2 mouse clicks Wink
 
View user's profile Send private message Send e-mail
Palbin
PostPosted: Wed Jan 25, 2012 5:04 pm Reply with quote

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 />';

?>
 
xGSTQ
PostPosted: Thu Jan 26, 2012 2:23 am Reply with quote

Guardian2003 wrote:
When your done with that, I want mine to change telepathically to save me the 2 mouse clicks Wink


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
 
xGSTQ
PostPosted: Thu Jan 26, 2012 2:25 am Reply with quote

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
 
xGSTQ
PostPosted: Thu Jan 26, 2012 3:12 am Reply with quote

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 Only registered users can see links on this board! Get registered or login!

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
 
Palbin
PostPosted: Thu Jan 26, 2012 5:45 am Reply with quote

I will try local tonight, but I would try dropping the Only registered users can see links on this board! Get registered or login! and only making it "localhost/ravens_250".
 
Guardian2003
PostPosted: Thu Jan 26, 2012 11:12 am Reply with quote

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
 
spasticdonkey
RavenNuke(tm) Development Team


Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA

PostPosted: Thu Jan 26, 2012 11:45 am Reply with quote

Can't you just exclude those extra values when using setcookie?
setcookie('theme', $theme, $themeExpire);
 
View user's profile Send private message Visit poster's website
xGSTQ
PostPosted: Thu Jan 26, 2012 11:46 am Reply with quote

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 Smile


Yeah i saw that nice feature
 
Palbin
PostPosted: Thu Jan 26, 2012 12:03 pm Reply with quote

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.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©