【问题标题】:included php files causing error包含导致错误的php文件
【发布时间】:2016-02-14 03:31:45
【问题描述】:

我有一个脚本,我试图将 php 文件包含在我的附属跟踪脚本中。两个脚本都在同一个 vps 上,我知道附属跟踪脚本可以工作,因为我已经以相同的方式成功地将它包含到不同的脚本中。

在这种情况下,包含跟踪代码会导致页面无法完成加载。

我尝试从 cpanel 和 php 文件顶部打开 php 错误,但没有看到任何错误报告

有点难过。谁能看到错误是什么,或者我可能做错了什么?

谢谢大家。

包含的行:

$sale_amount = '10.00';
$product = 'Drive-Plan';
include('partners/controller/record-sale.php);

完整的php文件:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
<?php namespace App\Http\Controllers;

use App;
use Auth;
use Input;
use Stripe\Stripe;
use Stripe\Plan;

class PaymentsController extends Controller {

    public function __construct() {
        $this->middleware('loggedIn');
        $this->middleware('paymentsEnabled');

        $this->user = Auth::user();
        $this->settings = App::make('App\Services\Settings');

        Stripe::setApiKey($this->settings->get('stripe_secret_key'));
    }

    /**
     * Subscribe user to a plan or swap him to a different plan.
     *
     * @return response
     */
    public function upgrade() {
        if ($this->user->subscribed()) {
            $this->user->subscription(Input::get('plan'))->swap();
        } else { 

$sale_amount = '10.00';
$product = 'Drive-Plan';
include('partners/controller/record-sale.php);

            $this->user->subscription(Input::get('plan'))->create(Input::get('stripe_token'), ['email' => $this->user->email]);
        }

        return response(trans('app.upgradeSuccess'), 200);


    }


    /**
     * Swap current users plan to a new one.
     *
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function swapPlan() {
        if ($this->user->subscribed() && Input::get('plan')) {
            $this->user->subscription(Input::get('plan'))->swap();

            return response(trans('app.planSwapSuccess', ['plan' => Input::get('plan')]), 200);
        }
    }

    /**
     * Attach new credit card to user.
     *
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function addNewCard() {
        $this->user->updateCard(Input::get('stripe_token'));

        return response(trans('app.cardAddSuccess'), 200);
    }

    /**
     * Resume a canceled subscription.
     */
    public function resumeSubscription() {
        $this->user->subscription(Input::get('plan'))->resume(Input::get('token'));

        return $this->user;
    }

    /**
     * Cancel users subscription.
     *
     * @return \App\User
     */
    public function unsubscribe() {
        $this->user->subscription()->cancel();

        return $this->user;
    }

    /**
     * Return current users invoices.
     *
     * @return array
     */
    public function getInvoices() {
        return view('invoices')->with('invoices', $this->user->invoices())->with('settings', $this->settings);
    }

    /**
     * Download invoice with given id.
     *
     * @param {int|string} $id
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function downloadInvoice($id) {
        return $this->user->downloadInvoice($id, [
            'vendor'  => $this->settings->get('invoiceVendor'),
            'product' => $this->settings->get('invoiceProduct'),
        ]);
    }

    /**
     * Return all created plans.
     *
     * @return array
     */
    public function getPlans() {
        $plans     = Plan::all();
        $formatted = [];

        foreach($plans->data as $plan) {
            $formatted[] = [
                'interval' => $plan['interval'],
                'name' => $plan['name'],
                'amount' => $plan['amount'] / 100,
                'currency' => $plan['currency'],
                'id' => $plan['id'],
                'created' => $plan['created'],
            ];
        }

        usort($formatted, function($a1, $a2) {
            if ($a1['created'] == $a2['created']) return 0;
            return ($a1['created'] < $a2['created']) ? -1 : 1;
        });

        return $formatted;
    }
}

【问题讨论】:

  • include('partners/controller/record-sale.php');在末尾添加报价
  • 你的 init_set 在&lt;?php 标签之外

标签: php error-handling syntax-error


【解决方案1】:

你错过了这一行的结尾引号:

include('partners/controller/record-sale.php);

应该是:

include('partners/controller/record-sale.php');

【讨论】:

  • @devpro。再次感谢。新错误是:命名空间声明语句必须是第 4 行 /home/drive/public_html/application/app/Http/Controllers/PaymentsController.php 脚本中的第一个语句
  • @cam r 这些在 PHP 标签里面??? ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
  • 删除了前几行错误报告,现在页面正在加载:)
  • 非常感谢。我现在将测试脚本是否正常运行。
猜你喜欢
  • 2017-04-29
  • 1970-01-01
  • 2012-05-13
  • 1970-01-01
  • 2014-04-10
  • 1970-01-01
  • 2022-07-19
  • 2021-07-05
相关资源
最近更新 更多