PDA

View Full Version : Interesting Sources...



alexjewell
08-21-2006, 07:30 PM
I have a question. Not really a problem. Just something I'm curious about.
I've been noticing some interesting url's for images and stylesheets and scripts, etc....
Instead of being .jpg, .css, .js, etc...
they're query strings.
Like, instead of image.jpg
it's images.php?image=iouhvisudbvsu
or something



http://us.bc.yahoo.com/b?P=31oaEkSOx8a2gYpiRNiwHAD5QTAlkkTqCJIAAp7w&T=15p12rcs0%2fX%3d1156188306%2fE%3d150500014%2fR%3dmail%2fK%3d5%2fV%3d2.1%2fW%3dH%2fY%3dYAHOO%2fF%3d401156405%2fH%3deW12PSIxIiBjb250ZW50PSJ0b3BzdG9yaWVzIiBtYWls PSJ2ZXNwYSI-%2fQ%3d-1%2fS%3d1%2fJ%3d69C98E44&U=13aorjh9g%2fN%3dWGM9E9j8YnU-%2fC%3d289534.9092402.9857338.8799822%2fD%3dHJAVA%2fB%3d3896300


For example, that image on Yahoo!...
Somehow it has to do with databases, yes?
msql, maybe?

Ah, I dunno.
Anyone want to explain HOW they do this?
And, WHY they do this?

Twey
08-21-2006, 07:41 PM
They're simply using PHP to output the content.
PHP isn't limited to outputting HTML; one can use it to create stylesheets, scripts, images, and theoretically anything else, dynamically.

blm126
08-21-2006, 08:10 PM
As to the WHY question. Say you have multiple images on your site. They all look the same except they have a different background color. Using PHP you could modify the color "on the fly". That's just an example but if you apply a little creativity, you can create complex, dynamic images.

Twey
08-21-2006, 08:42 PM
Such as the randomly-generated CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) images one sees on registration forms.

alexjewell
08-25-2006, 07:45 PM
That's amazing. Does anyone have any good resources on how to dynamically output stylesheets, etc?
I'd like to learn how to do this!

Twey
08-25-2006, 08:20 PM
Stylesheets and scripts are plain text, so you generate them the same way you would anything else, but with a different MIME type:
<?php
header('Content-Type: text/javascript');
// Use text/css for CSS, or image/<imagetype>
// for images (e.g. image/png, image/gif, image/jpeg)
echo(
'var myvar = 3;' . "\n" .
'document.write(myvar);' . "\n"
);
?>You can include that into an HTML page, and it will behave just like a static script.

Images are binary, so they're a lot harder. Luckily, most servers have the gd (http://www.boutell.com/gd/) image manipulation library available, which simplifies things considerably. You can find a gd tutorial here (http://www.phpfreaks.com/tutorials/105/0.php).

alexjewell
08-27-2006, 11:27 PM
Ok, so let's say I want to change the text size depending on the number in the url, so something like this, correct?



header('Content-Type: text/css');
$fontsize = $_GET['fontsize'];
echo (

'body{
font-size: '.$fontsize.';');


The quotes aren't making a whole lot of sense to me?
First of all, why're we using the () instead of just a normal echo? And, why are we using single quotes for the text and double quotes for the \n's?

ps - tried the image thing. Didn't work. It says the header information couldn't be modified because headers were already sent? http://flamehtmlstudios.com/projects/gd/image.php
you can see it there

The code I used for that:



header ("Content-type: image/png");
$img_handle = ImageCreate (230, 20) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($img_handle, 0, 10, 10);
$txt_color = ImageColorAllocate ($img_handle, 233, 114, 191);
ImageString ($img_handle, 31, 5, 5, "My first Program with GD", $txt_color);
ImagePng ($img_handle);

Twey
08-27-2006, 11:32 PM
First of all, why're we using the () instead of just a normal echo?Habit. :) You don't have to if you don't want to; it doesn't make a lot of difference either way.
And, why are we using single quotes for the text and double quotes for the \n's?Single quotes are marginally faster to parse, so they should be used wherever possible, but they won't convert the \n into a newline, so we use double quotes for that.
so let's say I want to change the text size depending on the number in the url, so something like this, correct?You might want to add on the missing end brace for that block. Also, if you really are expecting a
number in the urlyou'll have to specify units as well.

alexjewell
08-27-2006, 11:38 PM
Oh yes, forgot the "em" for the font. oops.

Anyway:

tried the image thing. Didn't work. It says the header information couldn't be modified because headers were already sent? http://flamehtmlstudios.com/projects/gd/image.php
you can see it there

The code I used for that:



header ("Content-type: image/png");
$img_handle = ImageCreate (230, 20) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($img_handle, 0, 10, 10);
$txt_color = ImageColorAllocate ($img_handle, 233, 114, 191);
ImageString ($img_handle, 31, 5, 5, "My first Program with GD", $txt_color);
ImagePng ($img_handle);

blm126
08-27-2006, 11:51 PM
your server does not support GD

Twey
08-27-2006, 11:52 PM
The first error:
Warning: Cannot modify header information - headers already sent by (output started at d:\webspace\ADMIN\flamehtmlstudios.com\WWW\projects\gd\image.php:1) in d:\webspace\ADMIN\flamehtmlstudios.com\WWW\projects\gd\image.php on line 2is caused by whitespace before the opening <?php delimiter. The second is caused by not having gd installed. :)

mburt, those look exactly the same. :)

alexjewell
08-28-2006, 12:00 AM
Well, now I'm getting a totally different error:

http://flamehtmlstudios.com/projects/gd/image.php

It's saying it can't be displayed because it has errors.

If this is because I don't have gd installed...
Then...
Uh....
Uh oh.
I'd have to contact my shared hosting provider...

Twey
08-28-2006, 12:04 AM
Yeah, it's outputting that same second error, which, due to the content type, is being read by the browser as image data. Obviously, for image data, it's badly formed.

alexjewell
08-28-2006, 12:05 AM
Oh well
Let's hope they can install GD for me for free.
:/

Thanks for all your help guys.

blm126
08-28-2006, 12:09 AM
You might be able to do it yourself...If your host has dl (http://us2.php.net/dl) enabled that is.