[英]MySql & PHP Code are showing as plain text
在 cPanel 中,我沒有問題,這些工作正常。 但是在本地主機中,我收到了很多錯誤。
Notice: Undefined variable: eroare in C:\xampp\htdocs\invo\install\index.php on line 68
Notice: Undefined variable: suc in C:\xampp\htdocs\invo\install\index.php on line 69
index.php 文件如下:
<?php
session_start();
if(isset($_POST['submit'])){
if($_POST['admin_user']=='' || $_POST['admin_pass']==''){
$eroare='Admin User/Pass Empty!';
}
if(!@mysql_connect($_POST['mysql_host'],$_POST['mysql_user'],$_POST['mysql_pass'])){
$eroare='MySQL Connection Failure';
}
if(!@mysql_select_db($_POST['mysql_db'])){
$eroare='MySQL Database Not Found!';
}
if(!$eroare){
$filename = 'sql.sql';
$templine = '';
$lines = @file($filename);
if(is_array($lines)){
foreach ($lines as $line_num => $line) {
if (substr($line, 0, 2) != '--' && $line != '') {
$templine .= $line;
if (substr(trim($line), -1, 1) == ';') {
mysql_query($templine) or print('Error performing query \'<b>' . $templine . '</b>\': ' . mysql_error() . '<br /><br />');
$templine = '';
}
}
}
}
$myFile = "../inc/db.php";
$fh = @fopen($myFile, 'w+') or $success=1;
$stringData = '<?php
$host = "'.$_POST['mysql_host'].'";
$username = "'.$_POST['mysql_user'].'";
$password = "'.$_POST['mysql_pass'].'";
$db = "'.$_POST['mysql_db'].'";
mysql_connect($host, $username, $password) or die("<center><font color=\"darkred\"><b>Cannot connect to database!</b></font></center>");
mysql_select_db($db);
?>';
@fwrite($fh, $stringData);
@fclose($fh);
mysql_query("insert into config(name,value) values('admin_user','".$_POST['admin_user']."')")or die(mysql_error());
mysql_query("insert into config(name,value) values('admin_pass','".$_POST['admin_pass']."')")or die(mysql_error());
if($success!=1){
$_SESSION['logged']=1;
$suc="Successfully Installed!<br/>Please configure your script from the <a href='../settings.php'>Settings Tab</a>";
}else
$suc='<b>Success!</b> The inc/db.php file <b>could not be created</b>. Please rename the db_config.php to db.php and configure it manually by opening the file in a text editor through FTP!';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<meta charset="utf-8">
<title>CDM Maker Installation</title>
<link rel="stylesheet" type="text/css" href="install.css" media="screen"/>
</head>
<body>
<div id="container2">
<div id="container">
<div class='header'>Installation</div>
<div class="content">
<?php if($eroare){?><div class='error'><?php echo $eroare?></div><?php }?>
<?php if($suc){?><div class='suc'><?php echo $suc?></div><?php }?>
<form action='' method='POST'>
<table width='100%' cellspacing='0' cellpadding='0'>
<tr>
<td>
<label for='username'>Admin Username</label>
<input type='text' class='login' name='admin_user' id='username' value='<? echo $_POST['admin_user']?>' placeholder="admin" required/>
<label for='parola'>Admin Password</label>
<input type='text' class='login' name='admin_pass' id='parola' value='<? echo $_POST['admin_pass']?>' placeholder="admin" required/>
<label for='host'>MySQL Host</label>
<input type='text' class='login' name='mysql_host' id='host' value='<? echo $_POST['mysql_host']?>' placeholder="localhost" required/>
<label for='user'>MySQL User</label>
<input type='text' class='login' name='mysql_user' id='user' value='<? echo $_POST['mysql_user']?>' placeholder="johndoe" required/>
<label for='pass'>MySQL Password</label>
<input type='text' class='login' name='mysql_pass' id='pass' value='<? echo $_POST['mysql_pass']?>' placeholder="********" required/>
<label for='db'>MySQL DB</label>
<input type='text' class='login' name='mysql_db' id='db' value='<? echo $_POST['mysql_db']?>' placeholder="my_database" required/>
<div style='clear:both; height:15px;'></div>
<center><button class="submit" name='submit' type="submit">Install</button></center>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
</body>
</html>
我嘗試過 ioncube,但我認為我的本地主機中缺少某些東西,請建議我如何在本地主機上運行它。 這個 undefine 變量僅在 localhost 中聲明,但在 cpanel 中聲明。
在文件開頭初始化所有變量無論如何
$eroare = $suc = '';
並且請使用像 PHPStorm 這樣的好 IDE 並單擊檢查代碼工具來檢查弱錯誤和警告。
在服務器上,警告、錯誤被關閉。 所以看到你的代碼失敗而不給出任何警告是一場噩夢。 所以請檢查代碼,然后只在實時服務器上上傳。
首先,您在 localhost 而不是遠程機器上啟用了更高級別的錯誤報告。 此通知級別錯誤不應停止腳本執行。 如果要修復錯誤,請在 if 語句中使用!empty($variable)
表達式,如下所示:
<div class="content">
<?php if(!empty($eroare)){?><div class='error'><?php echo $eroare?></div><?php }?>
<?php if(!empty($suc)){?><div class='suc'><?php echo $suc?></div><?php }?>
<form action='' method='POST'>
試試這個腳本。
在 session start() 函數之后添加這兩行。
$eroare='';
$suc='';
嘗試這個
if (empty($_POST['eroare'])) {
$eroare="";
} else {
$eroare=$_POST['eroare'];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.