Hi all, I'd appreciate your help if anyone can tell me how can I change the css file I want to call in when there's a certain parameter in the url. for example: My site (www.mysite.com) is using style.css I want when someone gets to my site with a parameter in the url (www.mysite.com?id=5) to use style2.css Thanks
Something like this should get the job done, if you place it in the <head></head> tags: (Haven't tested it as I'm not at home). <?php $css_file = htmlspecialchars($_GET['id']); if (($css_file != '') && (is_numeric($css_file))) { switch ($css_file) { case 0: echo "<style>"; break; case 1: echo "<style>"; break; case 2: echo "<style>"; break; } } else { //return default CSS echo "<style>"; } ?> PHP:
You can also simply retrieve the value from the URL and then embed it in the file path, like this: <?php $id = $_GET['id']; ?> <html> <head> <link rel="stylesheet" type="text/css" href="test<?php echo $id ?>.css" /> </head> </html> Code (markup):
cupi that's not secure at all you don't want to use that method the $id must be checked to be a number like Travis did it