douwayuan3063 2015-05-31 11:35
浏览 34
已采纳

仅允许来自特定网址的请求

I've made a CSS template which I can sell. The css is hosted on my server. I only want site's who paid to have access to this file, so I thought of a php file which echo's the css, only if the url exists in an array.

<?php

header("Content-type: text/css");

$allowedUrls = ['google.com', 'facebook.com'];

$thisURL = "http://urlfromrequester.com"; //???
$thisURL = str_ireplace('www.', '', $thisURL);
$thisURL = (parse_url($thisURL, PHP_URL_HOST));

foreach ($allowedUrls as $url) {
    if ($url == $thisURL) {
        $css = file_get_contents('theCSSFile.css');
    } else {
        $css = file_get_contents('FileWithLinkToBuyPage.css');
    }
}

echo($css);

This is a safe way to only print the css when the host bought the css file. But how can I get the URL of the requester?

People who buy this file will use it like this: <link rel="stylesheet" type="text/css" href="http://domain.com/checkLicence.php">

Thanks

  • 写回答

1条回答 默认 最新

  • doujuegai8830 2015-05-31 11:43
    关注

    You can use:

    $_SERVER['HTTP_REFERER'];
    

    Take into consider though, that the referral address is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

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

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站