在PHP 5.6.30
上的OSX上运行。我正在尝试从html文件执行脚本,而是下载文件。注意:这不能正常工作,因为html文件应该是.php,但这也是下载而不是打开它。
我试过了:
LoadModule php5_module libexec/apache2/libphp5.so
AddHandler application/x-httpd-php5 .php
添加到/etc/apache2/httpd.conf
sudo /usr/sbin/apachectl restart
)www/script.php
script.php
是否可执行您可以在https://reteps.github.io/website.html
看到它,我只在Google Chrome上进行过测试。
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)
?>
答案 0 :(得分:1)
来自GitHub Pages文档:https://help.github.com/articles/what-is-github-pages/:
GitHub Pages是一个静态站点托管服务,不支持服务器端代码,如PHP,Ruby或Python。