Page 1 of 1

how would I do this?

Posted: Fri Mar 19, 2004 4:21 am
by Bifta
This is probably easy but I have no idea how to do it.

I want to be able to use a URL string, e.g. http://www.mysite.com/index.php?cssfile=customer1

it'll then somehow find a CSS file called "customer1.css" and incorporate it into the page, this'll be used for several customers who'll just be given different urls ending in (e.g.) cssfile=customer2 or cssfile=customer3 etc. I'll be manually uploading the relevant CSS files in the same directory so I just need to find some way of incorporating them based on the URL.

Any help is appreciated

Thanks

Posted: Fri Mar 19, 2004 5:58 am
by twigletmac
You can get the value of the cssfile variable from the $_GET array, to get this value and set it to a default if it doesn't exist you could do:

Code: Select all

// first get rid of any extra spaces that have been added to the URL
// query string variables
foreach ($_GET as $key => $value) {
    $_GET[$key] = trim($value);
}

// now check whether there is a value for cssfile and if not set a default
if (!empty($_GET['cssfile']) {
    $cssfile = $_GET['cssfile'];
} else {
    $cssfile = 'customer1';
}
Then you'll have a variable in the script called $cssfile which you can use when writing the HTML to include the CSS file. You may want to also include a bit of script that checks that the file exists (in case the user modifies the querystring). You can use the [php_man]file_exists[/php_man]() function to do this.

Mac