Laravel - 仅在Safari和其他一些浏览器上使用HTTPS和AJAX时出错

时间:2015-12-21 15:05:29

标签: php ajax laravel

当我使用AJAX进行发布请求时,我收到此错误:

  

PHP Parse错误:语法错误,意外'/ *'(T_STRING),期待   第47行/home/laravel/public_html/public/index.php中的')'

     

PHP致命错误:require():需要打开失败   '/home/user/public_html/vendor/ClassLoader.php'   (include_path ='。:/ usr / lib / php:/ usr / local / lib / php')in   第6行/home/user/public_html/vendor/autoload.php

它所引用的index.php如下:

<?php

require __DIR__.'/../../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

我不知道为什么会这样。

这只发生在safari和其他一些浏览器中。不会发生在Chrome上。

inspect元素如下所示: Error on Web Developer Tools

请帮帮我们。感谢

编辑:文件夹结构:

home/user/laravel -> All my laravel files
home/user/laravel/public_html/public -> my public folder

当我composer install时,它会给我这个错误:

Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI
Composer could not find a composer.json file in /usr/bin

出于某种原因,它正在/ usr / bin中寻找composer.json文件。 composer.json文件位于我将要访问的当前目录中。

2 个答案:

答案 0 :(得分:0)

编辑:index.php应如下所示:

<?php

require __DIR__.'/../../bootstrap/autoload.php';
$app = require_once __DIR__.'/../../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

希望能够做到这一点。

任何PHP文件的第一行都应该是

<?php

在您的索引文件副本中遗漏了某些内容。我不确定那是怎么回事,但这就是你所看到的错误。

答案 1 :(得分:0)

我有同样的问题。完全一样。它只发生在HTTPS上。

这就是我的所作所为:

第一件事是第一件事。运行以下命令:

php artisan cache:clear 

chmod -R 777 app/storage 

composer dump-autoload

php artisan optimize

然后运行

npm install

确保在public_html文件夹中没有index.htmlindex.php文件。它应该只在public_html/public文件夹中。

之后,确保正确设置了Htaccess。

public_html目录中的Htaccess应该是这样的:

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

</IfModule>

完成以下操作后,请告诉我它是怎么回事。另外,请务必查看storage / logs / laravel.log中的日志文件和Apache日志。

干杯!