...

View Full Version : php color changer - need help hiding "...?color=hexcode" in the url



AshleyQuick
03-31-2004, 10:20 PM
This script works nicely. I just wish there was a way in which you could hide the "...?color=hexcode" that you see in the url. I just don't want the user to think about changing the hex values in the url hoping it will change the colors. Is there an easy way to accomplish this?

*Note - I used the full url in the img src so you can view the images.


<?php
$color = !isset($_GET['color']) ? '82CA9C' : $_GET['color'];
?>

<head>
<title></title>

<link rel="stylesheet" href="css/global.css" type="text/css" />
</head>

<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" marginheight="0" marginwidth="0">
<table bgcolor="<?php print $color;?>" class="main" height="100%">
<tr>
<td height="99%"><br>&nbsp;</td>
</tr>
<tr valign="bottom">
<td bgcolor="#ffffff" height="16"><br /><br />
&nbsp;Choose color scheme:<br /><br />
&nbsp;<a href="<?php echo $_SERVER[PHP_SELF];?>?color=FBAF5D"><img alt="orange" border="0" width="24" height="16" src="http://mywebpages.comcast.net/maxpixel/dev/phpcolorswitcher/art/FBAF5D.gif" /></a>&nbsp;
<a href="<?php echo $_SERVER[PHP_SELF];?>?color=448CCB"><img alt="blue" border="0" width="24" height="16" src="http://mywebpages.comcast.net/maxpixel/dev/phpcolorswitcher/art/448CCB.gif" /></a>&nbsp;
<a href="<?php echo $_SERVER[PHP_SELF];?>?color=A186BE"><img alt="purple" border="0" width="24" height="16" src="http://mywebpages.comcast.net/maxpixel/dev/phpcolorswitcher/art/A186BE.gif" /></a>&nbsp;
<a href="<?php echo $_SERVER[PHP_SELF];?>?color=AB5671"><img alt="magenta" border="0" width="24" height="16" src="http://mywebpages.comcast.net/maxpixel/dev/phpcolorswitcher/art/AB5671.gif" /></a>&nbsp;
<a href="<?php echo $_SERVER[PHP_SELF];?>?color=A67C52"><img alt="brown" border="0" width="24" height="16" src="http://mywebpages.comcast.net/maxpixel/dev/phpcolorswitcher/art/A67C52.gif" /></a>&nbsp;
<a href="<?php echo $_SERVER[PHP_SELF];?>?color=82CA9C"><img alt="green" border="0" width="24" height="16" src="http://mywebpages.comcast.net/maxpixel/dev/phpcolorswitcher/art/82CA9C.gif" /></a><br /><img alt="" border="0" width="1" height="25" src="art/spacer.gif" /></td>
</tr>
</table>
</body>
</html>

sidney
03-31-2004, 10:41 PM
you could make your individaul links forms

and use $_POST instead of $_GET

eg


<form action="<?php echo $_SERVER[PHP_SELF];?>" method="post"><input name="color" type="hidden" value="FBAF5D">
<INPUT TYPE="image" SRC="http://mywebpages.comcast.net/maxpixel/dev/phpcolorswitcher/art/FBAF5D.gif" alt="orange"
width="16" height="24" BORDER="0" NAME="Submit"></form>

AshleyQuick
04-01-2004, 07:26 AM
Very nice! Great job once again Sidney!

Is it possible to modify this so that the last color you chose is remembered for subsequent visits? Picky me! :)


<?php
$color = !isset($_POST['color']) ? '82CA9C' : $_POST['color'];
?>

<head>
<title></title>

<link rel="stylesheet" href="css/global.css" type="text/css" />
</head>

<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" marginheight="0" marginwidth="0">
<table bgcolor="<?php print $color;?>" class="main" height="100%">
<tr>
<td height="99%"><br>&nbsp;</td>
</tr>
<tr valign="bottom">
<td bgcolor="#ffffff" height="16"><br /><br />
&nbsp;Choose color scheme:<br /><br />
<table>
<tr>
<form action="<?php echo $_SERVER[PHP_SELF];?>" method="post">
<td><input name="color" type="hidden" value="FBAF5D">
<input type="image" SRC="art/FBAF5D.gif" alt="orange" width="24" height="16" border="0" name="Submit">&nbsp;</td>
</form>
<form action="<?php echo $_SERVER[PHP_SELF];?>" method="post">
<td><input name="color" type="hidden" value="448CCB">
<input type="image" SRC="art/448CCB.gif" alt="blue" width="24" height="16" border="0" name="Submit">&nbsp;</td>
</form>
<form action="<?php echo $_SERVER[PHP_SELF];?>" method="post">
<td><input name="color" type="hidden" value="A186BE">
<input type="image" SRC="art/A186BE.gif" alt="purple" width="24" height="16" border="0" name="Submit">&nbsp;</td>
</form>
<form action="<?php echo $_SERVER[PHP_SELF];?>" method="post">
<td><input name="color" type="hidden" value="AB5671">
<input type="image" SRC="art/AB5671.gif" alt="magenta" width="24" height="16" border="0" name="Submit">&nbsp;</td>
</form>
<form action="<?php echo $_SERVER[PHP_SELF];?>" method="post">
<td><input name="color" type="hidden" value="A67C52">
<input type="image" SRC="art/A67C52.gif" alt="brown" width="24" height="16" border="0" name="Submit">&nbsp;</td>
</form>
<form action="<?php echo $_SERVER[PHP_SELF];?>" method="post">
<td><input name="color" type="hidden" value="82CA9C">
<input type="image" SRC="art/82CA9C.gif" alt="brown" width="24" height="16" border="0" name="Submit">&nbsp;</td>
</form>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

raf
04-01-2004, 08:24 AM
changing the posted value is about just as easy as changing the querystring attribute, so i don't quite see the improvement.
I would create an array with the actual colourvalues, and then just add the elements key to the querystring.

like

$array_colour=array('448CCB', 'A186BE', 'AB5671', 'A67C52', '82CA9C');

and then your links or posted value look like

...?c=0
...?c=1
...

and you get the desired colour with

$colour[$_GET['c']]

This way, if they change the querystring, they just get another valid colour or none at all. You could check in advance if the key exists and display an errormessage if not found.


$user_colour_key=$_GET['c']; // or $_POST['c']
if (array_key_exists($user_colour, $array_colour)) {
$user_colour=$array_colour[$user_colour_key];
//or if you need the value on the following pages as well
//$_SESSION['user_colour']=$array_colour[$user_colour_key];
}else{
die ('Don not change the querystringvalues. Your session is destroyed/IP logged / ...');
}


If you are realy paranoid or if this colourscheme is such a real big thing for you, then you could add an encoded keyvalue to the querystring, and decode it again to set the $user_colour_key

<edit>
By using an array, you could also dynamically build the links or buttons or whatever, with a


foreach($array_colour as $key=>$value){
echo '<a href"blabla?c=' . $key . '" ...';
}

loop



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum