php - 如何在没有以 HTML 显示 JS 标签的情况下从 PHP 和 JS 中的其他站点读取数据?
问题描述
我有两个网站(support.mahtt.host 和 phonezone.ir),我希望 phonezone.ir 中的 test.php 文件从 support.mahtt.host 读取价格。根据 WHMCS 文档,一切正常,但我希望它以另一种方式工作。请检查此文件:http ://phonezone.ir/saeed/test.php 它从http://phonezone.ir/saeed/name.php 读取名称,从http://phonezone.ir/saeed/读取价格price.php,但正如您在其 HTML 代码中看到的那样,Javascript 标记显示从哪个站点读取价格和名称。
我最近开始学习 PHP,但我不知道在网络上准确地搜索什么。我曾尝试使用 file_get_contents() 和 curl() 函数,但我认为我尝试了错误的函数。
name.php 内容(省略 php 标签):
$name = "<script language='javascript' src='https://support.mahtt.host/feeds/productsinfo.php?pid=1&get=name'></script>";
price.php 内容(省略 php 标签):
$price = "<script language='javascript' src='https://support.mahtt.host/feeds/productsinfo.php?pid=9&get=price&billingcycle=monthly'></script>";
test.php 内容(省略 php 标签):
include ("./name.php");
include ("./price.php");
echo "The price of $name is $price.";
当前的html输出是:
The price of <script language='javascript' src='https://support.mahtt.host/feeds/productsinfo.php?pid=1&get=name'></script> is <script language='javascript' src='https://support.mahtt.host/feeds/productsinfo.php?pid=9&get=price&billingcycle=monthly'></script>.
我希望 HTML 输出与浏览器中显示的一样,如下所示:
The price of IRcPanel-A is 81,000 تومان.
当我或任何其他访问者看到时,我们只能在浏览器和 html 输出中看到上述输出。
你能帮我做什么来得到我的预期结果吗?
解决方案
我已经通过使用 php 代码而不是 JS 标签解决了这个问题。
我创建了另一个名为 db.php 的 .php 文件,其内容如下:
<?php
$servername = "MyServerIP";
$username = "user_name";
$dbname = "db_name";
$password = "some_password";
$saeedIsCool = new mysqli($servername, $username, $password, $dbname);
if ($saeedIsCool->connect_error) {
die("Connection failed: " . $saeedIsCool->connect_error);
}
$sql = "SELECT monthly FROM tblpricing WHERE id = 1";
$result = $saeedIsCool->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$id1Product = "". $row["monthly"]." Toman";
}
} else {
echo "0 results";
}
$floorid1Product = floor($id1Product). " Toman";
$saeedIsCool->close();
?>
并修改了我的 test.php 内容如下:
<?php
include ("./name.php");
include ("./db.php");
echo "The price of {$name} is {$floorid1Product} Toman per month";
?>
现在结果如预期的那样:
IRcPanel-A 的价格是每月 11200 Toman
推荐阅读
- snakemake - 是否可以将规则动态添加到“localrules:”?
- python-3.x - 所以我正在学习 Python 3.x,这本书想要使用一个循环来打印一个列表。但
- javascript - 从 MetaWeatherAPI 获取数据
- node.js - 在来自 JSON 文件的同一查询中在 Neo4j 中创建节点和关系
- node.js - 如何检查成员是否提到了特定用户?
- android - NullPointerException:尝试在 Android Studio 上调用虚拟方法
- r - add_row 将因子/数值列转换为 char;不能添加有序因子
- javascript - 如何在reduce函数的帮助下分解对象并使其成为以下结构
- python - Matplotlib 使用背景颜色填充垂直渐变、纹理和代码
- passport.js - 是否可以在请求上配置 PassportJS 策略?