views:

87

answers:

4

I have a classifieds website, and a partner of us (who runs another classifieds website) need to have access to a file on our server.

The file is called 'partner.php'.

This file simply prints out some information about the classifieds on our site.

So for our partners, they would just need to access "www.domain.com/partner.php?id=1234" to have access to that information.

I am planning to add a hash to the Url, so that outsiders don't have access to the file. But I don't know how to do this...

Is there anybody who could point me in the right direction?

I have been told on phone that I can use a "32 length MD5 string and add it to the URL", but I have really no clue how to start, or what they meant by this?

Anybody know what they mean?

Examples is appreciated.

Thanks

+3  A: 

I am planning to add a hash to the Url, so that outsiders don't have access to the file. But I don't know how to do this...

don't do it this way. A hash is fine for one-time links like E-Mail confirmation, but not for sensitive info. The hash will be present in the user's history, cache and in Proxy protocols; it can be shared accidentally.

You need to look into building proper, login-based authentication.

Some starting points:

Pekka
Hello Pekka. I know this isn't the best method, but I need to know how it works. Could you please explain how the Hash method works?
Camran
@Camran simple: 1. [Generate a random hash](http://stackoverflow.com/questions/2293684/best-way-to-create-a-random-hash) 2. Store it in the classifieds record 3. When a user opens the page, fetch the record that matches the given hash.
Pekka
@Pekka, storing a hash into the database would mean I would have to add another column which I cant currently. Too much work. I think my partner meant something else...
Camran
@Camran you can generate a md5 value out of the classified's ID but that is not really secure... A md5 value combining the classified's ID and another more "random" value like the client's name would be better, but then the client's name must not change. You could then `SELECT * FROM tablename WHERE MD5(CONCAT(id,clientname)) = "12345"` But using a truly random hash would be the best way to go.
Pekka
@Pekka: Btw, forgot to ask, so basically the reason why this hash method is unsafe is because it is delivered fully open in the URL, am I correct? Like domain.com/partner.php?key=555555. Then in the php file I check if the $_GET['key']==555555 ? I am confused now.
Camran
@Camran exactly.
Pekka
A: 

You could use HTTP Authentication, for example via .htaccess

Adding a hash to the URL means that you pass a GET-Parameter to the script and check it when the script starts. If the value is not the expected one, the script can simply die(); or throw some kind of error.

But I'd really NOT recommend the hash-thing, it's a bad idea.

Techpriester
Camran
+2  A: 

Or you can use both the Hash key and IP verification. If your partner is using just one computer/server to access your file you can check the hash key and the users IP address.

$ip = $_SERVER['REMOTE_ADDR'];
infinity
Yes, but how is the hash key verification done? This is what I need to know... could you explain this please?
Camran
For example: http://yoursite.ltd/file.php?pass=[Your Hash/Password here]and in the script you can check if it match, if not just die/exit.It is like a pre-shared key that is known only by you and your partner.
infinity
+1  A: 

Is it possible to use a different approach?

Maybe you can use a .htaccess to only allow access to the file from certain IP addresses.

Check out this page on .htaccess. There is a section called Restricting by IP Address

thearchitect