开发者

Does PHP $_POST/$_GET/$_REQUEST work when script is used as CSS?

If I were to use a PHP script for dynamic CSS (as in, not only writing to the CSS stylesheet, but called by the link line in place of a stylesheet), would $_REQUEST or any similar functions work? I'm having issues and it seems like that's the closest reason why my script keeps malfunctioning - it can do an SQL query perfectly fine when the query is whole and assigned to a variable, but when I attempt to call in a script that uses $_REQUEST and builds a query that way, it fails (despite working perfectly when called in other non-CSS-related scripts).

EDIT: Ok, I've just figured out the main issue. It seems that $_GET works for the link tag, i.e., "href='image.php?page=index'".

However, I want to be able to use $_REQUEST to get something from the URL, like how it is used in non-CSS-related scripts. Is there any way开发者_StackOverflow中文版 for me to do this?


Yes, all those superglobals are available no matter what you use your script for. The interpreter has no knowledge of what type of data the script is going to output. Your error must be somewhere else in the code. Are you outputting the correct header to tell the browser that it is css?

header('Content-Type: text/css');


<link href="css.php?id=1&value=2" rel="text/css">

first make sure that you specify the header in your css.php file

header('Content-Type: text/css');

Now you can have access to the query string:

$id = $_GET['id'];
$value = $_GET['value'];

Example:

body {
<?php
 if ($id == 1) {
   echo "background-color: red";
 }else {
   echo "background-color: yellow";
 }
?>

this should perfectly work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜