Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/04/2015, 17:38
Avatar de berkeleyPunk
berkeleyPunk
 
Fecha de Ingreso: febrero-2013
Ubicación: México :C
Mensajes: 565
Antigüedad: 11 años, 2 meses
Puntos: 22
Pregunta Cómo configurar x-frame-options?

Hola!

La idea es esta: visualizar un doc.html hallado en un dominio, en un iFrame de otro dominio.

He googleado, y veo que muchos se encuentran con el mismo problema que yo:
Uncaught SecurityError: Blocked a frame with origin "http://pruebas-berkeley.hol.es" from accessing a frame with origin "http://drupal-001.hol.es". Protocols, domains, and ports must match.

Entiendo que X-Frame-Options es un encabezado HTTP. Que tal cosa puede configurarse directamente en el servidor, en config.inc.php (para Apache), para negar/permitir que otros dominios (o incluso el nuestro propio) puedan visualizar nuestro sitio web dentro de iFrames, como Google.

No hago mis pruebas en servidores dedicados, así que no tengo acceso al config.inc.php.

Así voy, hasta el momento, sin éxito.
En el servidor 1 tengo a padre.php que sólo contiene:
Código PHP:
Ver original
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Title: Este es el documento PADRE</title>
  6. </head>
  7. <body>
  8.     <iframe src="http://pruebas-berkeley.hol.es/hijo.php"></iframe>
  9. </body>
  10. </html>

En el servidor 2 tengo a hijo.php que contiene:
Código HTML:
Ver original
  1. <!DOCTYPE html>
  2.     <meta charset="UTF-8">
  3.     <title>Title: Este documento está dentro de un iFrame</title>
  4. </head>
  5.     <a href="javascript:window.location.href=('http://www.facebook.com/share.php?u='+dir2+'&t='+tit2+'')" target="_blank">Compartir en Facebook</a>
  6.  
  7.     <script type="text/javascript">
  8.         var dir  = window.document.URL;
  9.         var dir2 = encodeURIComponent(dir);
  10.         var tit  = window.document.title;
  11.         var tit2 = encodeURIComponent(tit);
  12.     </script>
  13. </body>
  14. </html>

Como verán, pongo un link encargado de compartir en Facebook el documento actual (la idea es que, si logro arreglar lo de X-Frame-Options, dicho link comparta el sitio del dominio PADRE).

Ahora bien, justo arriba de <!DOCTYPE html> en padre.php, pongo:
Código PHP:
Ver original
  1. <?php header('X-Frame-Options: ALLOW-FROM http://pruebas-berkeley.hol.es'); ?>
Pero Chrome me sigue diciendo que 'X-Frame-Options' está configurado en 'DENY'.

He puesto también estas reglas (una a la vez) en el HTACCESS del servidor PADRE, sólo para ver si funciona el cambio de DENY a SAMEORIGIN:
Código htaccess:
Ver original
  1. Header append X-FRAME-OPTIONS "SAMEORIGIN"
  2. Header set X-Frame-Options SAMEORIGIN
Pero Chrome sigue diciendo que 'X-Frame-Options' está configurado en 'DENY'.


Imagino que tendría mayores posibilidades de arreglar mi problema si tuviera yo acceso al config.inc.php. Pero como hago mis pruebas en servidores gratuitos, ¿de plano estoy perdido? ¿No hay forma de hacer que funcione si se trata de servidores compartidos, gratuitos o no?


Saludos!

Última edición por berkeleyPunk; 26/04/2015 a las 17:44