Welcome Guest ( Log In | Register)



 
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
post 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 smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Multiple Admin Login (php)(3)
  2. Who's Viewing My Site?(11)
  3. Changing A Dynamic Ip(18)
  4. Showing A Users Ip Address In Php(5)
  5. Php Installed Modules Dynamic Reference Tool(4)
  6. Php Dynamic Signatures(9)
  7. How To Make A Sig Rotator(85)
  8. How To: Change Your Website's Index File(18)
  9. Css And Javascript Combined For Dynamic Layout(9)
  10. Yet Another Signature Rotator(7)
  11. Multiple Classes In Html(8)
  12. Putting A Signature On The Forum(35)
  13. Cool Signature Mod(9)
  14. Templating System Using Php Includes(13)
  15. Installing Multiple Os On Your Pc(0)
  1. Making A Dynamic Page On Blogspot(5)
  2. Asking Users To Confirm If They Wish To Leave The Page(5)
  3. Dynamic Signatures - The Real Way To Go(8)
  4. Using The Rewriterule(0)
  5. How To: Have Opera Check C-panel Webmail(1)
  6. How To Group Multiple Sets Of Data In Microsoft Excel 2007(0)
  7. Start Multiple Programs With One Shortcut(15)
  8. How To Make Your Signature Look Really Good!(15)
  9. Opening Nat On Your Xbox - Upnp With Netgear(0)
  10. How To Control Other Users’ Privileges (microsoft Windows Steadystate 2.5)(1)


 



- Lo-Fi Version Time is now: 20th July 2008 - 11:48 AM