ドットインストールのレッスンに沿って進めてきましたが、ログイン画面をブラウザに表示することができません。
(レッスン名:PHPでログイン機能を実装しよう » #08 ログイン画面を作っていこう)
ご助言頂けますと幸いです。
<確認手順>
ターミナルに下記コマンドを入力し、ビルトインWEBサーバーを立ち上げる。
php -S 192.168.33.10:8000 -t public_html/
Listening on http://192.168.33.10:8000と表示されるので、Chromeで検索バーにhttp://192.168.33.10:8000を入力。
<ターミナルで返ってきたエラーメッセージ>
[Thu Mar 20 16:44:54 2020] PHP Warning: require_once(/home/vagrant/sns_php/config/../lib/functions.php): failed to open stream: No such file or directory in /home/vagrant/sns_php/config/config.php on line 11 [Thu Mar 20 16:44:54 2020] PHP Fatal error: require_once(): Failed opening required '/home/vagrant/sns_php/config/../lib/functions.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/vagrant/sns_php/config/config.php on line 11 [Thu Mar 20 16:44:54 2020] 192.168.33.1:56996 [200]: / - require_once(): Failed opening required '/home/vagrant/sns_php/config/../lib/functions.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/vagrant/sns_php/config/config.php on line 11 [
<ブラウザ上の表示>
Warning: require_once(/home/vagrant/sns_php/config/../lib/functions.php): failed to open stream: No such file or directory in /home/vagrant/sns_php/config/config.php on line 11 Fatal error: require_once(): Failed opening required '/home/vagrant/sns_php/config/../lib/functions.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/vagrant/sns_php/config/config.php on line 11
<各ファイルの内容>
php
1//vagrant/sns_php/config/autoload.php 2 3<?php 4 5/* 6MyApp 7index.php controller 8MyApp\Controller\Index 9-> lib/Controller/Index.php 10*/ 11 12spl_autoload_register(function($class) { 13 $prefix = 'MyApp\'; 14 if (strpos($class, $prefix) === 0) { 15 $className = substr($class, strlen($prefix)); 16 $classFilePath = __DIR__ . '/../lib/' . str_replace('\', '/', $className) . '.php'; 17 if (file_exists($classFilePath)) { 18 require $classFilePath; 19 } 20 } 21});
php
1//vagrant/sns_php/config/config.php 2 3<?php 4 5ini_set('display_errors', 1); 6 7define('DSN', 'mysql:dbhost=localhost;dbname=dotinstall_sns_php'); 8define('DB_USERNAME', 'dbuser'); 9define('DB_PASSWORD', 'mu4uJsif'); 10 11define('SITE_URL', 'http://' . $_SERVER['HTTP_HOST']); 12 13require_once(__DIR__ . '/../lib/functions.php'); 14require_once(__DIR__ . '/autoload.php'); 15 16session_start();
sql
1//vagrant/sns_php/config/init.sql 2 3create database dotinstall_sns_php; 4 5grant all on dotinstall_sns_php.* to dbuser@localhost identified by 'mu4uJsif'; 6 7use dotinstall_sns_php 8 9create table users ( 10 id int not null auto_increment primary key, 11 email varchar(255) unique, 12 password varchar(255), 13 created datetime, 14 modified datetime 15); 16 17desc users;
php
1//vagrant/sns_php/lib/Controller.php 2 3<?php 4 5namespace MyApp; 6 7class Controller { 8 9 protected function isLoggedIn() { 10 // $_SESSION['me'] 11 return isset($_SESSION['me']) && !empty($_SESSION['me']); 12 } 13 14}
php
1//vagrant/sns_php/lib/function.php 2 3<?php 4 5function h($s) { 6 return htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); 7}
php
1//vagrant/sns_php/lib/Controller/Index.php 2 3<?php 4 5namespace MyApp\Controller; 6 7class Index extends \MyApp\Controller { 8 9 public function run() { 10 if (!$this->isLoggedIn()) { 11 // login 12 header('Location: ' . SITE_URL . '/login.php'); 13 exit; 14 } 15 16 // get users info 17 } 18 19}
php
1//vagrant/sns_php/public_html/index.php 2 3<?php 4 5// ユーザーの一覧 6 7require_once(__DIR__ . '/../config/config.php'); 8 9$app = new MyApp\Controller\Index(); 10 11$app->run();
php
1//vagrant/sns_php/public_html/login.php 2 3<?php 4 5// ログイン 6 7require_once(__DIR__ . '/../config/config.php'); 8 9// $app = new MyApp\Controller\Login(); 10// 11// $app->run(); 12 13echo "login screen"; 14exit;
回答1件
あなたの回答
tips
プレビュー