Q&A
###前提・実現したいこと
ログイン用のシステムをPHPで作っています。
###発生している問題・エラーメッセージ
プログラムをサーバーにアップし、ブラウザで見に行くとエラーコード500が帰ってきます。
エラー内容などは表示されません。ちなみに、PHPファイルの頭にエラを表示するように記述しています。
直接apacheのエラーログを見ると、次のようになっていました。
[Thu Dec 21 18:02:27.115932 2017] [php7:emerg] [pid 1221] [client 192.168.56.101:55236] PHP Parse error: syntax error, unexpected end of file in /var/www/html/login.php on line 111 [Thu Dec 21 18:02:28.115500 2017] [php7:emerg] [pid 1218] [client 192.168.56.101:55238] PHP Parse error: syntax error, unexpected end of file in /var/www/html/login.php on line 111
on line 111となっているので、確認したところそれはファイルの末尾で改行されているだけでした。PHPとhtmlの混合記述を取っていますのでそこに原因があるように思い、確認しましたが、問題らしいものはありませんでした。改行コードはLFです。
###該当のソースコード
login.php
1<?php 2ini_set("display_errors", On); 3error_reporting(E_ALL); 4get_request(); 5check_session(); 6 7if(isset($_POST['user_name'],$_POST['user_passwd'])){ 8 log_in($_POST['user_name'],$_POST['user_passwd']); 9} 10 11 12//functions for login program 13function log_in($user,$passwd){ 14 15if(isset($user,$passwd)){ 16 /*connect database*/ 17 $mysqli = new mysqli('localhost','**********','**********','ch_users'); 18 19 if($mysqli->connect_errno){ 20 echo $mysqli->connect_errno . ' : ' . $mysqli->connect_error; 21 exit(); 22 } 23 24 if($result = $mysqli->query("SELECT * FROM chat_users WHERE user_name = '" . $user . "' AND user_passwd = '" . $passwd . "' ")){ 25 $num_rows = $result->num_rows; 26 if($num_rows == 1){ 27 $_SESSION['login'] = true; 28 header('Location:/'); 29 exit(); 30 }else{ 31 header('Location:login?action=error'); 32 exit(); 33 } 34 $result->close(); 35 } 36 db_close(); 37} 38 39 40function logged_out(){ 41 session_start(); 42 $_SESSION = array(); 43 session_destroy(); 44 header('Location:login'); 45 exit(); 46} 47 48function get_request(){ 49 if(isset($_GET['action'])){ 50 $action = $_GET['action']; 51 if($action == "loggedout"){ 52 $page_title = "サインアウトしました"; 53 logged_out(); 54 55 }elseif($action == "error"){ 56 $error == true; 57 $page_title = "エラー"; 58 } 59 } 60} 61 62function check_session(){ 63 @session_start(); 64 65 if(isset($_SESSION['login'])){ 66 if($_SESSION['login'] == true){ 67 header('Location:/'); 68 exit(); 69 } 70 } 71} 72 73function set_title(){ 74 if(empty($page_title)){ 75 $page_title = "サインイン"; 76 } 77 echo $page_title; 78} 79 80?> 81 82 83<!DOCTYPE html> 84 <html> 85 <head> 86 <title> <?php set_title(); ?> </title> 87 <meta charset="UTF-8" > 88 <link rel="stylesheet" type="text/css" href="/bin/lib/common/style/style.css"> 89 </head> 90 <body> 91 <div id="contents" > 92 <div id="form" > 93 <form method="post"> 94 <label for="user_name" >ユーザー名</label> 95 <input type="text" id="user_name" name="user_name" maxlength="20" > 96 <br /> 97 <label for="user_passwd" >パスワード</label> 98 <input type="password" id="user_passwd" name="user_passwd" maxlength="16" > 99 <br /> 100 <input type="submit" value="サインイン" > 101 </form> 102 </div> 103 </div> 104 </body> 105 </html> 106
###試したこと
上の通りです。どなたかご教授いただけると幸いです。
###補足情報(言語/FW/ツール等のバージョンなど)
CentOS7 Virtualbox
PHP7.1.12
apache2.4.6
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2017/12/21 09:46