Jump to content

giving user control?


daweefolk

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.