目前我在下面显示了此代码,当用户所在国家/地区=美国但ID无法正常运行时,可能会显示广告。
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
$location = $details->country;
$details->country;
if($location == 'CA') {
echo '<script type="text/javascript">';
echo "<!-- window['pubs_ad_padid']"; echo '= "1005";';
echo "window['pubs_ad_subid'] = ''; //Insert value to pass through your sub id //-->";
echo "var se = document.createElement('script');";
echo 'se.type = "text/javascript";';
echo "se.src = (document.location.protocol ==="; echo ' "https:" ? "https:" : "http:") + "//d.example.com/js/pub.js";';
echo "document.getElementsByTagName('head')[0].appendChild(se);";
echo "</script>";
}
这里是没有包含所有回声爵士乐的普通代码。
<script type="text/javascript">
<!--
window['pubs_ad_padid'] = "1005";
window['pubs_ad_subid'] = ''; //Insert value to pass through your sub id
//-->
var se = document.createElement('script');
se.type = "text/javascript";
se.src = (document.location.protocol === "https:" ? "https:" : "http:") + "//d.example.com/js/pub.js";
document.getElementsByTagName('head')[0].appendChild(se);
</script>
答案 0 :(得分:1)
您是否尝试过这样:
<?php
if($location == 'CA') {
?>
<script type="text/javascript">
<!--
window['pubs_ad_padid'] = "1005";
window['pubs_ad_subid'] = ''; //Insert value to pass through your sub id
//-->
var se = document.createElement('script');
se.type = "text/javascript";
se.src = (document.location.protocol === "https:" ? "https:" : "http:") + "//d.example.com/js/pub.js";
document.getElementsByTagName('head')[0].appendChild(se);
</script>
<?>}</?>
这是它的基础知识。如果符合条件,那将只会回显脚本。如果需要,它还允许您更轻松地在其中添加另一个PHP回显。而且你不必为所有这些引用弄乱。这可能是你的问题所在。