njb182 Posted May 29, 2008 Share Posted May 29, 2008 So my site has 2 styles: light and dark. On the index page you can chose which one you want to use. Is there a script that can remember which one you chose so the next time you visit my index page it will redirect to the style you had last time? I know how to use MySQL if it's going to require it. Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/ Share on other sites More sharing options...
trq Posted May 29, 2008 Share Posted May 29, 2008 I know how to use MySQL if it's going to require it. Then all you need do is save the users choice into a field related to there login details. next time the user visits or logs in, query that field and get the correct style. Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/#findComment-552287 Share on other sites More sharing options...
njb182 Posted May 29, 2008 Author Share Posted May 29, 2008 I know how to use MySQL if it's going to require it. Then all you need do is save the users choice into a field related to there login details. next time the user visits or logs in, query that field and get the correct style. But there is no log in. Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/#findComment-552290 Share on other sites More sharing options...
Ne.OnZ Posted May 29, 2008 Share Posted May 29, 2008 You could set a cookie for the theme, then the only problem you will have is if they have cookies enabled or not, and once they delete the cookie, it goes back to your original theme. Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/#findComment-552292 Share on other sites More sharing options...
Gighalen Posted May 29, 2008 Share Posted May 29, 2008 or you could create a table named 'themepref' id -> auto inc ip -> varchar(100) theme -> varchar(100) and then create a little snipplet that will save their pref to the table when they submit for the first time, or update if they submit the second. Then you can just have a query that will select their ip from the list and insert the theme name into the css syntax. and if mysql_num_rows = 0, you can have it set to a default. Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/#findComment-552319 Share on other sites More sharing options...
peranha Posted May 29, 2008 Share Posted May 29, 2008 or you could create a table named 'themepref' id -> auto inc ip -> varchar(100) theme -> varchar(100) and then create a little snipplet that will save their pref to the table when they submit for the first time, or update if they submit the second. Then you can just have a query that will select their ip from the list and insert the theme name into the css syntax. and if mysql_num_rows = 0, you can have it set to a default. But beware as users IPs change. Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/#findComment-552323 Share on other sites More sharing options...
Gighalen Posted May 29, 2008 Share Posted May 29, 2008 or you could create a table named 'themepref' id -> auto inc ip -> varchar(100) theme -> varchar(100) and then create a little snipplet that will save their pref to the table when they submit for the first time, or update if they submit the second. Then you can just have a query that will select their ip from the list and insert the theme name into the css syntax. and if mysql_num_rows = 0, you can have it set to a default. But beware as users IPs change. Yes, but some stay the same It's just a suggestion if you don't want to make a cookie Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/#findComment-552325 Share on other sites More sharing options...
njb182 Posted May 29, 2008 Author Share Posted May 29, 2008 Is there anyway to use both the cookies idea and the IP mysql idea? Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/#findComment-552556 Share on other sites More sharing options...
Ne.OnZ Posted May 29, 2008 Share Posted May 29, 2008 You could set the them in the cookie and mysql. If the ip does change and the cookie is still there, they will still see the selected theme, or if they delete the cookie and the ip is the same. But if the ip changes and the cookie is deleted, it goes back to the original theme, which isn't that much of a problem is it? Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/#findComment-552596 Share on other sites More sharing options...
njb182 Posted May 29, 2008 Author Share Posted May 29, 2008 You could set the them in the cookie and mysql. If the ip does change and the cookie is still there, they will still see the selected theme, or if they delete the cookie and the ip is the same. But if the ip changes and the cookie is deleted, it goes back to the original theme, which isn't that much of a problem is it? Nope. Could someone give me code to do this? When I said i know how to use mysql, I meant i know how to create databases. Thats about it. Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/#findComment-552931 Share on other sites More sharing options...
Ryan95 Posted May 30, 2008 Share Posted May 30, 2008 i helped hi iwth the style changing code...fo anyone who canadd to this: <?php $style = $_GET['style']; if ($style == 'dark') { require_once ($_SERVER['DOCUMENT_ROOT'].'/en/dark.php'); } else { require_once ($_SERVER['DOCUMENT_ROOT'].'/en/light.php'); } ?> Very short Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/#findComment-553134 Share on other sites More sharing options...
Ne.OnZ Posted May 30, 2008 Share Posted May 30, 2008 In your if statement, you would check to see if the cookie is set or if the ip is the same: I don't know how you set up your tables in mysql or what they are called, so adjust it to your needs. Also, assign the ip address to a variable, then check to see what theme the ip address has stored. I'm sure you know how to do that? <?php if ($_COOKIE['dark'] || $ip) { require_once ($_SERVER['DOCUMENT_ROOT'].'/en/dark.php'); } else if($_COOKIE['light'] || $ip) { require_once ($_SERVER['DOCUMENT_ROOT'].'/en/light.php'); } ?> If you don't know how to do the mysql part, you can read up on SELECT, INSERT, UPDATE, and some functions as mysql_fetch_array at w3schools. I'm writing this in a hurry since I have to go, don't know when I'll be back. Hope this helps you a bit. Link to comment https://forums.phpfreaks.com/topic/107733-make-php-remember-your-selected-theme/#findComment-553571 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.