Jump to content

Sticky Cookies


rinz

Recommended Posts

Hi Guys!

 

I'm a PHP newbie struggling to get this bit of code to work correctly, It's buggy atm.  What I'm trying to do is have 2 cookies one which stores the value of either of yellowBlack blackYellow default or textonly (for changing CSS) and the other has text size small, medium and large (changing text size). 

 

Using the current code, when I try to re-size the text it defaults to the yellowBlack once I've moved from the default layout the other forms buttons become unclickable.

 

Any help appreciated its racking my brains to pieces.... heres the cookie code

 

<?php

 

//must keep cookie stuff at top of page!

//decide what language to display

$textSize = $_POST["textSize"];

 

if(isset($textSize)) {

setcookie("ling",$textSize,time()-60*60*24*365,"/",".mysite.co.uk",0); //wipe previous cookie

setcookie("ling",$textSize,time()+60*60*24*365,"/",".mysite.co.uk",0);

}

else {  //if user has not changed language

if(isset($_COOKIE['ling'])){

$textSize=$_COOKIE['ling'];

setcookie("ling",$textSize,time()-60*60*24*365,"/",".mysite.co.uk",0); //wipe previous cookie

setcookie("ling",$textSize,time()+60*60*24*365,"/",".mysite.co.uk",0);

}

else { //default - choose browser language

$textSize = ("medium");

setcookie("ling",$textSize,time()+60*60*24*365,"/",".mysite.co.uk",0);

}

}

 

$cssChange = $_POST["cssChange"];

 

if(isset($cssChange)) {

setcookie("ling2",$cssChange,time()-60*60*24*365,"/",".mysite.co.uk",0); //wipe previous cookie

setcookie("ling2",$cssChange,time()+60*60*24*365,"/",".mysite.co.uk",0);

}

else {  //if user has not changed language

if(isset($_COOKIE['ling2'])){

$cssChange=$_COOKIE['ling2'];

setcookie("ling2",$cssChange,time()-60*60*24*365,"/",".mysite.co.uk",0); //wipe previous cookie

setcookie("ling2",$cssChange,time()+60*60*24*365,"/",".mysite.co.uk",0);

}

else {

$cssChange = ("default");

setcookie("ling2",$cssChange,time()+60*60*24*365,"/",".mysite.co.uk",0);

}

}

 

//decide what the 'current page' is.

$cpage = $_SERVER['REQUEST_URI']; //gets the current URI (e.g. /index.php)

?>

 

 

This is the HTML code

 

    <li><a href="/atoz/" accesskey="6" tabindex="2">A to Z</a></li>

    <li><a href="/common/glossary.asp" accesskey="5" tabindex="3">Glossary</a></li>

    <li><a href="/accessibility/" accesskey="0" tabindex="4">Accessibility</a></li>

    <li><form class="textsize" method="post" action="<? print $cpage?>" style="border-bottom: 1px solid #000;">

        <input type="hidden" name="cssChange" id="textonly" value="textonly" /><input type="image" value="textonly" alt="Text Version" class= "textsizebutton" src="/images/<? print $cssChange?>/text-version.gif" /></form></li>

 

    <li><form class="textsize" method="post" action="<? print $cpage?>">

    <input type="hidden" name="cssChange" id="default" value="default" /> <input type="image" value="default" alt="Graphical Layout" class="textsizebutton" src="/images/fullcolour.gif" /> </form></li>

   

    <li><form class="textsize" method="post" action="<? print $cpage?>">

    <input type="hidden" name="cssChange" id="yellowBlack" value="yellowBlack" /> <input type="image" value="yellowBlack" alt="Black on Yellow" class="textsizebutton" src="/images/blackonyell.gif" /> </form></li>

   

    <li><form class="textsize" method="post" action="<? print $cpage?>">

    <input type="hidden" name="cssChange" id="blackYellow" value="blackYellow" /> <input type="image" value="blackYellow" alt="Yellow on Black" class="textsizebutton" src="/images/yellonblack.gif" /> </form></li>

   

    <li><a href="mailto:?subject=http://www.odi.gov.uk<? print $cpage?>"><img src="/images/<? print $cssChange?>/send-to-friend.gif" alt="Send to a Friend" width="16" height="14" /></a></li>

   

    <li><a href="JavaScript:window.print();"><img src="/images/<? print $cssChange?>/print-this-page.gif" width="16" height="14" alt="print this page" /></a></li>

   

    <li><form class="cssChange" method="post" action="<? print $cpage?>">

        <input type="hidden" name="textSize" id="small" value="small" /><input type="image" value="small" alt="Normal" class= "textsizebutton" src="/images/<? print $cssChange?>/a-small.gif" /></form></li>

   

    <li><form class="cssChange" method="post" action="<? print $cpage?>">

    <input type="hidden" name="textSize" id="medium" value="medium" /> <input type="image" value="medium" alt="Larger" class="textsizebutton" src="/images/<? print $cssChange?>/a-medium.gif" /> </form></li>

   

    <li><form class="cssChange" method="post" action="<? print $cpage?>">

    <input type="hidden" name="textSize" id="large" value="large" /> <input type="image" value="large" alt="Largest" class="textsizebutton" src="/images/<? print $cssChange?>/a-large.gif" /> </form></li>

 

</ul>

</div>

 

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.