簡體   English   中英

回聲問題

[英]Issues with echoing

目前,我在下面顯示了此代碼,假設當用戶所在國家/地區為=到美國但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>

你有沒有這樣嘗試過:

<?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回顯。 而且您不必擺弄所有這些引號。 這可能是您的問題所在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM