how would I do this?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bifta
Forum Newbie
Posts: 1
Joined: Fri Mar 19, 2004 4:21 am

how would I do this?

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply