Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/projects/

bacon-egg-pizza.php
cquiz.php
create-account.php
create-account111.php
create-quiz.php
create-quiz2.php
createaccount.php
delete-quiz.php
drop-rps-tables.php
legacy-code-rps.php
legacy-index.php
login.php
logincheck.php
newpassword-verify.php
newpassword.php
potential-code.txt
quiz-db-init.php
quizhub.php
quizhub2.php
results.php
rpsaccount-ajax-user-search.php
rpsaccount.php
rpsbetting-ajax-match-finder.php
rpsbetting.php
rpsbettingleaderboard.php
rpschangepassword.php
rpschangepassword.txt
rpsgame-ajax.php
rpsgame.php
rpsgameresults.php
rpshostnewgame.php
rpshub.php
rpsleaderboard.php
rpslib.php
rpslogin.php
rpsmaininclude.php
rpsproject/
rpsusersearch.php
table-init.php
verification.php

rpsgame-ajax.php

105 lines UTF-8 Windows (CRLF)
<?php require("../incl/dbconnection.php");

if(isset(
$_GET['matchkey']) AND isset($_GET['currentround'])){
    if (!isset(
$_GET['currentround'])) {
        echo 
"Error: round not set.";
    }
    
checkMoveStatusV1V2($dbconn,
    
htmlspecialchars($_GET['matchkey'], ENT_QUOTES'UTF-8'),
    
$_GET['currentround']);
}


function 
checkMoveStatusV1V2($dbconn,$matchkey,$currentround){
    
$sql "SELECT 
        m.matchid, 
        m.player1id, 
        m.player2id, 
        u1.userid AS p1id, 
        u2.userid AS p2id, 
        u1.rps AS u1move,
        u2.rps AS u2move
        FROM matches AS m
        INNER JOIN moves AS u1 ON m.player1id = u1.userid
        INNER JOIN moves AS u2 ON m.player2id = u2.userid
        WHERE matchid = ?"
;
    
$stmt $dbconn->prepare($sql);
    
$data=[$matchkey];
    
$stmt->execute($data);
    while(
$res $stmt->fetch(PDO::FETCH_ASSOC)){
        
//echo $res[];
    
}
    
$sql "SELECT COUNT(*) AS total FROM moves WHERE matchkey = ? AND round = ?";
    
$stmt $dbconn->prepare($sql);
    
$stmt->execute([$matchkey$currentround]);
    while(
$res $stmt->fetch(PDO::FETCH_ASSOC)){
        if(
$res['total']==2){
            
$sql="SELECT * FROM moves WHERE matchkey=? AND round=? /*AND NOT userid=?*/";
            
$stmt $dbconn->prepare($sql);
            
$data=[$matchkey,$currentround/*,$_SESSION['userid']*/];
            
$stmt->execute($data);
            while(
$res $stmt->fetch(PDO::FETCH_ASSOC)){
                if(
$res['userid']!=$_SESSION['userid']){
                    echo 
"opponent: ".$res['rps'].'<br>';
                }
                else if(
$res['userid']==$_SESSION['userid']){
                    echo 
"your move: ".$res['rps']."<br>";
                }
            }
        }
        else if(
$res['total']==1){
            echo 
"waiting for opponent or you";
        }
        else if(
$res['total']==0){
            echo 
"waiting for your move<br>";
        }
        
$sql="SELECT roundAmount FROM matches WHERE matchid = ?";
        
$stmt $dbconn->prepare($sql);
        
$stmt->execute([$matchkey]);
        while(
$res $stmt->fetch(PDO::FETCH_ASSOC)){
            if(
$res['roundAmount']==$currentround){
                
header("Location:rpsgameresults.php?matchkey=$matchkey");
                
$_SESSION['isInGame'] = false;
                exit;
            }
        }
        echo 
"<hr><strong>hela matchen:</strong><br>";

        
$currentmaxround 1;
        
$sql "SELECT round FROM moves WHERE matchkey = ? ORDER BY round DESC LIMIT 1";
        
$stmt $dbconn->prepare($sql);
        
$stmt->execute([$matchkey]);
        if(
$res=$stmt->fetch(PDO::FETCH_ASSOC)){
            
$currentmaxround=$res['round'];
        }

        
//get matchinfo
        
$sql "SELECT round, userid, rps FROM moves WHERE matchkey = ? ORDER BY round ASC, userid ASC";
        
$stmt $dbconn->prepare($sql);
        
$stmt->execute([$matchkey]);


        
$hasmademove=false;
        
$currentround = -1;
        while (
$move $stmt->fetch(PDO::FETCH_ASSOC)){
            
// New round header
            
if ($currentround != $move['round']) {
                
$currentround $move['round'];
                echo 
"<br>Round $currentround:<br>";
            }

            (int)
$currentround;
            
$matchoutput="";
            
// Identify if it's the current user or opponent
            
if ($move['userid'] == $_GET['userid']) {
                
$matchoutput .= "Du: ".$move['rps']."<br>";
            } 
            else if (
$currentround>=AND $currentround!=$currentmaxround){
                
$matchoutput .= "Motståndare: ".$move['rps']."<br>";
            }
            
//echo "$matchoutput: ".$move['rps']."<br>";
            
echo $matchoutput;
        }
    }
}
?>