【发布时间】:2020-06-15 17:39:46
【问题描述】:
我最近开始使用 PHP 进行编程,并开始了我的新个人项目,这是一个基于 PHP 的新闻网站,可以围绕特定主题生成头条新闻。我正在使用 PHP 7.4.4、Bootstrap 和一点 CSS。一切进展顺利,任何错误都已解决,任何问题都通过搜索得到解答。至少在我开始将实际新闻插入我的网站之前。当我尝试使用我的 api 密钥(来自https://newsapi.org 的 API 密钥)将直播新闻插入“体育新闻”页面时,页面顶部出现错误:
file_get_contents():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14095126:SSL 例程:ssl3_read_n:读取 /opt/lampp/htdocs/news/app/views/news/sportNews.php 时出现意外 eof在第 18 行
该消息确实显示在我的屏幕上,但即使在反复尝试修复错误之后,错误仍然没有改变。
这是我的 sportNews.php:
<?php $this->setSiteTitle('News'); ?>
<?php $this->start('body'); ?>
<head>
<link href="css/newscss.css" rel="stylesheet"></link>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
</head>
<body>
<?php
//API_KEY filled in when running program
$url = "https://newsapi.org/v2/everything?q=sports&apiKey=API_KEY";
$response = file_get_contents($url); //ERROR LINE
$NewsData = json_decode($response);
?>
<div class="jumbotron">
<h1>Sports News</h1>
</div>
<div class="container-fluid">
<?php
foreach($NewsData->articles as $News)
{
?>
<div class="row">
<div class="col-md-3">
<img src="<?php echo $News->urlToImage ?>" alt="News thumbnail">
</div>
<div class="col-md-9">
<h2>Title: <?php echo $News->title ?></h2>
<h5>Description: <?php echo $News->description ?></h5>
<p>Preview/Content: <?php echo $News->content ?></p>
<h6>Author: <?php echo $News->author ?></h6>
<h6>Published <?php echo $News->publishedAt ?></h6>
</div>
<?php
}
?>
</div>
</div>
</body>
<?php $this->end(); ?>
我已多次尝试修复此错误,包括测试类似堆栈溢出问题的答案,但都没有结果。经过彻底的搜索,我仍然没有结果,我决定问一个问题。任何帮助表示赞赏
【问题讨论】: