Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/12/2012, 03:37
Avatar de rompeguesos
rompeguesos
 
Fecha de Ingreso: marzo-2009
Mensajes: 692
Antigüedad: 15 años, 1 mes
Puntos: 8
Iniciandome con api de facebook y con problemas

Hola gente, esto haciendo para que los usuarios se puedan registrar con facebook, el caso es que el script funciona correctamente ya que lo hace todo bien, incluido el registro con su validacion, pero ahora estoy pillao en lo que creo una tonteria pero no hay modo de dar con el error, el error es que una vez que le doy al boton iniciar ya cuando vuelvo a la pagina se vuelve a lanzar el formulario, si vuelvo se lanza, asi siempre hasta que cierro la sesion de facebook, como podria evitar eso? es decir que solo se lance si le he dado al boton iniciar, os indico el codigo que tengo:

Código PHP:
Ver original
  1. <?php
  2.  
  3. // uses the PHP SDK. Download from https://github.com/facebook/php-sdk
  4. include("src/facebook.php");
  5.  
  6. //
  7. // from the facebook app page
  8. define('YOUR_APP_ID', '');
  9. define('YOUR_APP_SECRET', '');
  10.  
  11. //
  12. // new facebook object to interact with facebook
  13. $facebook = new Facebook(array(
  14.  'appId' => YOUR_APP_ID,
  15.  'secret' => YOUR_APP_SECRET,
  16. ));
  17. //
  18. // if user is logged in on facebook and already gave permissions
  19. // to your app, get his data:
  20. $userId = $facebook->getUser();
  21.  
  22. ?>
  23. <html>
  24. <head>
  25.  <style>body { text-align:center; font-size: 40px }</style>
  26. </head>
  27. <body>
  28. <?php
  29. if ($userId) {
  30.  //
  31.  // already logged? show some data
  32.  $user_profile = $facebook->api('/' + $userId);
  33.  
  34.  
  35. //*** Este es el formulario que se reenvia constantemente ***//
  36. echo "<p>YOU ARE: <strong>". $user_profile['name'] ."</strong><br/>";
  37. echo "Your birth date is: ".$user_profile['birthday']."</p>";
  38.  
  39. echo '<form name="check_out_form" id="idFormulario" action="valida.php" method="post">
  40. <input type="hidden" name="id" value="'.$user_profile["id"].'">
  41. <input type="hidden" name="name" value="'.$user_profile["name"].'">
  42. <input type="hidden" name="first_name" value="'.$user_profile["first_name"].'">
  43. <input type="hidden" name="middle_name" value="'.$user_profile["middle_name"].'">
  44. <input type="hidden" name="last_name" value="'.$user_profile["last_name"].'">
  45. <input type="hidden" name="link" value="'.$user_profile["link"].'">
  46. <input type="hidden" name="username" value="'.$user_profile["username"].'">
  47. <input type="hidden" name="location" value="'.$user_profile["location"]["name"].'">
  48. <input type="hidden" name="gender" value="'.$user_profile["gender"].'">
  49. <input type="hidden" name="email" value="'.$user_profile["email"].'">
  50. <script language="JavaScript">
  51. document.getElementById("idFormulario").submit();
  52. </script>
  53. </form>';
  54.  
  55. } else {
  56.  //
  57.  // use javaascript api to open dialogue and perform
  58.  // the facebook connect process by inserting the fb:login-button
  59.  ?>
  60.  <div id="fb-root"></div>
  61.  <fb:login-button scope='email'></fb:login-button>
  62.  <?php
  63. }
  64. ?>
  65.  <script>
  66.  window.fbAsyncInit = function() {
  67.  FB.init({
  68.  appId : <?=YOUR_APP_ID?>,
  69.  status : true,
  70.  cookie : true,
  71.  xfbml : true,
  72.  oauth : true,
  73.  });
  74.  
  75. FB.Event.subscribe('auth.login', function(response) {
  76.  // ------------------------------------------------------
  77.  // This is the callback if everything is ok
  78.  window.location.reload();
  79.  });
  80.  };
  81.  
  82. (function(d){
  83.  var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
  84.  js = d.createElement('script'); js.id = id; js.async = true;
  85.  js.src = "//connect.facebook.net/es_ES/all.js";
  86.  d.getElementsByTagName('head')[0].appendChild(js);
  87.  }(document));
  88. </script>
  89. </body>
  90. </html>