Jump to content

PHP Cookies and Checkboxes to remember a selection, Help please.


erich1

Recommended Posts

http://www.paddlingabc.com/index_exp.php

 

Basically I have a drop down selection box which users select and then once they select it I load the information they want in the iframe below the box.  It is a convenient way for me to manage a large amount of information that is not useful to everyone.  As you can see it is broken down by city.  I would like there to be a little checkbox below the selection box that when checked remembers the users selection the next time they visit.  Please note only the calgary.php page is created.  I am a little bit new to this so bear with me please.  Thanks so much for taking the time.

 

<li>
<h2>Current Information</h2>

<select onchange="sendValue(this);" name="config">
<option value="http://www.paddlingabc.com/sidebar/pincher.php">Pincher Creek, AB</option>
<option value="http://www.paddlingabc.com/sidebar/lethbridge.php">Lethbridge, AB</option>  
<option value="http://www.paddlingabc.com/sidebar/calgary.php">Calgary, AB</option> 
<option value="http://www.paddlingabc.com/sidebar/reddeer.php">Red Deer, AB</option> 
<option value="http://www.paddlingabc.com/sidebar/edmonton.php">Edmonton, AB</option> 
<option value="http://www.paddlingabc.com/sidebar/banff.php">Banff, AB</option> 
<option value="http://www.paddlingabc.com/sidebar/canmore.php">Canmore, AB</option>
<option value="http://www.paddlingabc.com/sidebar/jasper.php">Jasper, AB</option>
<option value="http://www.paddlingabc.com/sidebar/golden.php">Golden, BC</option>
<option value="http://www.paddlingabc.com/sidebar/invermere.php">Invermere, BC</option>
<option value="http://www.paddlingabc.com/sidebar/revelstoke.php">Revelstoke, BC</option>
<option value="http://www.paddlingabc.com/sidebar/fernie.php">Fernie, BC</option>
<option value="http://www.paddlingabc.com/sidebar/play.php">Popular Playboating Runs</option>
<option value="http://www.paddlingabc.com/sidebar/creeks.php">Popular Creeking Runs</option>
</select> 


<script type="text/javascript"> 
function sendValue(myObj){ 
newLocation = myObj.options[myObj.selectedIndex].value; 
document.getElementById('theFrame').src = newLocation; 
} 
</script>


<iframe id="theFrame" name="iframe" src="http://www.paddlingabc.com/sidebar/calgary.php" scrolling="no" align="top" height="600" width="220" frameborder="0"></iframe>
</li>

Link to comment
Share on other sites

Few things you could do here. $_SESSION vars are handy but the problem with them is the fact that after the browser closes, all values within the superglobal are reset and the var is empty. setcookie is a good way to handle this although I wouldn't rely on it because allot of people have accept cookies set to off.

 

Two suggestions:

1/ Registration system. Then you can save the value to a database and be done with it.

2/ Or you can do an IP type system.

 

There are a few ways of implementing the latter. One is checking the IP against and IP database, there are free versions out there but you will have to look for them for a while. You can get one here by paying a 'small' fee. http://www.ip2location.com/free.aspx Alternatively you can start your own, although this can be quite cumbersome and time consuming.

You can log the persons IP and record their selection in a database, then write a script that checks IP's against database values, if a match then show  the relevant data. etc etc. So many ways, just do some research on google and you ill find an option that suits you.

Link to comment
Share on other sites

Few things you could do here. $_SESSION vars are handy but the problem with them is the fact that after the browser closes, all values within the superglobal are reset and the var is empty. setcookie is a good way to handle this although I wouldn't rely on it because allot of people have accept cookies set to off.

 

Not following you here -- unless you take measures to reconfig this, sessions are facilitated by a cookie. They don't go away until they expire and you can set a long expiration if you want.  For something like form memory I don't think you need to go crazy, but yo can easily set them to expire in 7 days or whatever you want.

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.