duankousong9637 2019-05-24 11:11
浏览 31
已采纳

如何在没有JS标签的情况下从PHP和JS中读取其他站点的数据?

I have two websites (support.mahtt.host and phonezone.ir), and I want my test.php file in phonezone.ir reads prices from support.mahtt.host. As per WHMCS documentation, everything works fine but I want it works in another way. Please check this file: http://phonezone.ir/saeed/test.php It reads the name from http://phonezone.ir/saeed/name.php and the price from http://phonezone.ir/saeed/price.php, but as you see in its HTML codes, Javascript tag is shown that from which site the price and name are read.

I've started learning PHP recently and I don't know what to search for it exactly over the web. I have tried to work with file_get_contents() and curl() function, but I think I have tried the wrong ones.

name.php contents (php tags are omitted):

  $name = "<script language='javascript' src='https://support.mahtt.host/feeds/productsinfo.php?pid=1&get=name'></script>";

price.php contents (php tags are omitted):

  $price = "<script language='javascript' src='https://support.mahtt.host/feeds/productsinfo.php?pid=9&get=price&billingcycle=monthly'></script>";

test.php contents (php tags are omitted):

  include ("./name.php");
  include ("./price.php");
  echo "The price of $name is $price.";

The current html output is:

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>.

I want HTML output be like as it's shown in the browser, like this:

The price of IRcPanel-A is 81,000 تومان.

And when I or any other visitor sees, we only see the above output in both browser and html output.

Could you please help me what should I do to get my expected result?

  • 写回答

1条回答 默认 最新

  • dongshuo5101 2019-05-25 18:27
    关注


    I have solved this issue by using php codes instead of JS tags.
    I have created another .php file called db.php with the below contents:

    <?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();
    ?>
    

    And have modified my test.php contents as below:

    <?php
      include ("./name.php");
      include ("./db.php");
      echo "The price of {$name} is {$floorid1Product} Toman per month";
    ?>
    

    And now the result is as expected:
    The price of IRcPanel-A is 11200 Toman per month

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法