2017-04-02 63 views
0

我目前正在和PHP開展一些工作,並接管一個並非由我創建的項目。棘手的事情是,在服務器/ webhotel應用程序工作正常,但在我的本地測試環境(WAMP 3.0.6 64位,PHP 5.6.25,Apache 2.4.23,MySQL 5.7.14)它不起作用。正在輸出錯誤消息通過PHP是:PHP應用程序可以在webhotel上正常工作,但不能在本地服務器上運行(WAMP)

說明:未定義指數:...線110

被引導在該片段:

$bVal += $values[substr(utf8_decode(mb_strtolower($line)),$j,1)];. 

事情是,我已經從服務器複製了所有文件,包括它所依賴的所有文件。我只需做小小的調整(改變php腳本讀取的文本文件),但它甚至不能與原始文件一起工作。在PHP,Apache等平臺版本之間是否有共同的問題?據我所知,XHTTP請求正常運行,我覺得我不應該有這些問題,這可能來自我對PHP的經驗不足。

代碼將在下面發佈,並且預先感謝您甚至可以看看它!

代碼:https://pastebin.com/M6y9rfRa

+0

[PHP的可能重複: 「請注意:未定義的變量」, 「通知:未定義指數」 和「注意事項:Undefined offset「](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – miken32

+0

@ miken32感謝您的回覆。儘管我很欣賞你花時間回答這個問題,但鏈接的文章並沒有解釋爲什麼它能在服務器上運行,而不是在我的本地環境中運行(至少不是我所能理解的),這是真正的問題。如果我錯了,請指出具體的報價。然而,再次感謝您的時間! – DCBN

+0

可能有多種原因,但問題的根本在於'$ values [whatever]'不存在。首先我要檢查的是你已經安裝了多字節功能。同時檢查您嘗試用作索引的值。 – miken32

回答

0

你的代碼改成這樣,看看它是如何去

<script> 
    function doSomething() 
    { 
     var xhttp = new XMLHttpRequest(); 
     xhttp.onreadystatechange = function() 
     { 
      if (xhttp.readyState == 4) 
      { 
       if (xhttp.status == 200) 
        document.getElementById("calContent").innerHTML = xhttp.responseText; 
      } 
     } 
     xhttp.open("GET", "/num/ns.php?number=" + jQuery("#nInput").val() + "$$$" + jQuery('input[name=switcher]:checked').val(), true); 
     xhttp.send(); 
    } 
    function doSomethingElse() 
    { 
     var xhttp = new XMLHttpRequest(); 
     xhttp.onreadystatechange = function() 
     { 
      if (xhttp.readyState == 4) 
      { 
       if (xhttp.status == 200) 
        document.getElementById("calContent").innerHTML = xhttp.responseText; 
      } 
     } 
     xhttp.open("GET", "/num/ns.php?number2=" + jQuery("#nInput2").val() + "$$$" + jQuery('input[name=switcher2]:checked').val(), true); 
     xhttp.send(); 
    } 
</script> 
<style> 
    .calOut { 
     position: relative; 
     float: left; 
     margin-right: 18px; 
    } 
</style> 
<style media="print"> 
    #calContent { display: none; } 
</style> 
<div id="calContent" style="margin-top: 0px; margin-bottom: 50px; color:black;" class="contact_form" > 

<?php 
    $numname = "number"; 
    if (isset($_GET["number"])) { 
     echo "<div><input type='text' id='nInput' name='nInput' value='" . explode("$$$", $_GET["number"])[0] . "' />"; 
     echo "<br /><input type='radio' name='switcher' value='female' "; if (explode("$$$", $_GET["number"])[1] == "female") echo "checked"; echo ">Female&nbsp;&nbsp;"; 
     echo "<input type='radio' name='switcher' value='male' " . (explode("$$$", $_GET["number"])[1] == "male" ? "checked" : "") . ">Male&nbsp;&nbsp;"; 
     echo "<input type='radio' name='switcher' value='last' " . (explode("$$$", $_GET["number"])[1] == "last" ? "checked" : "") . ">Last name&nbsp;&nbsp;"; 
    } 
    else { 
     echo "<div><input placeholder='Enter vibration' type='text' id='nInput' name='nInput' />"; 
     echo "<br /><input type='radio' name='switcher' value='female' checked>Female&nbsp;&nbsp;<input type='radio' name='switcher' value='male' >Male&nbsp;&nbsp;"; 
     echo "<input type='radio' name='switcher' value='last' />Last name"; 
    } 
    echo "<br /><input type='submit' id='nForm' value='Generate names' onclick='doSomething()' class='qbutton' style='margin-bottom: 45px;'/><br /></div>"; 

    if (isset($_GET["number2"])) { 
     echo "<div><input type='text' id='nInput2' name='nInput2' value='" . explode("$$$", $_GET["number2"])[0] . "' />"; 
     echo "<br /><input type='radio' name='switcher2' value='female' "; if (explode("$$$", $_GET["number2"])[1] == "female") echo "checked"; echo ">Female&nbsp;&nbsp;"; 
     echo "<input type='radio' name='switcher2' value='male' " . (explode("$$$", $_GET["number2"])[1] == "male" ? "checked" : "") . ">Male&nbsp;&nbsp;"; 
     echo "<input type='radio' name='switcher2' value='last' " . (explode("$$$", $_GET["number2"])[1] == "last" ? "checked" : "") . ">Last name&nbsp;&nbsp;"; 
     $numname = "number2"; 
    } 
    else { 
     echo "<div><input placeholder='Enter vibration and number, eg. Lisa 17/8' type='text' id='nInput2' name='nInput' />"; 
     echo "<br /><input type='radio' name='switcher2' value='female' checked>Female&nbsp;&nbsp;<input type='radio' name='switcher2' value='male' >Male&nbsp;&nbsp;"; 
     echo "<input type='radio' name='switcher2' value='last' />Last name"; 
    } 

    echo "<br /><input type='submit' id='nForm2' value='Generate names' onclick='doSomethingElse()' class='qbutton' /><br /></div>"; 

    //echo $_SERVER['HTTP_REFERER']; 
    //echo "<br />"; 
    //if ($_SERVER['REMOTE_ADDR'] == "93.176.86.170" || $_SERVER['REMOTE_ADDR'] == "86.52.165.122") 
    // echo $_SERVER['REQUEST_URI']; 

    $values = [ 
     "a" => 1, "i" => 1, "j" => 1, "q" => 1, "y" => 1, "å" => 1, "á" => 1, "à" => 1, 
     "b" => 2, "k" => 2, "r" => 2, 
     "c" => 3, "g" => 3, "l" => 3, "s" => 3, "ç" => 3, 
     "d" => 4, "m" => 4, "t" => 4, 
     "e" => 5, "h" => 5, "n" => 5, "x" => 5, "é" => 5, "è" => 5, "è" => "5", 
     "u" => 6, "v" => 6, "w" => 6, "æ" => 6, 
     "o" => 7, "z" => 7, "ø" => 7, "ô" => 7, "ó" => 7, "ò" => 7, "ö" => 7, 
     "f" => 8, "p" => 8]; 
?> 
<br /> 
<?php 



//ini_set('memory_limit', '2048M'); 
error_reporting(0); 
ini_set("display_errors", 0); 
ini_set("log_errors", 0); 
ini_set("error_reporting", 0); 


    if (isset($_GET[$numname])) 
    { 
     $namecount = 0; 
     if (is_numeric(explode("/", explode("$$$", $_GET["number"])[0])[0])) 
     { 
      echo "<br />"; 
      if (explode("$$$", $_GET[$numname])[1] == "male") 
       $handle = fopen("./malenames.txt", "r"); 
      else if (explode("$$$", $_GET[$numname])[1] == "female") 
       $handle = fopen("./femalenames.txt", "r"); 
      else 
       $handle = fopen("./surnames.txt", "r"); 
      $output = Array(); 
      if ($handle) 
      { 
       while (($line = fgets($handle)) !== false) 
       { 
        $bVal = 0; 
        for($j=0;$j<=strlen(utf8_decode($line));$j++) 
        { 
         $bVal += $values[substr(utf8_decode(mb_strtolower($line)),$j,1)]; 
        } 
        if ($bVal==explode("/", explode("$$$", $_GET[$numname])[0])[0] || explode("/", explode("$$$", $_GET[$numname])[0])[0] == (1+(($bVal-1)%9))) 
        { 
         //echo $line . "<br />"; 
         $output[$namecount] = $line . " (" . $bVal . "/" . (1+(($bVal-1)%9)) . ")<br />"; 
         $namecount++; 
        } 
        //echo $line . "<br />"; 
       } 
       fclose($handle); 
       echo "<p id='numcount'>Found " . $namecount . " names</p>"; 
       echo "<br />"; 
       for ($i=0;$i<count($output);$i++) 
        echo $output[$i]; 
       unset($output); 
      } 
     } 
     else if (is_numeric(explode(" ", explode("/", explode("$$$", $_GET[$numname])[0])[0])[1])) 
     { 
      $parm1 = explode(" ", explode("$$$", $_GET[$numname])[0]); 
      $oldname = utf8_decode($parm1[0]); 
      $num = explode("/", $parm1[1])[0]; 
      //echo "<p>" . $parm1 . "</p>"; 
      //echo "<p>" . $oldname . "</p>"; 
      //echo "<p>" . $num . "</p>"; 
      echo "<br />"; 
      if (explode("$$$", $_GET[$numname])[1] == "male") 
       $handle = fopen("./malenames.txt", "r"); 
      else if (explode("$$$", $_GET[$numname])[1] == "female") 
       $handle = fopen("./femalenames.txt", "r"); 
      else 
       $handle = fopen("./surnames.txt", "r"); 
      $output = Array(); 
      if ($handle) 
      { 
       while (($line = fgets($handle)) !== false) 
       { 
        $linex = $parm1[0] . mb_strtolower($line);//utf8_decode(mb_strtolower($oldname . mb_strtolower($line))); 
        $bVal = 0; 
        for($j=0;$j<=strlen(utf8_decode($linex));$j++) 
        { 
         $bVal += $values[substr(utf8_decode(mb_strtolower($linex)),$j,1)]; 
        } 
        if ($bVal==$num || $num == (1+(($bVal-1)%9))) 
        { 
         //echo $line . "<br />"; 
         $output[$namecount] = $linex . " (" . $bVal . "/" . (1+(($bVal-1)%9)) . ")<br />"; 
         $namecount++; 
        } 
        //echo $line . "<br />"; 
       } 
       fclose($handle); 
       echo "<p id='numcount'>Found " . $namecount . " names</p>"; 
       echo "<br />"; 
       for ($i=0;$i<count($output);$i++) 
        echo $output[$i]; 
       unset($output); 
      } 
     } 
     else 
     { 
      echo "<br />Error in input"; 
     } 
     echo "<div style='clear:both;'></div>"; 
    } 
?> 
</div> 
<script src="http://code.jquery.com/jquery-latest.min.js" 
     type="text/javascript"></script> 
+0

嘿!事情是,我們在ns.php文件中。它向自己發送一個xhttp請求,以便php腳本可以將輸入數據從url中取出。我還在網絡標籤(在Chrome中)中監控了請求。沒有錯誤和請求似乎格式正確! – DCBN

+0

請向我展示更多信息**未定義的索引名稱**顯示了什麼?它通常是由''「錯誤造成的 –

+0

基本上,我得到了應該打印的每個」索引「的錯誤,我只是打印出了錯誤,並重復了X次,我不確定究竟有多少次,因爲我沒有計算,但它是很多圖像:http://puu.sh/v6okb/2716b07de1.png – DCBN

相關問題