user3308335 user3308335 - 6 months ago 18
PHP Question

Can't connect to a php file from nginx server

I have an nginx server set up on my rpi2 that works fine and is linked to my website. I have php5-fpm set up as well and my index.php file is simple, just to test it out.

<?php phpinfo(); ?>


going to website.com works and it shows the php info screen. Going to website.com/index.php works, as well as webstie.com/index.html, which shows the default "Welcome to nginx!" screen.

However, I am working on an accounts system and set up this simple page and put it in the www folder that includes my index files and named it login.php:

<?php

session_start();

?>
<html>
<head>
<meta http=equiv="Content Type" content="text/html; charset=utf-8" />
<title>Member System - Login</title>
</head>
<body>

<?php

$form="<form action='./login.php' method='post'></form>";
<table>
<tr>
<td>Username:</td>
<td><input type='text' name='user' /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='loginbtn' value='Login' /></td>
</tr>
</table>
</form>";

if ($_POST['loginbtn']){

$user= $_POST['user'];
$password = $_POST['password'];

if ($user) {
if($password){
echo "$user - $password <hr /> $form";
} else echo "You must enter your password. $form";
} else echo "You must enter your username. $form";

} else {
echo $form;
}

?>

</body>
</html>


However, whenever I go to website.com/login.php on a separate PC, Chrome says "The website.com page isn't working. website.com is currently unable to handle this request." With HTTP error 500, which is an internal server error.

In the www folder I ran

sudo cp index.php test.php


and then reloaded nginx. Going to website.com/test.php worked so I'm assuming the error lies within my login.php file but I haven't been able to figure it out.

What is wrong with my code? Any help is appreciated

Answer

If the example shown is the contents of login.php you have an error in your code

$form="<form action='./login.php' method='post'></form>";
<table>

will not work as <table> is hanging on it's own line outside of the string, delete the "; and it may fix the problem

Comments