[英]PHP Application works fine on webhotel but not on local server (WAMP)
I am currently working a little with PHP and taking over a project that wasn't created by me. 我目前正在使用PHP进行一些工作,并接管了一个不是我创建的项目。 The tricky things is that on the server/webhotel the application is working like expected, however in my local test environment (WAMP 3.0.6 64bit, PHP 5.6.25, Apache 2.4.23, MySQL 5.7.14) it isn't working.
棘手的是,在服务器/ Webhotel上,应用程序运行正常,但是在我的本地测试环境(WAMP 3.0.6 64bit,PHP 5.6.25,Apache 2.4.23,MySQL 5.7.14)中,该应用程序无法正常工作。 The error message that is being output by PHP is :
PHP输出的错误消息是:
Notice: Undefined index: ... line 110
注意:未定义的索引:...第110行
which is directed at this snippet: 针对此代码段:
$bVal += $values[substr(utf8_decode(mb_strtolower($line)),$j,1)];.
Thing is, I have copied all files as is from the server including all the files it rely on. 事实是,我已经从服务器复制了所有文件,包括它所依赖的所有文件。 I only have to make small tweaks (Change the text files the php script reads from) but it won't even work with the original ones.
我只需要进行一些小的调整(更改php脚本读取的文本文件),但它甚至无法与原始脚本一起使用。 Is there a common issue between platforms versions for PHP, Apache etc?
在PHP,Apache等平台版本之间是否存在常见问题? As far as I can tell the XHTTP request is acting normally and I feel like I shouldn't be having these issues, this may come from my inexperience with PHP though.
据我所知XHTTP请求正常运行,我觉得我不应该遇到这些问题,但这可能是由于我对PHP的经验不足。
Code will be posted below and thank you in advance for even taking a look at it! 代码将发布在下面,在此先感谢您的关注!
Code: https://pastebin.com/M6y9rfRa 代码: https : //pastebin.com/M6y9rfRa
Change your code to this and see how it goes 将您的代码更改为此,看看它如何进行
<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 ";
echo "<input type='radio' name='switcher' value='male' " . (explode("$$$", $_GET["number"])[1] == "male" ? "checked" : "") . ">Male ";
echo "<input type='radio' name='switcher' value='last' " . (explode("$$$", $_GET["number"])[1] == "last" ? "checked" : "") . ">Last name ";
}
else {
echo "<div><input placeholder='Enter vibration' type='text' id='nInput' name='nInput' />";
echo "<br /><input type='radio' name='switcher' value='female' checked>Female <input type='radio' name='switcher' value='male' >Male ";
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 ";
echo "<input type='radio' name='switcher2' value='male' " . (explode("$$$", $_GET["number2"])[1] == "male" ? "checked" : "") . ">Male ";
echo "<input type='radio' name='switcher2' value='last' " . (explode("$$$", $_GET["number2"])[1] == "last" ? "checked" : "") . ">Last name ";
$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 <input type='radio' name='switcher2' value='male' >Male ";
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.