Jump to content

Need URGENT help with variables and function


jainischalverma

Recommended Posts

Hi,

 

This is my issue :-

 

I am using a function that can generate color variations from a user-provided color HEX code. For example, someone input #FF0000 as the input, the function can take the color code and another variable for intensity and produce shade of that same color. This is the function :-

 

function hexDarker($hex,$factor = 30)
        {
        $new_hex = '';
        
        $base['R'] = hexdec($hex{0}.$hex{1});
        $base['G'] = hexdec($hex{2}.$hex{3});
        $base['B'] = hexdec($hex{4}.$hex{5});
        
        foreach ($base as $k => $v)
                {
                $amount = $v / 100;
                $amount = round($amount * $factor);
                $new_decimal = $v - $amount;
        
                $new_hex_component = dechex($new_decimal);
                if(strlen($new_hex_component) < 2)
                        { $new_hex_component = "0".$new_hex_component; }
                $new_hex .= $new_hex_component;
                }
                
        return $new_hex;        
        }

 

The function works flawlessly but my problem is this :-

 

I am generating four kinds of values using the same function and storing the values in four variables like this (where $sp_color is the hex value provided) :-

 

<?php
$bgCol = hexDarker($sp_color, 80);
$logocol = hexDarker($sp_color, 60);
$linksCol = hexDarker($sp_color, 40);
$linksCollight = hexDarker($sp_color, 10);
?>

 

Now when I use these values in a website design, they work, but everytime the page changes, the implementation of the colors is a bit delayed. Actually, the calls generate the values every time the pages are changed/refreshed which is causing a slight delay. Because of this, the default or no colors are shown on elements before they get filled with the above generated colors.

 

I need a way of either storing these values and applying some kind of loop to check the change in the variable ($sp_color). I am lost. Please help. caching ??

...Because of this, the default or no colors are shown on elements before they get filled with the above generated colors...

 

That shouldn't be possible in PHP :S

Are you sure the issue is PHP related?

 

PHP doesn't print out some content first and some other content later that should be printed out earlier.

I mean, you shouldn't be able to see the delay like that :S

Arh okay like that.

 

It's because you're calling for a PHP file for your stylesheet element which can be delayed (and stopped) like on this screenshot: http://img138.imageshack.us/img138/2113/cssdelay.jpg

 

To fix this you have to include the css of that PHP file into the main file/page/css...

...or setup a cache for the file in order to speed up the loading of it.

 

<?php
header('Content-type: text/css');
header("Cache-Control: must-revalidate");
$offset = 72000 ;
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
header($ExpStr);
?>

 

Although this kind of caching is time based and won't revalidate on change of data/output.

 

The third option is to create the CSS file with PHP and then revalidate with a function/class on every page load and re-create the CSS file if data has changed.

 

 

edit: The reason IE is "smooth" is because it DOES cache the php file (IE tends to cache everything even when it shouldn't :-/ )

this is a wordpress theme and if you know..... i have made some theme options which can take user input.

 

So, there is a style.php file which renders CSS through php (I hope you get my point).

 

In this style.php file , I have made those 4 calls to the hex function.

 

So, help me how to revalidate with a funcion on every page load -> this is where i am stuck!

The third option is to create the CSS file with PHP and then revalidate with a function/class on every page load and re-create the CSS file if data has changed.

 

edit: The reason IE is "smooth" is because it DOES cache the php file (IE tends to cache everything even when it shouldn't :-/ )

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.