【问题标题】:Downloads file instead of executing下载文件而不是执行
【发布时间】:2017-12-16 06:07:09
【问题描述】:

在 OSX 上运行,PHP 5.6.30。我正在尝试从 html 文件执行脚本,然后它会下载该文件。注意:这不起作用,因为 html 文件应该是 .php,但这也是下载而不是打开它。

我试过了:

  • 取消注释LoadModule php5_module libexec/apache2/libphp5.so
  • AddHandler application/x-httpd-php5 .php 添加到/etc/apache2/httpd.conf
  • 重启 apache (sudo /usr/sbin/apachectl restart)
  • 将我的文件移动到www/script.php
  • 检查script.php 是否可执行

你可以在https://reteps.github.io/website.html看到它,我只在谷歌浏览器上测试过。

HTML(应为 .php)

<!doctype html>
<html>
  <head>
    <title>

    </title>
    <link rel="stylesheet" type="text/css" href="navbar.css">
  </head>
  <body>

    <div id="menu">
        <a href="index.html">Home</a>
        <a href="https://github.com/reteps">Github</a>
        <a href="school.html">School Projects</a>
        <a href="side.html" >Side Projects</a>
        <a href="blog.html">Blog</a>
      </div>
  <form action="www/script.php" method="get">
    <input type="text" name="quizid" placeholder="kahoot id">
    <input type="submit" value="Go">
  </form>
  <p id="output">Nothing yet...</p>
  </body>
</html>

PHP

#!/usr/bin/php
<?php
$username = 'USERNAME@gmail.com';
$password = 'PASSWORD';
$loginUrl = 'https://create.kahoot.it/rest/authenticate';
$kahootId = htmlentities($_GET['quizid']);
$pageUrl = 'https://create.kahoot.it/rest/kahoots/' . $kahootId;

$loginheader = array(); 
$loginheader[] = 'content-type: application/json';
$loginpost = new stdClass();
$loginpost->username = $username;
$loginpost->password = $password;
$loginpost->grant_type = "password";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($loginpost));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER,$loginheader);
$store = curl_exec($ch);
curl_close($ch);
$token = json_decode($store,true)["access_token"];

//get questions
$quizheader = array(); 
$quizheader[] = 'authorization: ' . $token;
$options = array(
    'http' => array(
        'method'  => 'GET',
        'header'  => "Authorization: ".$token."\r\n"
    )   
);

$context = stream_context_create($options);
$raw_result = file_get_contents($pageUrl, false, $context);
$result = json_decode($raw_result,true)["questions"];
$myoutput = $_POST['output'];
header( "Location: website.html?output=$myoutput" );
print_r($result)
?>

【问题讨论】:

    标签: php html apache php-5.6


    【解决方案1】:

    来自 GitHub Pages 文档:https://help.github.com/articles/what-is-github-pages/

    GitHub Pages 是一种静态站点托管服务,不支持 PHP、Ruby 或 Python 等服务器端代码。

    【讨论】:

      猜你喜欢
      • 2017-11-16
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 2016-03-18
      • 2019-07-21
      • 2011-12-26
      相关资源
      最近更新 更多