Generate dynamic link for a specific download authentication......


/ Published in: PHP
Save to your folder(s)

Bind this particular custom function to a button and name that button as generate your link or any anchor does work, better pass it with a JavaScript's through the action and send the variable or make a ajax call and send it.....or in the action assign it to the php page and call that function then rest u can read from the below code....formatted....


Copy this code and paste it in your HTML
  1. <?php
  2. function Authlin($authcheckin){
  3. $app_id = "YOUR_APP_ID";
  4. $app_secret = "YOUR_APP_SECRET";
  5. $my_url = "YOUR_URL";
  6.  
  7. $code = $authcheckin;
  8.  
  9. if(empty($code)) {
  10. $_SESSION['state'] = md5(uniqid(rand(), TRUE));
  11. $dialog_url = "http://yourcodeurl.com/dialog/oauth?client_id="
  12. . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
  13. . $_SESSION['state'];
  14.  
  15. echo("<script> top.location.href='" . $dialog_url . "'</script>");
  16. }
  17.  
  18. if($_REQUEST['state'] == $_SESSION['state']) {
  19. $token_url = "https://yourcodeurl.com/oauth/access_token?"
  20. . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
  21. . "&client_secret=" . $app_secret . "&code=" . $code;
  22.  
  23. $response = @file_get_contents($token_url);
  24. $params = null;
  25. parse_str($response, $params);
  26.  
  27. $graph_url = "https://yourcodeurl.com/me?access_token="
  28. . $params['access_token'];
  29.  
  30. $user = json_decode(file_get_contents($graph_url));
  31. echo("Hello " . $user->name);
  32. }
  33. else {
  34. echo("The state does not match.Access Denied.");
  35. }
  36. }
  37. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.