daweefolk Posted December 9, 2007 Share Posted December 9, 2007 I'm wondering if there's a way to use php to give the user the option to pick the background color by clicking a link or something. example: they click on the link titled "red", background color changes to red, they click "blue" and it changes to blue Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 9, 2007 Share Posted December 9, 2007 Yes, there is a way. From you description, it sounds like you want this to immediately happen...which can be done with JavaScript. If you just want them to select a background color and have that color display after they click a submit button, then you can use PHP. Depending on how long you want the color to stick, you can use a database (long lasting), a session (short lasting), or a cookie (in between). You would just store the color using one of those methods. Quote Link to comment Share on other sites More sharing options...
daweefolk Posted December 9, 2007 Author Share Posted December 9, 2007 if it was just a session, would they have to do it again after they change the page? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 9, 2007 Share Posted December 9, 2007 A session ends when they close their browser, so it would last the entire time they are on your site...but next time they came to your site (after the browser was closed) they would have to do it over again. A cookie is almost like a session, but lasts longer. It lasts until the user clears them, or it times out. If you store it in a database, the color will be there forever or until changed. That would only work if you had registered users though, so you could tell who was who. Quote Link to comment Share on other sites More sharing options...
daweefolk Posted December 9, 2007 Author Share Posted December 9, 2007 can you explain (or show me a link that will explain) how to do this in php with a cookie? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 9, 2007 Share Posted December 9, 2007 <?php if (isset($_POST['submit'])){ //get the color they chose $color = $_POST['color']; //set the cookie setcookie("color", $color, time()+86400); /* expire in 24 hours */ } //Set the backround color to whatever they chose, or the default if (isset($_COOKIE['color'])) echo "<body bgcolor='{$_COOKIE['color']}'>"; else echo "<body bgcolor='white'>"; ?> <form method="post"> <select name="color"> <option value="FF8C00">Orange</option> <option value="734A12">Brown</option> </select><br> <input type="submit" name="submit"> </form> If you want more information on cookies and how to use them http://us2.php.net/set_cookie 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.