473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Disguising a PHP script and parameters as a html page

I'm not quite sure if the answer to my question lies in the Apache or
PHP realm.

If I have a php script running on Apache which outputs a JPEG image
such as http://domain/get_image.php?id=15&size=thumb can I somehow
disguise it as http://domain/image15_thumb.jpg to allow browser
caching? I'm assuming the majority of people's browsers don't cache
images generated from scripts such as PHP? For this reason I would
imagine the solution would have to completely hide the 'real' URL?

On a related note how would I 'disguise'
http://domain/index.php?page=contact as http://domain/contact.htm to
allow indexing of each dynamic page in search engines?

Many thanks
Geoff
Jul 16 '05 #1
5 6128
Geoff Soper wrote:
If I have a php script running on Apache which outputs a JPEG image
such as http://domain/get_image.php?id=15&size=thumb can I somehow
disguise it as http://domain/image15_thumb.jpg to allow browser
caching? I'm assuming the majority of people's browsers don't cache
images generated from scripts such as PHP? For this reason I would
imagine the solution would have to completely hide the 'real' URL?
mod_rewrite works quite nicely for something like this (not tested):

RewriteEngine On
RewriteBase /
RewriteRule ^image([0-9]+)_([^\.]+)\.jpg$ get_image.php?id=$1&size=$2 [L]
On a related note how would I 'disguise'
http://domain/index.php?page=contact as http://domain/contact.htm to
allow indexing of each dynamic page in search engines?


Same type of thing:

RewriteRule ^([^\.]+)\.htm index.php?page=$1 [L]

These statements would go inside your .htaccess file at your document
root. However, you need to be sure that mod_rewrite is enabled, or you
will get HTTP 500 errors.

I don't know about browsers and caching of dynamicly created images, but
one thing to remember is that if you are creating the image every time a
request is made, it will have a different creation or modification date.
Therefore, some browsers may load it no matter what.

As far as search engines indexing pages, I don't think this is going to
be a problem. However, it is better practive to hide the tech behind the
site. That way if you change to say jsp, you don't have to re-submit
your site and start over because you will be able to keep the same URI -
always a major plus.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 16 '05 #2
Geoff Soper wrote:
If I have a php script running on Apache which outputs a JPEG image
such as http://domain/get_image.php?id=15&size=thumb can I somehow
disguise it as http://domain/image15_thumb.jpg to allow browser
caching?


No. The form of the URL does not dictate how a browser should cache the
file, although in some instances, a proxy cache may choose to throw away
cached copies of certain URLs, for instance, anything containing /cgi-bin/
is usually thrown away.

Caching is provided for by ensuring you are sending the correct HTTP headers
along with each response. By default, PHP sends headers that do not allow
caching. This is a decent caching tutorial:

<URL:http://www.mnot.net/cache_docs/>
--
Jim Dabell

Jul 16 '05 #3
ge*****************@alphaworks.co.uk (Geoff Soper) wrote in
news:a2**************************@posting.google.c om:
If I have a php script running on Apache which outputs a JPEG image
such as http://domain/get_image.php?id=15&size=thumb can I somehow
disguise it as http://domain/image15_thumb.jpg to allow browser
caching?


First of all, the "extension" of the URL does not have anything to do
with caching - have a look at the "header" function of PHP to find out
which headers to set to enable caching.

Anyway, if you have PATH_INFO enabled in your Apache configuration you
can simply add something at the end of your URL, like:

http://domain/get_image.php/image15_thumb.jpg

Your script then will find "/image15_thumb.jpg" in
$_SERVER['PATH_INFO'].

If you need it one step further, rename your script to index.php, place
it in it's own subdirectory and you can use such a URL:

http://domain/scriptdir/image15_thumb.jpg

which will be the same as

http://domain/scriptdir/index.php/image15-thumb.jpg

Good luck,
Udo

--
To reply by e-mail, use following address:
udonews AT nova-sys.net
Jul 16 '05 #4
Geoff Soper wrote:

On a related note how would I 'disguise'
http://domain/index.php?page=contact as http://domain/contact.htm to
allow indexing of each dynamic page in search engines?


<shameless_plug>

You can do it in apache with URL rewriting. Just done a site using this
technique, at http://cdnopenhouse.com/

All of the php "called" resides in the root folder. Most of the requests
actually go to the same file, despite appearing as folders, subfolders,
whatever.

If you really want to see some of the rewriting code, I can show you, but there's
a lot of it (it's a big site)
</shameless_plug>

Benefits -
Friendly URLs - people do actually find it easier to know where they
are on a site if the URL contains actual words that reflect it

You can hide the platform to some extent, so that you can rewrite the
site in Perl, ASP, JSP, whatever, without having to give any indication
to the user

Once set up, it's easy to redesign the implementation of the site, since
the "virtual" folder names don't have to relate to an actual folder on the
webserver

You can use it to handle old urls (from an existing site) with a php file,
or even directly call your new php page(s) with the right query parameters
(if the old site had a relatively fixed url/folder/page naming scheme)

You can use it to make files appear to be in folders that they are not.
Disadvantages
If it's a big or complex site, the rewrite rules can become quite complex,
and if you're new to this kind of thing, or to regular expressions, it can be
a bit tricky

With a lot of rewrite rules, the server does have to work a bit harder, especially
if the regexps are complex (the site i mentioned has 200+ rewrite rules, but a lot
of these are to handle mapping 2500 old pages to new ones)

If you're having trouble getting the hang of it, it can be an absolute bitch!

There's a good guide to get you started at

http://httpd.apache.org/docs/misc/rewriteguide.html

HTH!

Matt
Jul 16 '05 #5
Wes Bailey wrote:


Nice site you made there matty. One comment though is that url
rewritting in apache is not for the faint at heart. I have years of
regexp experience and still goof once in a while. Unless you
absolutely have to hide that the application is written in php, I'd
suggest letting the world know you use PHP and be damn proud of it!

wes


Thanks Wes!

To be honest, I don't really like Apache's regexp support, and it doesn't
seem to have symbolic character classes (\d or [[:alpha:]], etc) - also,
it would be good if it could have some extended mechanism to handle the
query string (if only to kill SQL injection attempts outright before even
invoking a script file).

Oh, and the fact that you often have to turn Options +FollowSymlinks on
to get the Rewrite engine working, which is a bit of a twisted situation...

..htaccess rewrite maps would be fantastic - the project I mentioned would
have become a lot easier if I could have used rewrite maps, or used a perl
script to pass off the rewriting, none of which you can do from a .htaccess
file in Apache (and therefore on most clients' servers). I know you could
pass all requests to a script that did a redirect, but that would destroy most
of the benefits of hiding the URLs!

That said, I do genuinely believe that URL rewrites on *everything* is the
best way to go! They do seem to work best with frameworks that handle requests
through one or two central pages; but for me that tends to be the most modular,
structured way to organise a site.

What are everyone else's thoughts on this? I do think it's better not to have
a 124-character query string (JSP session IDs anyone?)... Who else out there
prefers the rewrite route?

Matt

--
Matt Mitchell - AskMeNoQuestions
Dynamic Website Development and Marketing
Jul 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Boris Nikolaevich | last post by:
This is backwards of what I usually want--normally if you have a long-running ASP script, it's a good idea to check to see whether the client is still connected so you can cancel execution. ...
13
by: Al Franz | last post by:
Anyone understand how to pass parameters to a JavaScript. If anyone finds this easy to do maybe they could take a look at my short script on this page and show me how it needs to be changed. ...
1
by: viktor9990 | last post by:
I have a page called CustomerSlides.aspx which contains an iframe(with the source Lookupage.aspx). The iframe page will look continuously in the database to see if a value has changed: if it is...
2
by: Trevor | last post by:
Many pages have URLs like this one http://www.appraisers.com/usa/california/san_bernardino/ instead of long nasty URLs with disgusting query strings and such. Can anybody point me to some place...
7
by: C.Joseph Drayton | last post by:
I have a problem that I am hoping someone can help me with. First let me describe the problem. I have an HTML form that in one field has an onBlur call to a JavaScript function. When you exit the...
7
by: Mariusf | last post by:
I am a novice Perl programmer and need to change a perl script that I use to create web pages with thumbnail images and some text. Currently the script created a web page for each artist / category...
2
by: Jay | last post by:
I have a web app running on the windows CE device. In one of the asp.net pages - it has javascript code. That seems to have a memory leak. When I run the web app - in about one hour, the app hangs....
4
by: happyse27 | last post by:
Hi All, The html page(see item a below) is calling javascript(item b below), but cant work as the page show blank. Not sure if the method of calling is wrong(in terms of default directory) or...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.