douxiong3245 2014-10-27 05:29
浏览 42

发送推荐网址卷曲

What i want to do is that when the request is made from any server I want to get the referrer url so I can check if this url is allowed to access my file or not, I have some plugins and on update check on admin side they will check versions connecting my site. So, the plugins are registered with clients site.

Here is my curl code sends referrer but I want to send referrer secretly so no one can change my code easily.

public function checkUpdate($task , $product) {

$parameters = array(
                'task' => $task,
                'product' => $product,
                'domain' => $_SERVER['HTTP_HOST']
            );


$curl = curl_init();
$parameters_str = '';

$url = "http://example.com";

foreach ($parameters as $key => $value) {
  $parameters_str .= "$key=$value&";
}

$url .= "?$parameters_str";

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_REFERER, $_SERVER['HTTP_HOST']);

$result = curl_exec($curl);
curl_close($curl);

return $result;
}

I hope you understand me. Or if you have better solution to do this work like check license of my clients then it will be great! Please also let me know if you think the question is not good or not explaining well in comments.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • doufa5001 2014-10-27 06:09
    关注

    If I haven't made any silly mistakes, this should do it:

    Request Side

    public function checkUpdate($task , $product) {
    
    $referral id = 'abcd12345';
    
    //you already had an array of parameters. I just added a referral id parameter. You can then pass  
    //this array as $_POST.
    $parameters = array(
                'task' => $task,
                'product' => $product,
                'domain' => $_SERVER['HTTP_HOST'],
                'ref_id' => $referral id
            );
    
    
    
    
    $url = "http://example.com";
    
    //unsure of any other curl parameters you need.
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
    
    
    $result = curl_exec($curl);
    curl_close($curl);
    
    return $result;
    }
    

    On Server side doing processing. I assume it's in index file of example.com?

    if (isset($_POST['ref_id'])) 
    {
       //do whatever you want with the referral id.
    }
    
    if (isset($_POST['domain'])) 
    {
       //do whatever you want with domain.
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序