2016-05-26 3 views
0

条件付きのPHPをどのように記述して有効にする必要がありますか?
現在のURLに基​​づいて、適切な設定ファイルを含むように、それが書かれている方法では動作しませんが、私は、私のカートのメインのindex.phpを編集した:条件付きのPHPはURLに基​​づいていますか?

( ?以下のファイル全体は、私の版は私が)//

<?php 
session_start(); 

@$cart = $_SESSION["cart"]; 
if ($cart == "") { 
    $cart    = md5(uniqid(rand())); 
    $_SESSION["cart"] = $cart; 
} 
foreach ($_GET as $get_key => $get_value) { 
    if ((preg_match("/\//", $get_value)) || (preg_match("/[\\\]/", $get_value)) || (preg_match("/:/", $get_value))) { 
     eval("unset(\${$get_key});"); 
     die("A hacking attempt has been detected. For security reasons, we're blocking any code execution."); 
    } 
} 
if (file_exists("install.php") && !file_exists("lib/datafiles.php")) { 
    header("location: install.php"); 
    exit; 
} 

// include('config.php'); 
//mine START ROOT INDEX 
$url = $_SERVER['PHP_SELF']; 
if (strstr($url, "?fr")) { 
    include 'configFr.php'; 
} 
if (strstr($url, "?en")) { 
    include 'config.php'; 
} else { 
    include 'config.php'; 
} 
//mine END 

include('lang/' . $langfront . '.php'); 
include('lib/datafiles.php'); 
include('navigation.php'); 
include('stat.php'); 
include('gateways/currency.php'); 
require('lib/version.php'); 
$url  = basename($_SERVER['PHP_SELF']); 
$filename = "db/$ItemsData.dat"; 
if (file_exists($filename)) { 
    $fp = fopen($filename, "r"); 
    $i = 0; 
    while (!feof($fp)) { 
     $offer = fgets($fp, 255); 
     $os = explode('|', $offer); 
     if (@$os[7] == 1) { 
      $SelectOffer[$i] = $offer; 
      $i++; 
     } 
    } 
    fclose($fp); 
} 
if (isset($SelectOffer)) { 
    $nb = count($SelectOffer); 
} else { 
    $nb = ''; 
} 
$show_per_page = 6; 
$nbcol   = 3; 
$nbnav   = 7; 
$sort   = $nb/$show_per_page; 
$sort   = ceil($sort); 
$sort++; 
$nbr_total = $sort; 
if (!isset($_GET['page'])) { 
    $nbr_pages = 1; 
} else { 
    $nbr_pages = $_GET['page']; 
} 
$row  = 0; 
$ShowLigne = ''; 
if ($nb > $show_per_page) { 
    $ShowLigne = $nb - $show_per_page; 
    $navigation = true; 
} 
if (isset($_GET['page'])) { 
    $row  = --$_GET['page'] * $show_per_page; 
    $ShowLigne = $nb - $show_per_page - $row; 
    if ($ShowLigne < 0) { 
     $ShowLigne = 0; 
    } 
} 
function thumbsize($dir, $thumbsize) 
{ 
    if (file_exists($dir)) { 
     $ImgSize  = getimagesize($dir); 
     $width_orig = $ImgSize[0]; 
     $height_orig = $ImgSize[1]; 
     if ($width_orig <= $height_orig) { 
      @$nwidth = $thumbsize * $width_orig/$height_orig; 
      @$nheight = $thumbsize; 
     } else { 
      @$nwidth = $thumbsize; 
      @$nheight = $thumbsize * $height_orig/$width_orig; 
     } 
     $nwidth = intval($nwidth); 
     $nheight = intval($nheight); 
     return array(
      $nwidth, 
      $nheight 
     ); 
    } 
} 
function flash($file) 
{ 
    if (file_exists($file)) { 
     $fp = fopen($file, "r"); 
     $ct = fgets($fp, 255); 
     fclose($fp); 
     @list($idTime, $price, $nprice, $step, $days, $hours) = explode('|', $ct); 
     $targetDate  = $idTime; 
     $actualDate  = time(); 
     $secondsDiff  = $targetDate - $actualDate; 
     $remainingDay  = floor($secondsDiff/60/60/24); 
     $remainingHour = floor(($secondsDiff - ($remainingDay * 60 * 60 * 24))/60/60); 
     $remainingMinutes = floor(($secondsDiff - ($remainingDay * 60 * 60 * 24) - ($remainingHour * 60 * 60))/60); 
     $remainingSeconds = floor(($secondsDiff - ($remainingDay * 60 * 60 * 24) - ($remainingHour * 60 * 60)) - ($remainingMinutes * 60)); 
     $year    = date("Y"); 
     $month   = date("m"); 
     $refresh   = $remainingHour - 1; 
     if ($remainingDay > '0' && $remainingHour == '0') { 
      $refresh = 23; 
     } 
     $coef1  = ($days * 24) + $hours; 
     $coef2  = ($remainingDay * 24) + $remainingHour; 
     $coef  = ($days == '0') ? $hours - $remainingHour : $coef1 - $coef2; 
     $step_price = $price - ($coef * $step); 
     if ($secondsDiff <= '1') { 
      $remainingDay  = 0; 
      $remainingHour = 0; 
      $remainingMinutes = 0; 
      $remainingSeconds = 0; 
      $step_price  = $price; 
      $close   = true; 
     } 
     $sec = mktime(date("H") + $remainingHour, date("i") + $remainingMinutes, date("s") + $remainingSeconds, $month, date("d") + $remainingDay, $year) - time(); 
    } 
    return array(
     $sec, 
     $refresh 
    ); 
} 
if (file_exists('pages/home.dat')) { 
    $content = @file_get_contents("pages/home.dat"); 
    @list($page_id1, $title1, $display1, $link1, $url1, $urlrewriting1, $target1, $meta_keywords1, $meta_description1, $registered1, $description1) = explode('|', $content); 
    $meta_title = $title . "-" . $title1; 
    if ($meta_keywords1 != 'null') { 
     $meta_keywords = $meta_keywords1; 
    } 
    if ($meta_description1 != 'null') { 
     $meta_description = $meta_description1; 
    } 
    if (trim($description1) == 'null') { 
     $description1 = ''; 
    } 
    if (preg_match("#{(.*?)}#si", trim($description1), $matches)) { 
     if (preg_match("#,#", $matches[1])) { 
      list($module, $ModuleFolder) = explode(',', $matches[1]); 
     } else { 
      $module = $matches[1]; 
     } 
     $description1 = preg_replace('#{(.*?)}#si', '|', $description1); 
     list($UpText, $DownText) = explode('|', $description1); 
    } 
} else { 
    $meta_title = $title; 
} 
?> 

<?php 
$include = "lib/display_home.php"; 
$design = $template; 
include("templates/" . $design . "/index.php"); 
?> 

EDIT鉱山ENDを開始して、//の間にある:@SgtAJさんのコメントにおかげで、以下の(まだグラグラが)版が正常に動作します

$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
if (strpos($_SERVER['REQUEST_URI'], '?fr') !== false){include 'configFr.php';} 
else {include 'config.php';} 
+0

私が間違っていると私を修正してください:実際のスクリプトを実行する前に、組み込まれている/必要なファイルが埋め込まれます。つまり、条件付きでファイルを含めることはできません。 – Jeff

+1

初心者の方には、あなたの怒りは驚きです。ええ、私はウンキーと言った。 :)あなたはif、if-elseを持っているので、いずれの方法でも、config.phpがインクルードされます。これは意図的でしたか?また、より良いパフォーマンスを得るために、strstr()の代わりにstrpos()を使用することもできます。そのことについて、あなたは$ _GET ['fr']をテストすることができませんでしたか? @Jeffはhttp://php.net/manual/en/function.include.phpにあるPHPの文書によると、インクルードは関数内にある可能性があるため、インクルードは最初である必要はありません。 –

+0

@SgtAJはい、ドキュメントをチェックしましたが、そのような条件については何も見つかりませんでした。ちょうど最初に処理されたものを含む私の頭の後ろのどこかにそれを持っていました。関数でビーイングすることは引数ですが、私はここで最初のコメントを取り戻します.... – Jeff

答えて

2

あなたはそれをこのように行うことができます:??

if (isset($_GET['fr'])) 
    { include 'configFr.php'; } 
else if (isset($_GET['en'])) 
    { include 'config.php'; } 
else 
    { include 'config.php'; } 

これはFRと専用のためをチェックすると、1つが単一のファイルに関係なく含まれます、両方、またはそれらのどれも存在しません。

関連する問題