如何从网站中删除以下 PHP 错误?

问题描述 投票:0回答:0
<?php

$weather = "";
$error = "";
// if($_GET["city"]){ 
    // better way -->
    if(array_key_exists('city',$_GET))
    {
    $city = str_replace(' ','',$_GET['city']);

    $file_headers = @get_headers("https://www.weather-forecast.com/locations/".$city."/forecasts/latest");

    if($file_headers[0] == 'HTTP/1.1 404 Not Found'){
        $error = "City couldn't be found";
    }
    else{
    $forcastPage = file_get_contents("https://www.weather-forecast.com/locations/".$city."/forecasts/latest");
    
    $pageArray = explode('3 days)</div><p class="b-forecast__table-description-content"><span class="phrase">',$forcastPage);

    if(sizeof($pageArray) >1){
    $secondPageArray = explode('</span></p></td>',$pageArray[1]);
    if(sizeof($secondPageArray)>1){
    $weather =  $secondPageArray[0];
    }
    else{
        $error = "City couldn't be found";
    }
    }
    else{
        $error = "City couldn't be found";
    }
}

    }

?>

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Weather Scraper</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
    <style>
        html{
            background: url(sunset.avif) no-repeat center center fixed;
            background-size: cover;
        }
        body{
            background:none;
        }
        .container{
            text-align:center;
            margin-top: 100px;
            width:450px;
        }
        input{
            margin:20px 0;
        }
        #weather{
            margin-top: 15px;
        }
    </style>
</head>
  <body>
    <div class="container">
        <h1>What's the weather?</h1>
        <form>
  <div class="mb-3">
    <label for="city" class="form-label">Enter the name of a city</label>
    <input type="text" name="city" class="form-control" id="city" placeholder="Eg. London , Tokyo" 
    value = "<?php
    if(array_key_exists('city',$_GET))
    {
     echo $_GET["city"];
    }
     ?>">
    
  </div>
  <button type="submit" class="btn btn-primary">Submit</button>
</form> 
<div id="weather">
    <?php 
    if($weather){
        echo '<div class="alert alert-success" role="alert">
        '.$weather.'
      </div>';
    }
    else if($error){
        echo '<div class="alert alert-danger" role="alert">
        '.$error.'
      </div>';
    }
    ?>
</div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
  </body>
</html>

当我在我的本地服务器上运行这段代码时,它运行没有任何错误并显示了输出。但是我在 000webhost 上托管了网站,网站链接:https://overprotective-gard.000webhostapp.com/?city=china

出现以下错误:

警告:file_get_contents():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14090086:SSL 例程:ssl3_get_server_certificate:证书验证在 /storage/ssd4/367/20650367/public_html/index.php 上失败17

警告:file_get_contents():无法在/storage/ssd4/367/20650367/public_html/index.php 在线17

中启用加密

警告:file_get_contents(https://www.weather-forecast.com/locations/london/forecasts/latest):无法打开流:操作在/storage/ssd4/367/20650367/public_html/中失败index.php 上线17

有人可以查看代码并帮助我删除错误吗?

php jquery web-development-server web-deployment-project
© www.soinside.com 2019 - 2024. All rights reserved.