IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

Dynamic Signature - Yet Another Way To Do It

, Create dynamic sigs for multiple users using .htaccess and RewriteRule


Rating 5 V
Galahad
no avatar
Neurotical Squirrel
*********
Group: [HOSTED]
Posts: 590
Joined: 4-November 04
From: Novi Sad, Vojvodina
Member No.: 2,127
myCENT:48.25



Post #1 post Sep 10 2007, 05:46 PM
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 smile.gif
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   13 galexcd 3,134 14th August 2007 - 01:25 PM
Last post by: Galahad
No New Posts   6 LuciferStar 11,409 7th November 2004 - 12:40 PM
Last post by: eldeo
No New Posts   12 dreek 9,257 18th September 2004 - 10:28 PM
Last post by: Triple X
No new   23 hatebreed 10,077 4th October 2004 - 01:43 PM
Last post by: odomike
No New Posts 2 rowita 4,269 16th April 2009 - 11:35 AM
Last post by: amrik09
No New Posts 3 finaldesign 12,355 9th December 2004 - 08:46 AM
Last post by: finaldesign
No New Posts   0 thablkpanda 4,925 7th December 2004 - 01:25 AM
Last post by: thablkpanda
No New Posts   7 BoSZ 3,371 19th December 2004 - 09:46 AM
Last post by: nicky1
No New Posts 5 spawn_syxx9 5,024 5th January 2005 - 05:09 AM
Last post by: Zenchi
No New Posts   0 kvarnerexpress 3,660 11th January 2005 - 09:35 PM
Last post by: kvarnerexpress
No New Posts   7 maddog39 3,753 24th February 2005 - 11:01 PM
Last post by: ill
No New Posts 0 karlo 3,178 24th February 2005 - 12:43 PM
Last post by: karlo
No New Posts   6 Benz1435 2,918 16th April 2009 - 11:34 AM
Last post by: amrik09
No New Posts   0 round 2,187 21st March 2005 - 01:54 AM
Last post by: round
No New Posts   3 itsmyard 961 16th April 2009 - 11:39 AM
Last post by: amrik09


 



RSS Open Discussion Time is now: 6th November 2009 - 07:29 AM

Web Hosting Powered by ComputingHost.com.