简体   繁体   English

PHP 页面在本地工作,但在服务器上不工作

[英]PHP page is working locally, but not on the server

My PHP page is blank when I upload it to my server and navigate to it in a browser.当我将它上传到我的服务器并在浏览器中导航到它时,我的 PHP 页面是空白的。

<form action="welcome.php" method="get">
    <input type="text" name="name" placeholder="enter first and last name" >
    <br />
    <input type="image" value="Submit" id="submit"/>
</form>

On the welcome.php page:在welcome.php页面上:

$fullName = $_GET['name'];
$firstName = explode(' ',trim($fullName));

<h2>Welcome <?php echo $firstName[0] ?>!</h2>

SOLVED .解决了 Permissions issue.权限问题。 The PHP file needed to be 644 , not 666 . PHP 文件需要是644 ,而不是666

The problem:问题:

<!– SHTML Wrapper – 500 Server Error –>

This is a silly Bluehost error.这是一个愚蠢的Bluehost错误。 Typically related to file permissions.通常与文件权限有关。 See here: http://www.bluehostforum.com/showthread.php?11101-SHTML-Wrapper-500-Server-Error-moving-to-a-new-box-helps请参阅此处: http : //www.bluehostforum.com/showthread.php?11101-SHTML-Wrapper-500-Server-Error-moving-to-a-new-box-helps

Just make sure that your file does not have the "world write" permission.只需确保您的文件没有“世界写入”权限。

Try checking your server's Apache log file.尝试检查您服务器的 Apache 日志文件。 This should give you some indication to the server error if any.如果有的话,这应该会给你一些关于服务器错误的指示。

If you do not have access to the error log, add the following to the top of your PHP file.如果您无权访问错误日志,请将以下内容添加到 PHP 文件的顶部。 It will show any errors on the page you are viewing.它将显示您正在查看的页面上的任何错误。

error_reporting(E_ALL);
ini_set('display_errors', 1);

One of the easiest solutions is enabling FastCGI from the cPanel PHPConfig.最简单的解决方案之一是从cPanel PHPConfig 启用 FastCGI。

Just enable it and everything will work.只需启用它,一切都会起作用。

Viewing the source code, you have an internal server error (500).查看源代码,您有一个内部服务器错误 (500)。 Googling the error, you have WordPress(?) or this affects it.谷歌搜索错误,你有 WordPress(?) 或者这会影响它。

<!– SHTML Wrapper – 500 Server Error –>

According to this guide , it's a problem with PHP CGI and you need to fix it in your host' panel, or manually via the terminal. 根据本指南,这是 PHP CGI 的问题,您需要在主机面板中修复它,或通过终端手动修复。

This question is almost 10 years old, but I never saw this.这个问题已经有将近 10 年的历史了,但我从未见过。

If you are using HostGator, do the following: go to cPanel –> MySQL Databases –> Add New User (set the password, and allow all or none of the query permissions – if you are a student then allow all permissions).如果您使用的是 HostGator,请执行以下操作:go 到 cPanel –> MySQL 数据库 –> 添加新用户(设置密码,并允许所有查询权限或不允许任何查询权限——如果您是学生,则允许所有权限)。

Now scroll down to "Add User To Database."现在向下滚动到“将用户添加到数据库”。 Make sure the username you just created is linked to the database you are trying to use.确保您刚刚创建的用户名链接到您尝试使用的数据库。

Here's a sample of how your code should look like:以下是您的代码的示例:

// Server conditional values and connection
// This first if-statement connects to your localhost
if ($_SERVER['HTTP_HOST'] == 'localhost') {
        define('HOST', 'localhost');
        define('USER', 'root');
        define('PASS', '1550');
        define('DB', 'webPoll');
} else {
// Means that you are in a web server
        define('HOST', 'localhost');
        // localhost is the default parameter
        define('USER', 'kevin69_tacoUser'); 
        // add the username you just created
        define('PASS', 'hUIDnd193');
        // password for such username
        define('DB', 'kevin69_webPoll');
        // username_database
}
$conn = mysqli_connect(HOST, USER, PASS, DB);

Hope this helps someone out there!希望这可以帮助那里的人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM