Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php color changer - need help hiding "...?color=hexcode" in the url

    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 Code:
    <?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>
    Last edited by AshleyQuick; 03-31-2004 at 10:27 PM.

  • #2
    Regular Coder
    Join Date
    Mar 2004
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you could make your individaul links forms

    and use $_POST instead of $_GET

    eg

    PHP Code:
      <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>

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 Code:
    <?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>

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    PHP Code:
    $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
    PHP Code:
    foreach($array_colour as $key=>$value){
       echo 
    '<a href"blabla?c=' $key '" ...';

    loop
    Last edited by raf; 04-01-2004 at 08:29 AM.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •