Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- ?>
- <!DOCTYPE html>
- <html>
- <body>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $database = "quiz";
- $conn = mysqli_connect($servername, $username, $password, $database);
- $username = $_POST['usr'];
- $password = $_POST['pswd'];
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- //echo "Failed connection";
- }
- function shufflePath(&$array)
- {
- $keys = array_keys($array);
- shuffle($keys);
- foreach ($keys as $key) {
- $new[$key] = $array[$key];
- }
- $array = $new;
- return true;
- }
- function save_image($img, $fullpath)
- {
- $ch = curl_init($img);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
- $rawdata = curl_exec($ch);
- curl_close($ch);
- if (file_exists($fullpath)) {
- unlink($fullpath);
- }
- $fp = fopen($fullpath, 'x');
- fwrite($fp, $rawdata);
- fclose($fp);
- }
- // login button
- if (isset($_POST['log'])) {
- $_SESSION['username'] = $_POST['usr'];
- $_SESSION['password'] = $_POST['pswd'];
- // sql login code here
- header("Location: theme.php");
- }
- // Sign up button
- if (isset($_POST['sign'])) {
- echo "sign";
- $sql = "INSERT INTO users (username, password) VALUES ('$username', '$password')";
- //echo "log<br>";
- if ($conn->query($sql) === TRUE) {
- //echo "New record created successfully";
- } else {
- //echo "Error: " . $sql . "<br>" . $conn->error;
- }
- }
- if (isset($_POST['theme'])) {
- $_SESSION['backgroundURL'] = none;
- $_SESSION['theme'] = $_POST['thm'];
- $curl = curl_init();
- $searchstring = "{$_SESSION['theme']} background";
- $url = "https://www.bing.com/images/search?q=" . str_replace(" ", "%20", $searchstring) . "&qs=n&form=QBIR&qft=%20filterui%3Aimagesize-wallpaper&sp=-1&pq=" . str_replace(" ", "%20", $searchstring) . "&sc=8-20&sk=&cvid=1A7214553B3B41DDAA03F66B890ACB14";
- //retrieve images from bing search for the $searchstring provided above
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- $result = curl_exec($curl);
- curl_close($curl);
- /*finds the url for each image, the first string(<a class="thumb" target="_blank" href="(.*?))
- is what comes before every image url, so we use that to find and isolate the url
- */
- preg_match_all('!<a class="thumb" target="_blank" href="(.*?)"!', $result, $url_matches);
- $images = array_values(array_unique($url_matches[1]));
- $_SESSION['backgroundURL'] = $images[0];
- header("Location: character.php");
- }
- if (isset($_POST['name'])) {
- $_SESSION['name1'] = $_POST['name1'];
- $_SESSION['name2'] = $_POST['name2'];
- $_SESSION['name3'] = $_POST['name3'];
- $_SESSION['name4'] = $_POST['name4'];
- header("Location: questions.php");
- }
- if (isset($_POST['quest'])) {
- $_SESSION['question1'] = $_POST['question1'];
- $_SESSION['question2'] = $_POST['question2'];
- $_SESSION['question3'] = $_POST['question3'];
- $_SESSION['question4'] = $_POST['question4'];
- $_SESSION['question5'] = $_POST['question5'];
- header("Location: answer1.php");
- }
- if (isset($_POST['ans1'])) {
- $_SESSION['answer1for1'] = $_POST['answer1'];
- $_SESSION['answer2for1'] = $_POST['answer2'];
- $_SESSION['answer3for1'] = $_POST['answer3'];
- $_SESSION['answer4for1'] = $_POST['answer4'];
- header("Location: answer2.php");
- }
- if (isset($_POST['ans2'])) {
- $_SESSION['answer1for2'] = $_POST['answer1'];
- $_SESSION['answer2for2'] = $_POST['answer2'];
- $_SESSION['answer3for2'] = $_POST['answer3'];
- $_SESSION['answer4for2'] = $_POST['answer4'];
- header("Location: answer3.php");
- }
- if (isset($_POST['ans3'])) {
- $_SESSION['answer1for3'] = $_POST['answer1'];
- $_SESSION['answer2for3'] = $_POST['answer2'];
- $_SESSION['answer3for3'] = $_POST['answer3'];
- $_SESSION['answer4for3'] = $_POST['answer4'];
- header("Location: answer4.php");
- }
- if (isset($_POST['ans4'])) {
- $_SESSION['answer1for4'] = $_POST['answer1'];
- $_SESSION['answer2for4'] = $_POST['answer2'];
- $_SESSION['answer3for4'] = $_POST['answer3'];
- $_SESSION['answer4for4'] = $_POST['answer4'];
- header("Location: answer5.php");
- }
- if (isset($_POST['ans5'])) {
- $_SESSION['answer1for5'] = $_POST['answer1'];
- $_SESSION['answer2for5'] = $_POST['answer2'];
- $_SESSION['answer3for5'] = $_POST['answer3'];
- $_SESSION['answer4for5'] = $_POST['answer4'];
- header("Location: ready.php");
- }
- if (isset($_POST['readyYes'])) {
- $questionTrav = array(
- "takeQuizQ1.php",
- "takeQuizQ2.php",
- "takeQuizQ3.php",
- "takeQuizQ4.php",
- "takeQuizQ5.php"
- );
- $_SESSION['qTraversal'] = 0;
- $_SESSION['resultChr1'] = 0;
- $_SESSION['resultChr2'] = 0;
- $_SESSION['resultChr3'] = 0;
- $_SESSION['resultChr4'] = 0;
- shuffle($questionTrav);
- $_SESSION['shuffledarray'] = $questionTrav;
- $_SESSION['shuffledarray'][5] = "processResult.php";
- header("Location: " . $_SESSION['shuffledarray'][$_SESSION['qTraversal']]);
- }
- if (isset($_POST['readyNo'])) {
- header("Location: edit.php");
- }
- if (isset($_POST['chooseChar1'])) {
- $_SESSION['qTraversal']++;
- $_SESSION['resultChr1']++;
- header("Location: " . $_SESSION['shuffledarray'][$_SESSION['qTraversal']]);
- }
- if (isset($_POST['chooseChar2'])) {
- $_SESSION['qTraversal']++;
- $_SESSION['resultChr2']++;
- header("Location: " . $_SESSION['shuffledarray'][$_SESSION['qTraversal']]);
- }
- if (isset($_POST['chooseChar3'])) {
- $_SESSION['qTraversal']++;
- $_SESSION['resultChr3']++;
- header("Location: " . $_SESSION['shuffledarray'][$_SESSION['qTraversal']]);
- }
- if (isset($_POST['chooseChar4'])) {
- $_SESSION['qTraversal']++;
- $_SESSION['resultChr4']++;
- header("Location: " . $_SESSION['shuffledarray'][$_SESSION['qTraversal']]);
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement