PHP Web Host - Quality Web Hosting For All PHP Applications Sign up for PayPal and start accepting credit card payments instantly
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
mrmortimer
New Member
New Member


Joined: Jan 22, 2008
Posts: 13

PostPosted: Wed Jan 23, 2008 10:20 am Reply with quote Back to top

I've written a script to create dynamic signature images for some friends on a gaming forum I've been known to frequent, and currently have the same script placed in several directories (one for each person). I can't help but think that a single instance of the script should be able to serve everyone, but I'm not entirely sure of how to implement this. To illustrate:

This is my personal sig image:
Image

(if you refresh the page, you see that the image changes)
Code:

It's address is http://www.geekcavecreations.com/images/sa/MrMortimer/sig.jpeg


The current setup is (base address)/user/sig.jpeg

what I'm wanting to do is more along the lines of (base address)/user.jpeg
{BTW, I'm already using .htaccess to allow script execution with the .jpeg file extension}

I'm sure that I can use a custom error page to do this, or even mod_rewrite, but I'm sure exactly how to implement this. I think using rewrite would be better, and I'm allowed limited use of .htaccess files, but I'm not sure if my server allows mod_rewrite.

Please bear in mind that all of my skills with PHP/Apache are self-learned, so I have several severe gaps in my knowledge, and am more or less over my head here. However, I'm a fast learner. Very Happy

[edit] As a side note, the forum pages these are posted on don't allow non-image extensions or query strings within the image URL's. thus, the .jpeg extension [/edit]


Last edited by mrmortimer on Fri Feb 01, 2008 8:59 am; edited 1 time in total
View user's profile Send private message
evaders99
Moderator


Joined: Apr 30, 2004
Posts: 2853

PostPosted: Wed Jan 23, 2008 1:40 pm Reply with quote Back to top

This is what I use using mod_rewrite

I have a directory that is just images/

in .htaccess
Code:

RewriteEngine on
RewriteRule ^(.*).jpg           sig.php?charname=$1   


It rewrites all attempts to images/USER.jpg into the form
sig.php?charname=user

As an example
Only registered users can see links on this board!
Get registered or login to the forums!
Only registered users can see links on this board!
Get registered or login to the forums!


Hope that helps what you are doing!
View user's profile Send private message Visit poster's website
mrmortimer
New Member
New Member


Joined: Jan 22, 2008
Posts: 13

PostPosted: Wed Jan 23, 2008 7:21 pm Reply with quote Back to top

I'll give it a try. Thank you greatly.
View user's profile Send private message
mrmortimer
New Member
New Member


Joined: Jan 22, 2008
Posts: 13

PostPosted: Tue Jan 29, 2008 7:26 pm Reply with quote Back to top

Well, it took a while to get back to this, but that did the trick. Thanks again for the assist!
Very Happy
Here's what it looks like:
Image

I've even added some error handling, just in case someone misspells the name.
example:
Image


Last edited by mrmortimer on Thu Jan 31, 2008 4:11 am; edited 1 time in total
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 7487
Location: Arizona

PostPosted: Wed Jan 30, 2008 6:12 am Reply with quote Back to top

mrmortimer, just make sure you "cleanse" that $1 input very carefully before you use it. I haven't a clue how you've coded this, but just make sure no-one can perform a SQL injection, XSS, or file inclusion type exploit on it. Since that is coming in off a URL, which can also be encoded, ensure you can handle that. Bottom line is be careful.
View user's profile Send private message Visit poster's website
mrmortimer
New Member
New Member


Joined: Jan 22, 2008
Posts: 13

PostPosted: Wed Jan 30, 2008 12:42 pm Reply with quote Back to top

Thanks for the tip. I've run it through stripslashes, and the script uses no SQL of any type. Not really sure if there's anything else I need to do to it, since it only looks for the one variable, and that points to a directory elsewhere in the tree. If there's anything else I need to do to "cleanse" the input, I'd dearly love to learn. If needed, I can post the code. It's rather short.

[edit]
Another security measure I've implemented is to change the regex in the .htaccess file to the following:

RewriteRule ^([a-zA-Z]{3,15}).jpg sig.php?charname=$1

I figure that this will eliminate most, if not all, hacking attempts.
[/edit]
View user's profile Send private message
Gremmie
Former Moderator in Good Standing


Joined: Apr 06, 2006
Posts: 2401
Location: Iowa, USA

PostPosted: Wed Jan 30, 2008 6:01 pm Reply with quote Back to top

Hopefully you mean't addslashes(), but since you aren't doing any SQL stuff the chances are lower. Hopefully you aren't doing any evals or executing shell scripts on the server with the input. Smile

Looks good and sounds like you have taken adequate precautions!
View user's profile Send private message
mrmortimer
New Member
New Member


Joined: Jan 22, 2008
Posts: 13

PostPosted: Thu Jan 31, 2008 4:10 am Reply with quote Back to top

Gremmie wrote:
Hopefully you mean't addslashes(), but since you aren't doing any SQL stuff the chances are lower. Hopefully you aren't doing any evals or executing shell scripts on the server with the input. Smile

Looks good and sounds like you have taken adequate precautions!


Actually, that was a "senior" moment. Yup, I did. Silly me. And considering that the .htaccess file is my first line of defense here, only allowing alphabetics of between 3 and 15 characters in length, I don't think there's much they can do to the script. Very Happy
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 7487
Location: Arizona

PostPosted: Thu Jan 31, 2008 5:48 am Reply with quote Back to top

Yes, your edit above showing the rewrite rule makes me feel much, much better, as it keeps them from using "../" as well as any encoded values. Wink

Good job!
View user's profile Send private message Visit poster's website
mrmortimer
New Member
New Member


Joined: Jan 22, 2008
Posts: 13

PostPosted: Thu Jan 31, 2008 8:31 am Reply with quote Back to top

One thing I didn't mention was that, if someone DOES try to hack it using any one of several known methods (SQL injection, file inclusion, etc.), it's picked up by my error handling page, and if it matches certain profiles, it runs through a "hacker alert" routine that tracks the user and emails their ISP with details of the attack. I SO hate malicious hackers!
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 7487
Location: Arizona

PostPosted: Fri Feb 01, 2008 4:39 am Reply with quote Back to top

hhhhmmmm.... sounds to me like you may need to become a contributor to NukeSentinel... I like the sounds of what you have done. Wink
View user's profile Send private message Visit poster's website
mrmortimer
New Member
New Member


Joined: Jan 22, 2008
Posts: 13

PostPosted: Fri Feb 01, 2008 8:47 am Reply with quote Back to top

montego wrote:
hhhhmmmm.... sounds to me like you may need to become a contributor to NukeSentinel... I like the sounds of what you have done. Wink


I don't know about that. Very Happy Considering the gaps in my knowledge of PHP, I've probably re-invented a rather oblong and out off round wheel with my error handling script. I'm reasonably sure that the only reason why many of my scripts work at all is because of all the chickens that so selflessly gave their all in all of those sacrifices. However, if I can help out at all, I'm more than happy to do so. So many people have helped me over the years that I feel it's my responsibility to give back wherever and whenever I can. I just need to learn where best I can assist. Lead me, oh great one. Smile
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2008 by Raven
Proud to be listed at Lobo Links Web Directory

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::

:: fisubice Theme Recoded To 100% W3C CSS & HTML 4.01 Transitional Compliance by Raven and 64bitguy ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum