Sous OSX, sur PHP 5.6.30
. J'essaie d'exécuter un script à partir d'un fichier html, et il télécharge le fichier à la place. NOTE: ceci ne fonctionne pas correctement car le fichier html devrait être .php, mais c'est aussi le téléchargement au lieu de l'ouvrir.Télécharge le fichier au lieu d'exécuter
J'ai essayé:
- décommentant
LoadModule php5_module libexec/apache2/libphp5.so
- ajouter
AddHandler application/x-httpd-php5 .php
à/etc/apache2/httpd.conf
- redémarrer apache (
sudo /usr/sbin/apachectl restart
) - déplacer mon fichier à
www/script.php
- la vérification que
script.php
est exécutable
Vous pouvez le voir au https://reteps.github.io/website.html
, et j'ai seulement testé sur Google Chrome.
HTML (devrait être .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 = '[email protected]';
$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)
?>