Click to See Complete Forum and Search --> : handiling color parameters comming through the link
Salam
02-08-2003, 08:28 PM
Hi, I need to know how I can make a page handle parameters it receives in the link to determine its background and text colors. It should be able to handle a situation where only one of the two parameters is sent. That is all I need and I am not looking for something more complicated than that. Is that doable in html or java script and what is a simple way for me to do it.
So these frour links would open the same page but with different background and text colors (page does not exist):
http://www.xyxyxy.com/page.htm?bgcolor_var=F7EBE7&fgcolor_var=000000
http://www.xyxyxy.com/page.htm?fgcolor_var=B7A756&bgcolor_var=C8ECC0
http://www.xyxyxy.com/page.htm?bgcolor_var=64C8EC
http://www.xyxyxy.com/page.htm?fgcolor_var=9B7A116
Thanks
Sam
Yes, it is doable in javascript, but if you have a server that supports PHP, that would be a _far_ better option. Got PHP?
Salam
02-08-2003, 08:44 PM
YES, the site is hosted on a server that supports PHP 4.1.1
Sam
Before we go further, I should make sure....Are these pages on your own domain? They need to be in order to do it.
Salam
02-08-2003, 08:52 PM
YES they are and thanks a lot :)
Sam
Ok, give me a bit to work this out, ok?
Salam
02-08-2003, 08:59 PM
Hi, to make sure I gave you a good answer ... this page will be hosted on a server that supports PHP on a domain that I control. On the other hand, the link of this page (that also includes the color parameters) may be used from anywhere. Am I still OK ?
Thanks
Sam
As promised...
<?PHP
$background = "FFFFFF"; # Set default background color, if none was set.
$foreground = "000000"; # Set default font color, if none was set.
#Don't edit below this line
$bgcolor = $background;
$fgcolor = $foreground;
if ($QUERY_STRING != "")
{
$query = $QUERY_STRING;
list($one,$two)= split ("&", $query);
list($placeone,$bgcolor)= split ("=", $one);
if ($placeone == "bgcolor_var")
{
list($placeone2,$fgcolor)= split ("=", $two);
if ($placeone2 != "fgcolor_var")
$fgcolor = $foreground;
}
if ($placeone == "fgcolor_var")
{
$fgcolor = $bgcolor;
$bgcolor = $background;
}
}
echo ("<style type=\"text/css\">\n");
echo ("body {\n");
echo ("background-color: #$bgcolor;\n");
echo ("color: #$fgcolor;\n");
echo ("}\n");
echo ("</style>");
?>Insert that into your <head>
and here is the link code that you need...
<a href="your.php?bgcolor_var=F7EBE7&fgcolor_var=FF0000">specify both</a>
<a href="your.php?bgcolor_var=F7EBE7">specify background</a>
<a href="your.php?fgcolor_var=FF0000">specify foreground</a>
<a href="your.php">use default</a>
Salam
02-08-2003, 11:03 PM
Thank you sooooooooo much
Works very well exept in one case and that is when the fgcolor is positioned in the link before the bgcolor. In this case the the back ground color is always set to white. Like in this case
page.php?fgcolor_var=119876&bgcolor_var=333333
All other cases work fine. My question is wether the code was designed assuming that the bgcolor is the first parameter or order should not matter and this is a small bug in the code. I will look into it if you say its a bug. Sure if that is how its designed then that is good enough. I mainly want to know for my self as I go head and analyze the first php code I see in my life :)
Thanks you very much again
Sam
It was designed that way. I should have mentioned it. Sorry.
Origianlly posted by Salam
I mainly want to know for my self as I go head and analyze the first php code I see in my life :)Glad to see you are going to try to figure out the logic behind it. If you need any help, let me know.
Salam
02-08-2003, 11:21 PM
Hi, actually I am sure that I can change the code so that order is not important ... its like normal programming. My question here is on the style code
echo ("<style type=\"text/css\">\n");
echo ("body {\n");
echo ("background-color: #$bgcolor;\n");
echo ("color: #$fgcolor;\n");
echo ("}\n");
echo ("</style>");
Seems to me (I sure can be wrong) that the style code makes the page assume the text on the page is English letters ... do you know if this is right ?
Thanks again
Sam
I'm not sure I understand what you mean. All that the style code is doing is setting the background and font color...
Salam
02-09-2003, 12:20 AM
Yes, you are right, that code has nothing to do with the language. The contents of the page is Arabic and with the file becomming a PHP file when I load the page I see the Arabic text scrambled and for it to become readable every time after I load the page in the browser I need to select "view" then "encoding" then "windows(Arabic) from the browser menue. Sure this is my problem and will work on it.
Last two questions and I do not want to be more anoying than that. You really got me on my feet with PHP :)
1)
If you know the answer, can I make FrontPage handle PHP files. Now its not and I have to use NotePad instead. FrontPage 2000 help does not say anything about PHP
2)
Do you know of a good on line reference for PHP ? I used to program in Java and C and I think that from this point I can manage doing simple PHP stuff if I have an online reference.
Thanks a lot
Sam
1) Do you mean make FrontPage your default PHP editor?
2) I use http://www.php.net. It's great.
Salam
02-09-2003, 12:34 AM
Hi, thanks for the PHP site. on the other hand, YES I like to be able to make FrontPage be able to edit PHP files. I am a FrontPage user. Question if this is doable or not.
Thanks,
Sam
I don't know if you can make FrontPage edit PHP...I don't think so, sorry. :(
Salam
02-09-2003, 12:48 AM
No problem and thanks sooooooooo much. You made me a great favor.
Sam