Final Fantasy Forums
Go Back   Final Fantasy Forums > Final Fantasy Extreme Discussion Central > 1001001011
Final Fantasy Final Fantasy Forums Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

1001001011 Come to this forum to get technical help, or just discuss technology as a whole; computers, electronics, phones, and other accessories that make us drool.

Reply
 
LinkBack Thread Tools Display Modes
Old 03-21-2007, 11:23 PM   #1 (permalink)
Trav
kill em all
 
Join Date: Mar 2007
Location: Scotland
Age: 24
Posts: 351
Rep Power: 0 Trav is on a distinguished road
Default PHP CSS Query

Hey yo.

I'm working on customisation of mass-produced websites. I've nailed image/sound customisation but I have a problem with CSS customisation.

I'm looking for a User to complete a 'form' in php, which can be used to change CSS values. So in theory a user can change the background colour or text colour whenever they choose.

But I've been looking around and cant seem to find a solution, anybody got any ideas?
Or perhaps a better form of customisation.


Greatly appreciated.
Trav is offline   Reply With Quote
Old 03-22-2007, 05:33 AM   #2 (permalink)
Reynard Struan
Member
 
Reynard Struan's Avatar
 
Join Date: Mar 2007
Location: Moncton, New Brunswick
Age: 28
Posts: 75
Rep Power: 4 Reynard Struan is on a distinguished road
Send a message via AIM to Reynard Struan Send a message via MSN to Reynard Struan Send a message via Yahoo to Reynard Struan
Default

Maybe I'm just dumb (and I'm not really putting a lot of thought into it because it's 5:30AM and I'm tired), but one way I could see to do it is re-code the CSS as inline instead of as an external file and have the form call a PHP script that uses an include statement to dump in the text of the CSS up until the part where you want to change a value, and then throw in an echo $_POST['variableName']; and then another include statement to dump the rest of the page in.

I'm sure there's a more elegant solution, but I'll leave that up to better programmers than I who aren't posting at 5:30AM
__________________

Reynard Struan is offline   Reply With Quote
Old 03-22-2007, 11:39 AM   #3 (permalink)
Kionae
Senior Member
 
Kionae's Avatar
 
Join Date: Feb 2007
Location: Illinois
Age: 27
Posts: 751
Rep Power: 5 Kionae is on a distinguished road
Send a message via MSN to Kionae
Default

I did this same thing for a site once...

You can actually include PHP inside of a CSS file. What I did was I created a form that stored the values for background color, link color, text color, etc. in a database table and then linked up the PHP inside the CSS file to the database and echoed them out in the proper places.

Try googling 'dynamic css'.
__________________


Quote:
Originally Posted by Rhea
I think I have a lesbo crush on Kionae. ^______________^
<3 From Jak.
Kionae is offline   Reply With Quote
Old 03-22-2007, 04:34 PM   #4 (permalink)
Trav
kill em all
 
Join Date: Mar 2007
Location: Scotland
Age: 24
Posts: 351
Rep Power: 0 Trav is on a distinguished road
Default

Thanks very much for the info. Now I know it IS possible so great. Do you still have the files Kionae or some link for demostration?
Trav is offline   Reply With Quote
Old 03-22-2007, 07:36 PM   #5 (permalink)
Kionae
Senior Member
 
Kionae's Avatar
 
Join Date: Feb 2007
Location: Illinois
Age: 27
Posts: 751
Rep Power: 5 Kionae is on a distinguished road
Send a message via MSN to Kionae
Default

Meh... I tried to find the files after I posted. I guess that project never got uploaded to my web site after I graduated and had to clear off of the university servers, because they're not on my portfolio site (though I could have sworn I had them there).

I'll see if I can hunt them down in my class project files when I get home, but I had computer issues a while back, and I'm not sure they made it onto my backup drive or not. I know I lost a few things from my last couple of semesters, and since it's not online like I thought it was, that may have been one of them.
__________________


Quote:
Originally Posted by Rhea
I think I have a lesbo crush on Kionae. ^______________^
<3 From Jak.
Kionae is offline   Reply With Quote
Old 03-22-2007, 09:00 PM   #6 (permalink)
Trav
kill em all
 
Join Date: Mar 2007
Location: Scotland
Age: 24
Posts: 351
Rep Power: 0 Trav is on a distinguished road
Default

OMG I made a partial attempt at this plus looking at references online this is some difficult ****!

<BRICK WALL> anybody care to give me some help?
Trav is offline   Reply With Quote
Old 03-23-2007, 12:39 AM   #7 (permalink)
Kionae
Senior Member
 
Kionae's Avatar
 
Join Date: Feb 2007
Location: Illinois
Age: 27
Posts: 751
Rep Power: 5 Kionae is on a distinguished road
Send a message via MSN to Kionae
Default

Quote:
Originally Posted by Travnia View Post
OMG I made a partial attempt at this plus looking at references online this is some difficult ****!

<BRICK WALL> anybody care to give me some help?
It's easy. It really is. You may just be thinking about it too much and missing the obvious. I know I did when I first tried this.

Set up your html (or php... whatever) file, then for your CSS file, instead of using the .css extension, you use .php... so your call to your external style sheet would look like this:

<link rel="stylesheet" href="test.php" type="text/css" />

Now, in your stylesheet, before you start typing out your CSS rules, since you're using a file extension that doesn't match the content of the file, you have to tell the browser what to do with it. In order to do that, the first line of your stylesheet needs to be:

<?php Header ("Content-type: text/css");?>

You can now use whatever PHP you want in your stylesheet to pull in values.


As an example:

http://www.nlb-creations.com/mystuff/test.html

The HTML (test.html):

Code:
<html>
<head>

<link rel="stylesheet" href="test.php" type="text/css" />

</head>

<body>

The CSS for this page is stored in a php file.

</body>
</html>
And the CSS (test.php):

Code:
<?php Header ("Content-type: text/css");?>

<?php

echo "body {";
echo "background-color: #000000;";
echo "color: #ffffff;";
echo "}";

?>
I hope that's clear... I've been writing php all day at work, so I'm a little loopy. XD
__________________


Quote:
Originally Posted by Rhea
I think I have a lesbo crush on Kionae. ^______________^
<3 From Jak.
Kionae is offline   Reply With Quote
Old 03-23-2007, 07:38 AM   #8 (permalink)
Trav
kill em all
 
Join Date: Mar 2007
Location: Scotland
Age: 24
Posts: 351
Rep Power: 0 Trav is on a distinguished road
Default

Yeah thanks Kionae I had got that far, I got into difficulties with parameters.

Example:
1. A form asking for a colour hex format
2. #FF5A00 entered
3. Background of webpage changed to #FF5A00 colour

This is where I'm getting tripped up.
Trav is offline   Reply With Quote
Old 03-23-2007, 09:24 AM   #9 (permalink)
YopY
BOOM HEADSHOT!
 
YopY's Avatar
 
Join Date: Jan 2007
Age: 22
Posts: 299
Rep Power: 4 YopY is on a distinguished road
Default

I dunno what you're getting at in that last post tbh :/.
YopY is offline   Reply With Quote
Old 03-23-2007, 10:06 AM   #10 (permalink)
Trav
kill em all
 
Join Date: Mar 2007
Location: Scotland
Age: 24
Posts: 351
Rep Power: 0 Trav is on a distinguished road
Default

How so?

1. A form asking for a colour in hex format
2. #FF5A00 string is entered
3. Background of webpage changed to #FF5A00 colour

This is what I want.

But this means I have to write this data to the CSS file, every website has told me to disguise the CSS file as a PHP file.
Trav is offline   Reply With Quote
Old 03-23-2007, 12:24 PM   #11 (permalink)
Kionae
Senior Member
 
Kionae's Avatar
 
Join Date: Feb 2007
Location: Illinois
Age: 27
Posts: 751
Rep Power: 5 Kionae is on a distinguished road
Send a message via MSN to Kionae
Default

Quote:
Originally Posted by Travnia View Post
How so?

1. A form asking for a colour in hex format
2. #FF5A00 string is entered
3. Background of webpage changed to #FF5A00 colour

This is what I want.

But this means I have to write this data to the CSS file, every website has told me to disguise the CSS file as a PHP file.
Hmm... Maybe I'm not understanding the problem. Once you've set up your CSS as a PHP file, doing that should be as simple as taking the value from the form and writing it to a database table, then pulling it back out of the database in the stylesheet, the same way you'd do with any other information stored in a database.

For example, in the css file with the .php extension, do something like this:

Code:
<?php Header ("Content-type: text/css");?>

<?php
	$dbhost = 'localhost';
	$dbname = 'mydatabase';
	$dbuser = 'myusername';
	$dbpass = 'mypassword';

	mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
	mysql_select_db($dbname) or die(mysql_error());

	$result = mysql_query("SELECT * FROM mytable") or die(mysql_error());  
	$row = mysql_fetch_array($result);
?>

body {
	background-color: <?php $row['bgcolor'] ?>
}

Code example plx? Maybe if I saw exactly how you're going about this I could point you toward a solution.

Alternatively, if you don't want to use a database, I think you can pass parameters straight to the CSS file... but you'd still have to find a way to store them somewhere, else they won't be persistant.

Code:
<link rel="stylesheet" href="mystyle.php?&myparam="<? php echo $_POST['myvalue']; ?>" type="text/css" />
__________________


Quote:
Originally Posted by Rhea
I think I have a lesbo crush on Kionae. ^______________^
<3 From Jak.
Kionae is offline   Reply With Quote
Old 03-23-2007, 03:32 PM   #12 (permalink)
Trav
kill em all
 
Join Date: Mar 2007
Location: Scotland
Age: 24
Posts: 351
Rep Power: 0 Trav is on a distinguished road
Default

I've decided to do something more concrete.

A User can submit their CSS file via a form. PHP reads the CSS file and prints the contents in a textarea. Once in the textarea changes can be made and then saved. Writing the results back.

I'll post an example of this real soon once I get home and stuff.
Trav is offline   Reply With Quote
Old 03-23-2007, 04:28 PM   #13 (permalink)
Kionae
Senior Member
 
Kionae's Avatar
 
Join Date: Feb 2007
Location: Illinois
Age: 27
Posts: 751
Rep Power: 5 Kionae is on a distinguished road
Send a message via MSN to Kionae
Default

Quote:
Originally Posted by Travnia View Post
I've decided to do something more concrete.

A User can submit their CSS file via a form. PHP reads the CSS file and prints the contents in a textarea. Once in the textarea changes can be made and then saved. Writing the results back.

I'll post an example of this real soon once I get home and stuff.
That would work, sure, but it's not quite as userfriendly for css-n00bs. And you have the hassle of dealing with writing to files. Using a database simplifies things considerably.

Just for my own clarification, is this what you're trying to do?

http://www.nlb-creations.com/mystuff/form.php
__________________


Quote:
Originally Posted by Rhea
I think I have a lesbo crush on Kionae. ^______________^
<3 From Jak.
Kionae is offline   Reply With Quote
Old 03-23-2007, 04:39 PM   #14 (permalink)
Trav
kill em all
 
Join Date: Mar 2007
Location: Scotland
Age: 24
Posts: 351
Rep Power: 0 Trav is on a distinguished road
Default

Yes! Exactly that!


However I dont think I can use a database, as this has to be a distributed system.

I have a series of website with common functionality.

I've added these diagrams as a general illustration of my website. It is quite a complex system.
Attached Images
File Type: jpg fig1a.jpg (68.4 KB, 2 views)
File Type: jpg fig1b.jpg (70.9 KB, 2 views)
Trav is offline   Reply With Quote
Old 03-23-2007, 04:46 PM   #15 (permalink)
Kionae
Senior Member
 
Kionae's Avatar
 
Join Date: Feb 2007
Location: Illinois
Age: 27
Posts: 751
Rep Power: 5 Kionae is on a distinguished road
Send a message via MSN to Kionae
Default

I don't see why you couldn't use a database. Set it up with fields like:

client_id
bgcolor
color
a-link
a-visited
etc., etc. etc.

That way, each client has their own unique record in the database table containing their custom CSS values. When you need to render a page owned by a specific client, just query the table looking for the client's id number.
__________________


Quote:
Originally Posted by Rhea
I think I have a lesbo crush on Kionae. ^______________^
<3 From Jak.
Kionae is offline   Reply With Quote
Old 03-23-2007, 04:47 PM   #16 (permalink)
Trav
kill em all
 
Join Date: Mar 2007
Location: Scotland
Age: 24
Posts: 351
Rep Power: 0 Trav is on a distinguished road
Default

I think that's solved it. Thanks a lot Kionae you are a star.

Do you have the source code for that demo you posted?
Trav is offline   Reply With Quote
Old 03-23-2007, 04:57 PM   #17 (permalink)
Kionae
Senior Member
 
Kionae's Avatar
 
Join Date: Feb 2007
Location: Illinois
Age: 27
Posts: 751
Rep Power: 5 Kionae is on a distinguished road
Send a message via MSN to Kionae
Default

Sure. Had to change the .html file's extension to attach it.

Not my prettiest code, but meh... what do you want for 10 minutes of effort. XD

Also, I should point out... you don't need to use hex values with this setup (since you're not saving in a file, and don't have to worry about string position when echoing out the contents). Text color values (black, green, navajowhite, etc.) are all valid as well.
Attached Files
File Type: php form.php (1.4 KB, 2 views)
File Type: php test.php (603 Bytes, 1 views)
File Type: txt test.html.txt (178 Bytes, 1 views)
__________________


Quote:
Originally Posted by Rhea
I think I have a lesbo crush on Kionae. ^______________^
<3 From Jak.
Kionae is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:02 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.0.0