|
|
|
|
![]() ![]() |
Sep 10 2007, 05:46 PM
Post
#1
|
|
|
Neurotical Squirrel ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 579 Joined: 4-November 04 From: Novi Sad, Vojvodina Member No.: 2,127 |
Ever since I connected a program I made in Visual Basic to MySQL database, I had an idea to create some sort of a status page... And I did that, where I updated my connection status every 60 seconds, updated my Winamp playlist, and several other interesting things... Then, I figured I could create an image, and display all that info, and show it on forums, as a signature...
And I made a great PHP script, that look real fancy, and does the job perfectly... So, I was adding the reference to http://status.galahad.trap17.com/stat.php to all the forums... BUT (there's always that but) as well as it worked on some forums, on some forums, like here, on Trap17, I couldn't add a link to PHP file, it just didn't work between IMG BBCodes... So, i pondered, and pondered, and couldn't get the solution... So I asked alex7h3pr0gr4m3r here, since he made a sort of a dynamic sig... And he told me the folder.extension trick... Name your folder image.jpg and place index.php inside, and voila, instant dynamic picture... But this solution is not very ellegant one... So, I did a little more digging, and found a great solution, which I will implement on my site... Actualy, I'm planing a sort of a system for people to get sigs from my site, and I'll create a public version of Windows application for it... Anyway, here's what I found, and learned... You can use .htaccess file, to control the behaviour of web server in a particular folder... Let's say you have a site called www.signatures.com, and want to have a subdomain called sigs, that would be sigs.signatures.com... And let's say you want your users to be able to show their dynamic signatures in this form: http://sigs.signatures.com/user.jpg ... Now, that works fine, if you add folders manualy, naming them user.jpg, and placing index.php inside, but that's kind of a hassle.. You are running a site that gets let's say 100 new users each day, and you need to have a script that will create folders, files... Too much hassle, and let's not forget it uses disk space... There is an ellegant solution to this, without any bother, and that's .htaccess... What we do, is tell web server to rewrite HTTP requests for certain files... And without furter ado, here's the magic: This goes in .htaccess file, located in root folder for your subdomain sigs (eg. /public_htm/sigs/ would be tha path here on Trap17) CODE RewriteEngine on RewriteBase / RewriteRule ^(.+).jpg http://sigs.signatures.com/signature.php\?user\=$1 [NC,L] RewriteRule ^(.*).jpg http://www.signatures.com/ [R=permanent,NC,L] Now, the line CODE RewriteRule ^(.+).jpg http://sigs.signatures.com/signature.php\?user\=$1 [NC,L] tels web server to redirect silently all requests for files containing one ore mora characters, and have .jpg extension, to the address specified at the end.... Variable at the end of the URL, $1, will be replaced with whatever is entered as a file name, before jpg, in our case it will contain text "user"...NC tells web server that case insensitive match should be performed, and L tells web server to stop matching other rules... This speeds up response times for the web server... Now, when I say silently, that means that location bar in your browser will not reflect the change in URL, that is, if you type http://sigs.signatures.com/user.jpg, that's exactly what location bar will show, not http://sigs.signatures.com/signature.php?user=user... That way, noone knows that any redirection is performed.... Second line CODE RewriteRule ^(.*).jpg http://www.signatures.com/ [R,NC,L] tells web server to redirect blank requests (eg. http://sigs.signatures.com/) to main page of our site, where users can sign up for our service, enquire about our services, or something similar... R=permanent does a redirection, and a location bar in your browser will reflect this change, URL will be changed to http://www.signatures.com/... Now, all you need to do, in that signatures.php, is create a script that will query a database for user name specified in a GET variable "user", and create a dynamic image based on users preferences... If that user doesn't exist, you can display a generic image, advertising your site, or redirecting to main page, and asking a user to register that username... And that's it folks |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 20th July 2008 - 11:48 AM |