dongwenyou4298 2014-08-29 09:31
浏览 38
已采纳

如果在codeigniter中设置会话,Facebook无法废弃我的网址

I am using addthis for sharing and framework is Code Igniter.

Problem is if in my controller i check session then facebook not able to scrap my url.If i remove session then it is working. So what can i do to working fb sharing with session.

The following code is working:
controller

public function index()
{
     $this->load->view('client/home');
}

if i check session then fb sharing is not working:

public function index()
{
    if(!$this->session->userdata('client_id'))
    {
        redirect('client/login/index', 'refresh');
        exit;
    }
     $this->load->view('client/home');
}

Thanks in advance.

sidenote: i set session when customer login into website. so when customer click on FB sharing button the session is already set.

  • 写回答

1条回答 默认 最新

  • drodsh7940 2014-08-29 09:55
    关注

    Try this modified version of the code:

    public function index()
    {
        if(!$this->session->userdata('client_id') && !strstr( $_SERVER['HTTP_USER_AGENT'], 'facebookexternalhit') )
        {
            redirect('client/login/index', 'refresh');
            exit;
        }
         $this->load->view('client/home');
    }
    

    I've added an condition, which checks to see if the user agent is the Facebook scraper (facebookexternalhit). If the user-agent is not Faecebook, it forces login. (Remember that user-agent can be spoofed). If it detect Facebook, it will load the page and allow Facebook to scrape the content correctly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题