Jump to content
xisto Community
Sign in to follow this  
Galahad

Dynamic Signature - Yet Another Way To Do It Create dynamic sigs for multiple users using .htaccess and RewriteRule

Recommended Posts

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://forums.xisto.com/no_longer_exists/ to all the forums... BUT (there's always that but) as well as it worked on some forums, on some forums, like here, on Xisto, 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 http://forums.xisto.com/no_longer_exists/,'>http://forums.xisto.com/no_longer_exists/, 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://forums.xisto.com/no_longer_exists/ ... 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 Xisto)

RewriteEngine onRewriteBase /RewriteRule ^(.+).jpg http://sigs.signatures.com/signature.php\?user\=$1 [NC,L]RewriteRule ^(.*).jpg http://forums.xisto.com/no_longer_exists/ [R=permanent,NC,L]

Now, the line
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://forums.xisto.com/no_longer_exists/, that's exactly what location bar will show, not http://forums.xisto.com/no_longer_exists/... That way, noone knows that any redirection is performed....

Second line
RewriteRule ^(.*).jpg http://forums.xisto.com/no_longer_exists/ [R,NC,L]
tells web server to redirect blank requests (eg. http://forums.xisto.com/no_longer_exists/) 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://forums.xisto.com/no_longer_exists/...

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 :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.