Jump to content

Change the URL to hide all signes of PHP


Kairu

Recommended Posts

Cant quite explain it in the topic I know.

Alright, what I have so far is an image which is called with a URL "http://www.urlofsite.com/dir/image.jpeg?id=1", where the .jpeg extension is treated as PHP. My question is this: Is it possible to make the URL required to access the image properly, something like "http://www.urlofsite.com/dir/images/1.jpeg" Thus removing any indication that it is not a real .jpeg?

Any help is appreciated. Thanks!
Link to comment
Share on other sites

if you're running apache,  you can use .htaccess to "rewrite" the filename to a php file...

the following code will basically rewrite 1.jpeg to index.php?page=1
[code]DirectoryIndex index.php
ReWriteEngine On
RewriteRule ^/?([^/]*)\.jpeg$ ./index.php?page=$1 [L,NS]
[/code]

google search for "htaccess mod rewrite"
Link to comment
Share on other sites

I cant quite figure this out. I went over multiple documents last night on htaccess rewrites, but I cant seem to get it working.

I don't have the htaccess file handy, but from memory it's something like this....

[code]Options +FollowSymlinks
RewriteEngine on
RewriteRule ^images/(.+).jpeg image.jpeg?id=$1 [nc][/code]

Would it make a difference that the htaccess file is in the main directory with the image.jpeg?
Link to comment
Share on other sites

I still dont quite get it... and that code isnt working.....

Could someone explain it or show me?

If it means anything, the file is in the main directory, but I want to make it seem like it is in a folder, and I need it to appear as [#].jpeg.

So a rewrite from.... http://url.com/image.jpeg?id=1 ....to.... http://url.com/images/1.jpeg
Link to comment
Share on other sites

Thank you! This has been very helpful! One last question though.... Is it possible to deny access to "image.php" while still being able to call it through the .htaccess file? I know nothing of .htaccess.... I guess that will be the next thing I teach myself after php.
Link to comment
Share on other sites

Two ideas:

1. You could program your PHP file to deny all requests for anything that doesn't have a referrer -- however not all browsers send a referrer when they request a page. [code=php:0]if(!$_SERVER['HTTP_REFERER']) die();[/code]

2. You could also attempt to rewrite all PHP extension requests to an error page. You might get an internal server error -- but it's worth a try.
[code] RewriteRule ^/?([^/]*)\.php$ ./sorry.html [NC][/code]
Link to comment
Share on other sites

Not so amazingly I have another question.... I tried this, and it came up with a server error. Is it because of the first decimal?

[code]Options +FollowSymLinks
DirectoryIndex index.jpeg
RewriteEngine On
RewriteRule ^([^/]*)\.([^/]*)$ /images/image.$2.php?id=$1 [NC][/code]

I want to be able to output into the four main formats, being chosen by the extension placed at the end of the called URL.
Link to comment
Share on other sites

Ah! Remove the proceeding slash... This is actually quite an ingenious way to hide the fact that I'm using PHP by the way.

Asa you can see from above, I took a different approach and added a directory before the file. Now I'm going to have to find a way to have it output a plain text 404 error if they try any extensions or id's that do not exist....

Question. Does the running PHP still think the URL being called by the browser is the redirected one, or does it think the url is the one shown in the address bar of the user? I want this error message to be as real as possible.....
Link to comment
Share on other sites

as far as I know, PHP has no way of knowing that apache is redirecting. Here's a bit of PHP code that might come in handy, though.

To make sure those headers are right, you might want to "curl -I" a page on your server that doesn't exist. It will give you things like your actual apache and OS versions.

[code=php:0]if(...) {
        header("HTTP/1.1 404 Not Found");
        header("Date: Tue, 20 Dec 2005 04:23:31 GMT");
        header("Server: Apache/2.0.46 (Red Hat)");
        header("Accept-Ranges: bytes");
        header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
        header("Last-Modified: Mon, 28 Mar 2005 16:41:32 GMT");
        header("ETag: \"5c6e5f-3c3-37676700\"");
        header("Content-Length: 959");
        header("Connection: close");
        header("Content-Type: text/html");
        header("X-Pad: avoid browser bug");
        echo "<HTML>
<HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD>
<BODY>
<H1>Not Found</H1>
The requested document was not found on this server.
<P>
<HR>
<ADDRESS>
Web Server at ".$_SERVER['SERVER_NAME'];
echo "
</ADDRESS>
</BODY>
</HTML>

<!--
  - Unfortunately, Microsoft has added a clever new
  - \"feature\" to Internet Explorer. If the text of
  - an error's message is \"too small\", specifically
  - less than 512 bytes, Internet Explorer returns
  - its own error message. You can turn that off,
  - but it's pretty tricky to find switch called
  - \"smart error messages\". That means, of course,
  - that short error messages are censored by default.
  - IIS always returns error messages that are long
  - enough to make Internet Explorer happy. The
  - workaround is pretty simple: pad the error
  - message with a big comment like this to push it
  - over the five hundred and twelve bytes minimum.
  - Of course, that's exactly what you're reading
  - right now.
-->";
}[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.