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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.