HighDots Forums  

hide elements on page based on cookie

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss hide elements on page based on cookie in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
gareth
 
Posts: n/a

Default Re: hide elements on page based on cookie - 07-21-2004 , 08:23 AM






The problem is your using strlen() ie

<?php if(strlen($_COOKIE['levelCookie']) == 2) { ?>

strlen() gets the length of a string, in this case the length of
"leveCookie", which will always be 1 for a number between 1 and 9

You just need to remove strlen, ie use

if($_COOKIE['levelCookie'] == 1){

} elseif($_COOKIE['levelCookie'] ==2){

} elseif($_COOKIE['levelCookie'] == 3){

}


--
Gareth
http://www.garethdp.com/
Buzz inet - http://www.buzzinet.co.uk/

Team Macromedia Volunteer for Dreamweaver MX
Dreamweaver MX Support: http://www.dreamweavermxsupport.com/index.php

PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.
http://www.dreamweavermxsupport.com/extensions/

Co-Author: Dreamweaver MX: Instant Troubleshooter - Apress
Co-Author: Practical Intranet Development - Apress
Co-Author: Dreamweaver MX: Advanced PHP Web Development - Apress
Co-Author: Dreamweaver MX: PHP Web Development - Wrox



Reply With Quote
  #2  
Old   
msa
 
Posts: n/a

Default hide elements on page based on cookie - 07-21-2004 , 09:14 AM






I have three <td> tags that I need to either hide or show, based on access
level defined in a cookie.

the three buttons are:
secure (to show when accessLevel = 1)
sales (to show when accessLevel = 2)
login (to show when there is no cookie)

I have had some success with to following code:

_________________________________
<tr> <?php if(strlen($_COOKIE['levelCookie']) == 1) { ?>

<td height="22" class="menutable"><input name="Submit5292222"
type="button" class="menutext"
onClick="MM_goToURL('parent','http://atricure.com/test/secure/secure.php');r
eturn document.MM_returnValue"
onMouseOver="pviiClassNew(this,'menutextoverdown') "
onMouseOut="pviiClassNew(this,'menutext')" value="secure"></td>
<?php } ?>
</tr>
<tr><?php if(strlen($_COOKIE['levelCookie']) == 2) { ?>

<td height="22" class="menutable"><input name="Submit5292222"
type="button" class="menutext"
onClick="MM_goToURL('parent','http://atricure.com/test/secure/sales.php');re
turn document.MM_returnValue"
onMouseOver="pviiClassNew(this,'menutextoverdown') "
onMouseOut="pviiClassNew(this,'menutext')" value="sales"></td>
<?php } ?></tr>
<tr><?php if(strlen($_COOKIE['levelCookie']) < 1) { ?>
<td class="menutable" height="22">
<form action="<?php echo "$PHP_SELF"; ?>" METHOD="POST"
name="UserLoginForm" id="UserLoginForm">
<table width="145">
<tr>
<td class="menutextsmallleft" colspan="2"><p
class="alertText"><br><?php echo "$errorMessage"; ?><br>
</p>
<p>Login: <br>
<input name="UserName" type="text" id="UserName"
size="20" value="<?php echo $_COOKIE['acCookie']; ?>">
</p></td>
</tr>
<tr>
<td class="menutextsmallleft"colspan="2"><p>Password: <br>
<input name="Password" type="Password" id="Password"
value="" size="20">
</p></td>
</tr>
<tr>
<td width="100">&nbsp;
</td>
<td width="40"><input name="Login" type="submit"
class="submitButton" id="Login" value="Login"></td>
</tr>
</table>
<input name="action" type="hidden" id="action" value="login">
</form></td><?php } ?>
</tr>

___________________________________

the problem that I am having is that when I change one of the strlen
comparisons, it affects the others......so i get one or two of the
parameters to work and the other doesn't.....i change the third and it
works, but now the other two don't. With the above code, it works for:
login and secure....but not for sales. If i change the sales comparison,
then the other two don't work anymore............yee gads, very frustrating.

Thanks for any help....I am desperate!!



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.