1

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 for me to do this?

4
  • not sure what you are saying, but obviously you can use a $_GET in your css/php script Commented Jul 25, 2011 at 0:09
  • Yes, it should work - check your webserver setup, make sure any redirect you might be using preserves query strings if using GET. Commented Jul 25, 2011 at 0:10
  • $_REQUEST is a variable, not a function. Why not show some of your code? A minimal, meaningful example if possible. Commented Jul 25, 2011 at 0:10
  • Ok, here's the code that calls the assembling script: if($trigger == "songs") { $query = "Select item, color from Table where "; $url = ""; require("assemble.php"); } And here is the beginning of the assemble.php script: $title = $_REQUEST['title']; $titlej = $_REQUEST['titlej']; $titler = $_REQUEST['titler']; Commented Jul 25, 2011 at 0:15

2 Answers 2

2

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');

Sign up to request clarification or add additional context in comments.

2 Comments

This answer is correct, but I would add that the CSS scripts will always be fetched by GET, so $_POST will always be empty in this case. The variable itself will be present, however.
Yes, I have the correct header. In fact, the script always works unless it's on the search results page and calls the script to assemble the SQL code. The assemble script always works when it's called by the search script...
0
<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

1 Comment

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 for me to do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.