首页 > 解决方案 > 从其他文件夹重定向时,Stripe API 停止工作

问题描述

不知道发生了什么,但是当我将一个条带结账应用程序下载到我的计算机并通过我的终端运行它时,它就可以工作了。我的条带仪表板上的日志获得了多个事件而没有错误。

php -S localhost:4242

我安装了条带 CLI 来测试 webhook,但后来遇到了这个问题。无论哪种方式,它都帮助我进行了一些调试。

stripe listen --forward-to=localhost:4242

当我转到 localhost:4242/index.html 并单击应该启动“订阅”过程的按钮时,条纹日志:

2021-04-13 14:48:24   --> checkout.session.completed [evt_1Ifg2uLgiL5uZZPEFUQPX5UY]
2021-04-13 14:48:24  <--  [200] POST http://localhost:4242 [evt_1Ifg2uLgiL5uZZPEFUQPX5UY]
2021-04-13 14:48:24   --> payment_method.attached [evt_1Ifg2uLgiL5uZZPEovIMBDrU]
2021-04-13 14:48:24  <--  [200] POST http://localhost:4242 [evt_1Ifg2uLgiL5uZZPEovIMBDrU]
2021-04-13 14:48:24   --> customer.subscription.created [evt_1Ifg2vLgiL5uZZPEeW5I9uuv]
2021-04-13 14:48:24  <--  [200] POST http://localhost:4242 [evt_1Ifg2vLgiL5uZZPEeW5I9uuv]
2021-04-13 14:48:25   --> customer.subscription.updated [evt_1Ifg2vLgiL5uZZPET119BTe4]
2021-04-13 14:48:25  <--  [200] POST http://localhost:4242 [evt_1Ifg2vLgiL5uZZPET119BTe4]
2021-04-13 14:48:25   --> invoice.paid [evt_1Ifg2vLgiL5uZZPERfBA65LF]
2021-04-13 14:48:25  <--  [200] POST http://localhost:4242 [evt_1Ifg2vLgiL5uZZPERfBA65LF]
2021-04-13 14:48:26   --> invoice.updated [evt_1Ifg2vLgiL5uZZPEe3m7U1wL]
2021-04-13 14:48:26  <--  [200] POST http://localhost:4242 [evt_1Ifg2vLgiL5uZZPEe3m7U1wL]

这就是问题开始的地方。我创建了一个带有登录系统和一堆东西的网站,我的目的是将这个条带结账应用程序链接到那个登录系统,所以我需要访问 $_SESSION 变量。顺便说一下,这是我的文件夹结构:

Root
|── /includes
│   │── login.inc.php
│   └── logout.inc.php
│
|── /stripe_test
|    │── index.html
|    │── createcheckout.php
|    │── config.ini
|    │── config.php
│    └── script.js
│
|── /loginpage.php
|── /editprofile.php
|── /logoutpage.php
|── /index.php
|── /header.php
|── /footer.php
└── .htaccess

我在 root/index.php 中添加了一个简单的链接,该链接重定向到 root/stripe_test/index.html,使它成为一种“选择计划”页面。我应该提一下,我将根目录托管在 xampp localhost:8080 中,这更奇怪。原因是从 localhost:4242 打开该条带 html 页面使其按预期工作。简而言之:

我检查了我的 apache 错误日志,这是单击按钮后显示的内容:

[Tue Apr 13 15:51:35.411737 2021] [core:warn] [pid 8520:tid 588] AH00098: pid file C:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Tue Apr 13 15:51:35.432756 2021] [mpm_winnt:notice] [pid 8520:tid 588] AH00455: Apache/2.4.46 (Win64) OpenSSL/1.1.1h PHP/8.0.2 configured -- resuming normal operations
[Tue Apr 13 15:51:35.432756 2021] [mpm_winnt:notice] [pid 8520:tid 588] AH00456: Apache Lounge VS16 Server built: Oct  2 2020 11:45:39
[Tue Apr 13 15:51:35.432756 2021] [core:notice] [pid 8520:tid 588] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Tue Apr 13 15:51:35.434758 2021] [mpm_winnt:notice] [pid 8520:tid 588] AH00418: Parent: Created child process 11816
[Tue Apr 13 15:51:35.724020 2021] [mpm_winnt:notice] [pid 11816:tid 700] AH00354: Child: Starting 150 worker threads.
[Tue Apr 13 15:51:44.120877 2021] [php:warn] [pid 11816:tid 1840] [client ::1:58891] PHP Warning:  require_once(shared.php): Failed to open stream: No such file or directory in C:\\xampp\\root\\config.php on line 3, referer: http://localhost:8080/stripe_test/index.html
[Tue Apr 13 15:51:44.120877 2021] [php:error] [pid 11816:tid 1840] [client ::1:58891] PHP Fatal error:  Uncaught Error: Failed opening required 'shared.php' (include_path='C:\\xampp\\php\\PEAR') in C:\\xampp\\root\\config.php:3\nStack trace:\n#0 {main}\n  thrown in C:\\xampp\\root\\config.php on line 3, referer: http://localhost:8080/stripe_test/index.html

我不知道为什么该目录有两个“反斜杠”,但它可能与 .htaccess 文件和在我的标题中。这是 htaccess 指令:

Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^profile/([\w-]+)/?$ profile.php?userid=$1 [L,QSA,NC]
RewriteRule ^([\w-]+)/([\w-]+)/?$ city_page.php?state=$1&city=$2 [L,QSA]

有人可以解释这里发生了什么吗?我认为主要问题是 htaccess 和基本 href,因为当我在终端中定位实际文件夹 stripe_test 并直接从该目录运行服务器时,它可以工作。当我使用我的 xampp 运行服务器时,它会使用那些 .htaccess 指令和基本 href,这时 error.log 会显示奇怪的路径。

标签: phpregexapache.htaccessstripe-payments

解决方案


没有文件 C:\\xampp\\root\\config.php。它在 C:\\xampp\\root\\stripe_test\\config.php


推荐阅读