用户在 Facebook 上的持久标记?

发布于 2025-01-02 00:15:30 字数 419 浏览 0 评论 0原文

我正在为我们的主要电子商务网站设计一个移动网站。由于该网站由不灵活的遗留代码组成,因此我选择查找用户的用户代理字符串并将他们标识为每个页面请求的移动用户。这样就不需要更改 url 结构。到目前为止,这似乎运作良好。

不过,我认为使用这个移动版本可能会很酷,这样用户就可以通过 iframe 浏览我们在 facebook 上的电子商务网站(尺寸非常完美)。但是,与移动浏览器不同,我很难找到一种持久的方法来将用户识别为 Facebook 用户。我知道 facebook 会在第一次通过 iframe 查看页面时发送 $_POST 变量,我可以简单地将其存储在会话变量中并完成它。但出现的问题是,如果用户访问 Facebook,在其会话中被标记为 Facebook 用户,然后访问我们的常规电子商务网站,该怎么办?好吧,他们仍然会被识别为 Facebook 用户并获得 Facebook 版本的服务,这并不理想。

I'm in the middle of designing a mobile site for our main ecommerce site. Because the site is composed of inflexible legacy code I've opted to look up the users user agent string and identify them as a mobile user each page request. That way no changes to the url structure are needed. This seems to be working nicely so far.

However, I thought it may be kind of cool to use this mobile version so that users can browse our ecommerce site on facebook via iframe (the dimensions are perfect). But, unlike the mobile browsers, I am having trouble finding a persistent way to identify the user as a facebook user. I know facebook sends a $_POST variable the first time a page is viewed via iframe, and I could simply just store that in a session variable and be done with it. The issue that arises though is that what if the user visits with facebook, gets marked as a facebook user in their session, then visits our regular ecommerce site? Well, they'd still be identified as a facebook user and get served the facebook version, which is not ideal.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感受沵的脚步 2025-01-09 00:15:30

也许您可以从另一个角度解决问题并测试网站是否从框架加载?

这可以通过 JavaScript 实现:

if (top === self) { 
   //not a frame 
} else { 
   //a frame 
}

Maybe you can tackle the problem for another angle and test if the website is loaded from a frame or not?

This is possible with javascript:

if (top === self) { 
   //not a frame 
} else { 
   //a frame 
}
等风来 2025-01-09 00:15:30

不确定回答我自己的问题是否符合礼仪,但我找到了一个答案,它是 Hassou 的答案和 javascript php 检测脚本的组合。

我修改的脚本来自这里:
http://snippets.bluejon .co.uk/check4-js-and-cookies/check4-js-enabled-v2-phpcode.php

本质上的想法是使用 javascript 提交引用当前 url 的表单,结果告诉您是否启用了 javascript...但是,可以轻松更改此想法,仅当 javascript 在 iframe 中返回 true 时才提交表单。然后,您可以将 $_POST 数据传递到表单中,以便继承 $_POST 数据(仅当在应用程序的显示层中引用 $_POST 数据时才需要)。这是基本的想法:

<?php
/* Include head of your application goes here, this should do whatever
session handling code you have and all processing done to the $_POST variables */

// ~~~~~~Full Url Function - Works With Mod_Rewrite~~~~~~~~~ //
// important thing is function will grab all $_GET vars
function fullurlnav()
{
$fullurlsortnav = 'http';
$script_name = '';
  if(isset($_SERVER['REQUEST_URI']))
  {
  $script_name = $_SERVER['REQUEST_URI'];
  }
  else
  {
  $script_name = $_SERVER['PHP_SELF'];
    if($_SERVER['QUERY_STRING']>' ')
    {
    $script_name .=  '?'.$_SERVER['QUERY_STRING'];
    }
  }

  if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on')
  {
  $fullurlsortnav .=  's';
  }

$fullurlsortnav .=  '://';

  if($_SERVER['SERVER_PORT']!='80')
  {
  $fullurlsortnav .=
  $_SERVER['HTTP_HOST'].':'.$_SERVER['SERVER_PORT'].$script_name;
  }
  else
  {
  $fullurlsortnav .=  $_SERVER['HTTP_HOST'].$script_name;
  }

return $fullurlsortnav;
}
// ~~~~~~~~~~~End Full URL Function~~~~~~~~~ //
?>
<html>
<body>
<?php
// Only run this check if user has been identified as a facebook user in their session
// or if they've been identified via the $_POST['signed_request'], which facebook sends
// upon first request via iframe.
// Doing this removes the check when it's unneeded.
if (!isset($_POST['inIframe']) && ( isset($_SESSION['inIframe']) || isset($_POST['signed_request']) ) )
{   
?>
    <form name="postJs" action="<?php echo fullurlnav(); ?>" method="post">
    <input type="hidden" name="inIframe" value="1">
    <?php
    // Carry over $_POST
    foreach($_POST as $key => $value)
    {
    echo '<input type="hidden" value="'.$value.'" name="'.$key.'" />';
    }
    ?>
    </form>
    <script type="text/javascript">
            <!--
          // If in an iframe
          if (top !== self)
          {
          document.postJs.submit();
          }
        //-->
    </script>
  <?php
}
elseif(isset($_POST['inIframe']) && ( isset($_SESSION['inIframe']) || isset($_POST['signed_request']) ) )
{
$_SESSION['inIframe']=1;
}
else
{
$_SESSION['inIframe']=0;
}

if ($_SESSION['inIframe']== 1){
echo 'IS in an Iframe';
}else{
echo 'IS NOT in an Iframe';
}

// echo out rest of your template code
?>
</body>
</html>

它在页面显示代码输出及其工作原理上有点棘手,但这是我到目前为止的基本想法。从技术上讲,可以将表单生成块与下面的 elseif else 语句分开,并在任何显示输出之前使用代码上方的那些语句,这可能更容易处理。请注意,上面的代码未经测试,只是为具有相同问题的其他人提供基本思路。

Not sure if it's proper etiquette to answer my own question but I found an answer which is a combo of Hassou's answer and a javascript php detection script.

The script I altered is from here:
http://snippets.bluejon.co.uk/check4-js-and-cookies/check4-js-enabled-v2-phpcode.php

Essentially the idea is to use javascript to submit a form referencing the current url, the result tells you if javascript is enabled... However, the idea can easily be altered to submit a form only if javascript returns true for being in an iframe. You can then pass in the $_POST data into the form so that the $_POST data is carried over (only needed if the $_POST data is referenced within the display layer of your application). Here's the basic idea:

<?php
/* Include head of your application goes here, this should do whatever
session handling code you have and all processing done to the $_POST variables */

// ~~~~~~Full Url Function - Works With Mod_Rewrite~~~~~~~~~ //
// important thing is function will grab all $_GET vars
function fullurlnav()
{
$fullurlsortnav = 'http';
$script_name = '';
  if(isset($_SERVER['REQUEST_URI']))
  {
  $script_name = $_SERVER['REQUEST_URI'];
  }
  else
  {
  $script_name = $_SERVER['PHP_SELF'];
    if($_SERVER['QUERY_STRING']>' ')
    {
    $script_name .=  '?'.$_SERVER['QUERY_STRING'];
    }
  }

  if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on')
  {
  $fullurlsortnav .=  's';
  }

$fullurlsortnav .=  '://';

  if($_SERVER['SERVER_PORT']!='80')
  {
  $fullurlsortnav .=
  $_SERVER['HTTP_HOST'].':'.$_SERVER['SERVER_PORT'].$script_name;
  }
  else
  {
  $fullurlsortnav .=  $_SERVER['HTTP_HOST'].$script_name;
  }

return $fullurlsortnav;
}
// ~~~~~~~~~~~End Full URL Function~~~~~~~~~ //
?>
<html>
<body>
<?php
// Only run this check if user has been identified as a facebook user in their session
// or if they've been identified via the $_POST['signed_request'], which facebook sends
// upon first request via iframe.
// Doing this removes the check when it's unneeded.
if (!isset($_POST['inIframe']) && ( isset($_SESSION['inIframe']) || isset($_POST['signed_request']) ) )
{   
?>
    <form name="postJs" action="<?php echo fullurlnav(); ?>" method="post">
    <input type="hidden" name="inIframe" value="1">
    <?php
    // Carry over $_POST
    foreach($_POST as $key => $value)
    {
    echo '<input type="hidden" value="'.$value.'" name="'.$key.'" />';
    }
    ?>
    </form>
    <script type="text/javascript">
            <!--
          // If in an iframe
          if (top !== self)
          {
          document.postJs.submit();
          }
        //-->
    </script>
  <?php
}
elseif(isset($_POST['inIframe']) && ( isset($_SESSION['inIframe']) || isset($_POST['signed_request']) ) )
{
$_SESSION['inIframe']=1;
}
else
{
$_SESSION['inIframe']=0;
}

if ($_SESSION['inIframe']== 1){
echo 'IS in an Iframe';
}else{
echo 'IS NOT in an Iframe';
}

// echo out rest of your template code
?>
</body>
</html>

It gets a little tricky skating around your page display code output and it's workings, but that's the basic idea i have so far. Technically one could separate the form generation block from the elseif else statements below, and use those above your code before any display output, that may be easier to handle. Note that the above code is untested, just given to provide the basic idea for others with the same issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文