0

i have 1 file named header-guest.php
when you are open this link http://royta.ir/badurl
this code will run:

if(!isset($headerload)){
if(isset($_COOKIE['userid'])){
    include_once('tmp/header.php');
}
else{
    include_once('tmp/header-guest.php');
}
}

and when you click on بازگشت به خانه
with ajax this code will run in #content

if(!isset($headerload)){
if(isset($_COOKIE['userid'])){
    include_once('tmp/header.php');
}
else{
    include_once('tmp/header-guest.php');
    include_once('block/index-visitor.php');
}
}

and in header-guest.php we have this code

<? echo $sitetitle; $headerload = 1;?>

but when you click on badurl and then click on بازگشت به خانه
header-guest.php will run 2 times
how i prevent it?

4

2 回答 2

3

为了防止加载资源两次使用require_onceor include_onceinclude_once如果您碰巧为同一资源放置了两条语句,它将防止资源被加载两次。

于 2013-07-24T07:26:45.303 回答
0

我修复它
我在我的 js 中添加此代码以进行 ajax 加载

$.ajax({
            url: location,
            data: {headerload:555},
            success: function(result) {

所以我在我的页面中添加了这个

if(!isset($headerload) and !isset($_GET['headerload'])){

所以它现在不会加载两次

于 2013-07-24T08:38:54.650 回答