Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why don't you try sending your API_KEY in custom headers which can be triggered along with php or ajax requests from the client side, that way your API_KEY is not visible in the URL at all, later which can be ripped of from the server using <code>apache_request_headers()</code>, it is a much safer approach, if you are still not satisified you can implement HMAC http authentication, which is damn safe, I bet you.</p> <p><strong>Approach 1:(without HMAC)</strong></p> <p><strong>Client Side:</strong></p> <p><em>using Jquery</em></p> <p><code>$.ajax({</code><br/> <code>url: 'foo/bar',</code><br/> <code>headers: { 'api_key': 'API_KEY' }</code><br/> <code>});</code></p> <p><em>Using PHP</em> </p> <p><code>header('api_key':'API_KEY');</code></p> <p>by adding header with the request the URL can be just </p> <p><code>http://website.com/index.php?movie=Titanic</code></p> <p><strong>On serverside:</strong></p> <p><code>$headers = apache_request_headers();</code><br/> <code>if(isset($headers['api_key']))</code><br/> <code>{</code><br/> <code>// validate your api_key from database</code><br/> <code>}</code><br/></p> <p><strong>Approach 2: (with HMAC)</strong> In this case, there is a slight change, instead of sending API_KEY in your url as query string , you will have to send userID or any other unique identifier, inorder which is related to the api_key in your database.</p> <p><strong>on client side:</strong></p> <p>do HMAC as given in <code>https://code.google.com/p/crypto-js/#HMAC</code></p> <p>or using php function <code>hash_hmac()</code><br> using both methods you will get a hashed value which is a combination of your API_KEY , and your data eg. <code>$hashed_value = hash_hmac('sha1','titanic','API_KEY');</code><br/> <code>header('hash':$hashed_value);</code><br/></p> <p>your url <code>http://website.com/index.php?movie=Titanic&amp;uid=xx</code></p> <p><strong>On server side:</strong></p> <p><code>$headers = apache_request_headers();</code><br/> <code>if(isset($headers['hash']))</code><br/> <code>{</code><br/> <code>// then try to recreate your hash in server, like</code><br/> <code>//using $_GET['uid']= get your API_KEY from DB</code><br/> <code>$api_key = getApiKey($_GET['uid']);</code><br/> <code>$hash = hash_hmac('sha1',$_GET['movie'],$api_key);</code><br/> <code>if($hash==$headers['hash'])</code><br/> <code>{</code><br/> <code>// User authenticated </code> }</p> <p><code>}</code><br/></p> <p>If you go through <a href="http://en.wikipedia.org/wiki/Hash-based_message_authentication_code" rel="nofollow">HMAC</a>, you can figure out its benefits.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload