php - how prevent include 2 times but if not included before include now -
i have 1 file named header-guest.php
when open link http://royta.ir/badurl
code run:
if(!isset($headerload)){ if(isset($_cookie['userid'])){ include_once('tmp/header.php'); } else{ include_once('tmp/header-guest.php'); } }
and when click on بازگشت به خانه
ajax code 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 have code
<? echo $sitetitle; $headerload = 1;?>
but when click on badurl , click on بازگشت به خانه
header-guest.php run 2 times
how prevent it?
to prevent loading resources twice use require_once
or include_once
. prevent resource being loaded twice if happen put 2 include_once
statements same resource.
Comments
Post a Comment