PHP

Problème d'enregistrement dans la base de données

Non Résolu

Bonjour j'ai un souci avec un script qui devrait permettre de d'enregistrer les infos steam dans la base de donné sauf que gros soucis cela fait 3 jours que j'essaye plusieurs chose et rien a faire tous se passe bien lors de la connexion mais pas d'enregistrement dans la base de donné voici le script et j'ai mis se que j'ai a la base de donné:


base de données :


-- Base de données :  `monsite`
--


-- --------------------------------------------------------


--
-- Structure de la table `users_steam`
--


CREATE TABLE `users_steam` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `steamid` varchar(255) NOT NULL,
  `avatar` varchar(500) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
COMMIT;


scrpt steam :


<?php
$username = "root"; 
$password = ""; 
$host = "localhost"; 
$dbname = "monsite";


$db = mysqli_connect($host, $username, $password, $dbname );


if (!$db) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}


require 'openid.php';



$_STEAMAPI = "mon steam api"; //sa ces ok


try {
    $openid = new LightOpenID('/index.php');
    if(!$openid->mode) {
        if(isset($_GET['login'])) {
            $openid->identity = 'http://steamcommunity.com/openid/?l=english';
            header('Location: ' . $openid->authUrl());
        } else {
            echo "<h2>Connect to Steam</h2>";
            echo "<form action='?login' method='post'>";
            echo "<input type='image' src='http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_small.png'>";
            echo "</form>";
        }
    } elseif($openid->mode == 'cancel') {
        echo 'User has canceled authentication!';
    } else {
        if($openid->validate()) {
            $id = $openid->identity;
            $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
            preg_match($ptn, $id, $matches);


            $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$matches";
            $json_object= file_get_contents($url);
            $json_decoded = json_decodemysql_select_db($json_object);//sa marche jusque la aprés sa reviens a ma page index.php


        foreach ($json_decoded->response->players as $player)
        {
                $sql_fetch_id = "SELECT * FROM users_steam WHERE steamid = $player->steamid";
                $query_id = mysqli_query($db, $sql_fetch_id);
                
                $_SESSION['name'] = $player->personaname;
            $_SESSION['steamid'] = $player->steamid;
            $_SESSION['avatar'] = $player->avatar;




                if (mysqli_num_rows($query_id) == 0) {
                    $sql_steam = "INSERT INTO users_steam (name, steamid, avatar) VALUES  ('$player->personaname', '$player->steamid', '$player->avatar')";
                    mysqli_query($db, $sql_steam);
                }
            }
        } else {
                        echo "User is not logged in.\n";
        }
    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}

?>
965 vues
20 janvier 2020 à 20:58 (Édité)
Cette pub permet au site de vivre ...

8 commentaires

Bonsoir @fredoloulou,


Excuse-moi pour le retard de ma suite de réponse.

Est-ce que ton problème a été résolu ?

Si oui, peux-tu le mettre en résolu ?

Si non, peux-tu me rappeler ton problème afin que je regarde de plus près ?


Merci d'avance.

Bonjour fredoloulou,


Dès que je me mets derrière mon ordinateur, j’analyserai ton code et je regarderai pour ton soucis ;)


Pour ce qui est de MySQLi c’est pas qu’il n’est plus utilisable, mais disons que questions de sécurité, effectivement c’est mieux de se mettre au PDO qui est quand même beaucoup plus propre pour les codes puis beaucoup plus sécurisé.


Le MYSQLi reste toute fois utilisable, mais de moins en moins conseillé il me semble (surtout si tu fais les mises à jour des versions de PHP en 7.x.x)

Bonjour @Clouder,

votre collègue @Jerem971 me dit que mysqli n'est plus recommandé je pense du au injection qui peuvent être vu du coup j'ai fabriqué un autre dossier php en PDO que voici n°1,que je veut mettre dans le dossier steamauth.php voir n°2 qui marche avec n°3 et n°4 problème une insertion directe dans la db sa pas de problèmes sa marche des que je met un update pour éviter la répétition sa ne marche plus hors quand je fais le php a par sa marche et en print r j'obtiens bien les sessions

et le dossier index.php n°5

a savoir que je veux mettre mes variables et requêtes dans steamauth.php donc n02 et pas appart


n°5


<?php
    require ('steamauth/steamauth.php'); 
     
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>SteamAuth Demo</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .table {
            table-layout: fixed;
            word-wrap: break-word;
        }
    </style>
  </head>
  <body style="background-color: #EEE;">
    <div class="container" style="margin-top: 30px; margin-bottom: 30px; padding-bottom: 10px; background-color: #FFF;">
        <h1>SteamAuth </h1>
        <span class="small pull-left" style="padding-right: 10px;">for SteamAuth 3.2</span>
        <hr>
        <?php
if(!isset($_SESSION['steamid'])) {
    echo "<div style='margin: 30px auto; text-align: center;'>Welcome Guest! Please log in!<br>";
    loginbutton();
    echo "</div>";
    }  else {
    include ('steamauth/userInfo.php');
    
    ?>  
        <div style='float:left;'>
            <a href=''>
                <button class='btn btn-success' style='margin: 2px 3px;' type='button'>GitHub Repo</button>
            </a>
            <a href=''>
                <button class='btn btn-warning' style='margin: 2px 3px;' type='button'>Download</button>
            </a>
        </div>
        <br>
        <br>
        <h4 style='margin-bottom: 3px; float:left;'>Steam WebAPI-Output:</h4><span style='float:right;'><?php logoutbutton(); ?></span>
        <table class='table table-striped'>
            <tr>
                <td><b>Variable name</b></td>
                <td><b>Value</b></td>
                <td><b>Description</b></td>
            </tr>
            <tr>
                <td>$steamprofile['steamid']</td>
                <td><?=$steamprofile['steamid']?></td>
                <td>SteamID64 of the user</td>
            </tr>
            <tr>
                <td>$steamprofile['communityvisibilitystate']</td>
                <td><?=$steamprofile['communityvisibilitystate']?></td>
                <td>1 - Account not visible; 3 - Account is public (Depends on the relationship of your account to the others)</td>
            </tr>
            <tr>
                <td>$steamprofile['profilestate']</td>
                <td><?=$steamprofile['profilestate']?></td>
                <td>1 - The user has a Steam Community profile; 0 - if not</td>
            </tr>
            <tr>
                <td>$steamprofile['personaname']</td>
                <td><?=$steamprofile['personaname']?></td>
                <td>Public name of the user</td>
            </tr>
            <tr>
                <td>$steamprofile['lastlogoff']</td>
                <td><?=$steamprofile['lastlogoff']?></td>
                <td>
                    <a href='http://www.unixtimestamp.com/' target='_blank'>Unix timestamp</a> of the user's last logoff
                </td>
            </tr>
            <tr>
                <td>$steamprofile['profileurl']</td>
                <td><?=$steamprofile['profileurl']?></td>
                <td>Link to the user's profile</td>
            </tr>
            <tr>
                <td>$steamprofile['personastate']</td>
                <td><?=$steamprofile['personastate']?></td>
                <td>0 - Offline, 1 - Online, 2 - Busy, 3 - Away, 4 - Snooze, 5 - looking to trade, 6 - looking to play</td>
            </tr>
            <tr>
                <td>$steamprofile['realname']</td>
                <td><?=$steamprofile['realname']?></td>
                <td>"Real" name</td>
            </tr>
            <tr>
                <td>$steamprofile['primaryclanid']</td>
                <td><?=$steamprofile['primaryclanid']?></td>
                <td>The ID of the user's primary group</td>
            </tr>
            <tr>
                <td>$steamprofile['timecreated']</td>
                <td><?=$steamprofile['timecreated']?>
                </td>
                <td>
                    <a href='http://www.unixtimestamp.com/' target='_blank'>Unix timestamp</a> for the time the user's account was created
                </td>
            </tr>
            <tr>
                <td>$steamprofile['uptodate']</td>
                <td><?=$steamprofile['uptodate']?></td>
                <td>
                    <a href='http://www.unixtimestamp.com/' target='_blank'>Unix timestamp</a> for the time the user's account information was last updated
                </td>
            </tr>
            <tr>
                <td>$steamprofile['avatar']</td>
                <td>
                    <img src='<?=$steamprofile['avatar']?>'><br>
                    <?=$steamprofile['avatar']?>
                </td>
                <td>Address of the user's 32x32px avatar</td>
            </tr>
            <tr>
                <td>$steamprofile['avatarmedium']</td>
                <td>
                    <img src='<?=$steamprofile['avatarmedium']?>'><br>
                    <?=$steamprofile['avatarmedium']?>
                </td>
                <td>Address of the user's 64x64px avatar</td>
            </tr>
            <tr>
                <td>$steamprofile['avatarfull']</td>
                <td>
                    <img src='<?=$steamprofile['avatarfull']?>'><br>
                    <?=$steamprofile['avatarfull']?>
                </td>
                <td>Address of the user's 184x184px avatar</td>
            </tr>
        </table>
        <?php
        }    
        ?>
        <hr>
        <div class="pull-right">
            <i>This page is powered by <a href="http://steampowered.com">Steam</a></i>
        </div>
        <a href="">GitHub Repo</a><br>
        Demo page by <a href="" target="_blank">BlackCetha</a>
    </div>
    
    <!--Version 4.0--> 
  </body>
</html>


n°4


<?php
//Version 4.0
$steamauth['apikey'] = "xxx"// Your Steam WebAPI-Key found at https://steamcommunity.com/dev/apikey
$steamauth['domainname'] = "localhost"// The main URL of your website displayed in the login page
$steamauth['logoutpage'] = ""// Page to redirect to after a successfull logout (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!
$steamauth['loginpage'] = ""// Page to redirect to after a successfull login (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!

// System stuff
if (empty($steamauth['apikey'])) {die("<div style='display: block; width: 100%; background-color: red; text-align: center;'>SteamAuth:<br>Please supply an API-Key!<br>Find this in steamauth/SteamConfig.php, Find the '<b>\$steamauth['apikey']</b>' Array. </div>");}
if (empty($steamauth['domainname'])) {$steamauth['domainname'] = $_SERVER['SERVER_NAME'];}
if (empty($steamauth['logoutpage'])) {$steamauth['logoutpage'] = $_SERVER['PHP_SELF'];}
if (empty($steamauth['loginpage'])) {$steamauth['loginpage'] = $_SERVER['PHP_SELF'];}
?>


n°3


<?php

                
if (empty($_SESSION['steam_uptodate']) or empty($_SESSION['steam_personaname'])) {
    require 'SteamConfig.php';
    $url = file_get_contents("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamauth['apikey']."&steamids=".$_SESSION['steamid']); 
    $content = json_decode($url, true);
    $_SESSION['steam_steamid'] = $content['response']['players'][0]['steamid'];
    $_SESSION['steam_communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate'];
    $_SESSION['steam_profilestate'] = $content['response']['players'][0]['profilestate'];
    $_SESSION['steam_personaname'] = $content['response']['players'][0]['personaname'];
    $_SESSION['steam_lastlogoff'] = $content['response']['players'][0]['lastlogoff'];
    $_SESSION['steam_profileurl'] = $content['response']['players'][0]['profileurl'];
    $_SESSION['steam_avatar'] = $content['response']['players'][0]['avatar'];
    $_SESSION['steam_avatarmedium'] = $content['response']['players'][0]['avatarmedium'];
    $_SESSION['steam_avatarfull'] = $content['response']['players'][0]['avatarfull'];
    $_SESSION['steam_personastate'] = $content['response']['players'][0]['personastate'];
    if (isset($content['response']['players'][0]['realname'])) { 
           $_SESSION['steam_realname'] = $content['response']['players'][0]['realname'];
       } else {
           $_SESSION['steam_realname'] = "Real name not given";
    }
    $_SESSION['steam_primaryclanid'] = $content['response']['players'][0]['primaryclanid'];
    $_SESSION['steam_timecreated'] = $content['response']['players'][0]['timecreated'];
    $_SESSION['steam_uptodate'] = time();
}

$steamprofile['steamid'] = $_SESSION['steam_steamid'];
$steamprofile['communityvisibilitystate'] = $_SESSION['steam_communityvisibilitystate'];
$steamprofile['profilestate'] = $_SESSION['steam_profilestate'];
$steamprofile['personaname'] = $_SESSION['steam_personaname'];
$steamprofile['lastlogoff'] = $_SESSION['steam_lastlogoff'];
$steamprofile['profileurl'] = $_SESSION['steam_profileurl'];
$steamprofile['avatar'] = $_SESSION['steam_avatar'];
$steamprofile['avatarmedium'] = $_SESSION['steam_avatarmedium'];
$steamprofile['avatarfull'] = $_SESSION['steam_avatarfull'];
$steamprofile['personastate'] = $_SESSION['steam_personastate'];
$steamprofile['realname'] = $_SESSION['steam_realname'];
$steamprofile['primaryclanid'] = $_SESSION['steam_primaryclanid'];
$steamprofile['timecreated'] = $_SESSION['steam_timecreated'];
$steamprofile['uptodate'] = $_SESSION['steam_uptodate'];

// Version 4.0
?>
    


n°2


<?php
ob_start();
session_start();
     
function logoutbutton() {
    echo "<form action='' method='get'><button name='logout' type='submit'>Logout</button></form>"//logout button
}

function loginbutton($buttonstyle = "square") {
    $button['rectangle'] = "01";
    $button['square'] = "02";
    $button = "<a href='?login'><img src='https://steamcommunity-a.akamaihd.net/public/images/signinthroughsteam/sits_".$button[$buttonstyle].".png'></a>";
    
    echo $button;
}

if (isset($_GET['login'])){
    require 'openid.php';
    try {
        require 'SteamConfig.php';
        $openid = new LightOpenID($steamauth['domainname']);
        
        if(!$openid->mode) {
            $openid->identity = 'https://steamcommunity.com/openid';
            header('Location: ' . $openid->authUrl());
        } elseif ($openid->mode == 'cancel') {
            echo 'User has canceled authentication!';
        } else {
            if($openid->validate()) { 
                $id = $openid->identity;
                $ptn = "/^https?:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
                
                preg_match($ptn, $id, $matches);
                 
                $_SESSION['steamid'] = $matches[1];
 
                if (!headers_sent()) {
                    header('Location: '.$steamauth['loginpage']);
                    
                } else {
                    ?>
                    <script type="text/javascript">
                        window.location.href="<?=$steamauth['loginpage']?>";
                    </script>
                    <noscript>
                        <meta http-equiv="refresh" content="0;url=<?=$steamauth['loginpage']?>" />
                    </noscript>
                    <?php
                    
                }
            } else {
                echo "User is not logged in.\n";
            }
            
        }
    } catch(ErrorException $e) {
        echo $e->getMessage();
    }
     
}


if (isset($_GET['logout'])){
    require 'SteamConfig.php';
    session_unset();
    session_destroy();
    header('Location: '.$steamauth['logoutpage']);
    exit;
}

if (isset($_GET['update'])){
    unset($_SESSION['steam_uptodate']);
    require 'userInfo.php';
    header('Location: '.$_SERVER['PHP_SELF']);
    exit;
}

// Version 4.0

?>


n°1


<?php
    require ('steamauth.php');
    # You would uncomment the line beneath to make it refresh the data every time the page is loaded
    // unset($_SESSION['steam_uptodate']);
 
    try
    {
        // On se connecte a la base de donnée
        $bdd = new PDO("mysql:host=localhost;dbname=monsite;charset=utf8""root""",array());
    }
    catch(Exception $e)
    {
        // En cas d'erreur, on affiche un message et on arrête tout
            die('Erreur : '.$e->getMessage());
    }
        // Mise a jour des info de l'utilisateur
    include ('userInfo.php');      
 
    if (isset($_SESSION['steamid'])) { /* L'utilisateur est connecté grâce à son compte steam */ /* On cherche s'il a déjà une ligne dans la bdd */
        $reqname = $bdd->prepare("SELECT * FROM users_steam WHERE steamid = ?");
        $reqname->execute(array($_SESSION['steamid']));
        $nameexist = $reqname->rowCount();
        $type = "account";
 
        if (isset($_SESSION["name"])) {
            $req = $bdd->prepare("UPDATE users_steam SET name = :name WHERE url = :url");
            $req->bindParam(":name",$steamprofile['realname'],PDO::PARAM_STR);
            $req->bindParam(":url",$steamprofile['profileurl'],PDO::PARAM_STR);
            $req->execute();
        }
        
        else { /* Première connexion du membre */ /* On l'insert dans la base de données */
            $reqInsert = $bdd->prepare('INSERT INTO users_steam(steamid, name, url)VALUES (:steamid, :name, :url)');
  
        $reqInsert->execute([
            ':steamid' => $steamprofile['steamid'],
            ':url' => $steamprofile['realname'],
            ':profile' => $steamprofile['profileurl'],
        ]);
        }
    }   
?>


donc non sur le dernier topic que j'ai posté je n'obtiens aucune réponse en db car

ceci récupère bien


$DB->insert("INSERT INTO users_steam (steamid, name, lien) VALUES ('" . $_SESSION['steamid'] . "','" . $_SESSION['steam_realname'] . "','" . $_SESSION['steam_profileurl'] . "')");


ceci ne veut rien dire et sert a rien


 $req=$DB->query("SELECT * FROM users_steam WHERE steamid = ('" . $_SESSION['steamid'] . "')");
    
                $req=$req->fetch();
                
                if ($req<> "") {
                    $valid = true;
                }

@fredoloulou,


Tu obtiens une erreur ou ta variable ne récupère rien ?

donc après avoir fait un gros echec je suis arrivé a recupere le steam id dans la base mais il me recupere pas le name et le lien voici le script en plusieur partie


SteamConfig.php


<?php
//Version 4.0
$steamauth['apikey'] = "clef api"// Your Steam WebAPI-Key found at https://steamcommunity.com/dev/apikey
$steamauth['domainname'] = "localhost"// The main URL of your website displayed in the login page
$steamauth['logoutpage'] = ""// Page to redirect to after a successfull logout (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!
$steamauth['loginpage'] = ""// Page to redirect to after a successfull login (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!

// System stuff
if (empty($steamauth['apikey'])) {die("<div style='display: block; width: 100%; background-color: red; text-align: center;'>SteamAuth:<br>Please supply an API-Key!<br>Find this in steamauth/SteamConfig.php, Find the '<b>\$steamauth['apikey']</b>' Array. </div>");}
if (empty($steamauth['domainname'])) {$steamauth['domainname'] = $_SERVER['SERVER_NAME'];}
if (empty($steamauth['logoutpage'])) {$steamauth['logoutpage'] = $_SERVER['PHP_SELF'];}
if (empty($steamauth['loginpage'])) {$steamauth['loginpage'] = $_SERVER['PHP_SELF'];}
?>


index.php


<?php

    require ('steamauth/steamauth.php');  



  ?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>SteamAuth Demo</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .table {
            table-layout: fixed;
            word-wrap: break-word;
        }
    </style>
  </head>
  <body style="background-color: #EEE;">
    <div class="container" style="margin-top: 30px; margin-bottom: 30px; padding-bottom: 10px; background-color: #FFF;">
        <h1>SteamAuth Demo</h1>
        <span class="small pull-left" style="padding-right: 10px;">for SteamAuth 3.2</span>
        <hr>
        <?php
if(!isset($_SESSION['steamid'])) {
    echo "<div style='margin: 30px auto; text-align: center;'>Welcome Guest! Please log in!<br>";
    loginbutton();
    echo "</div>";
    }  else {
    include ('steamauth/userInfo.php');
    ?>
        <form method="post">
        <div style='float:left;'>
            <a href='https://github.com/SmItH197/SteamAuthentication'>
                <button class='btn btn-success' style='margin: 2px 3px;' type='button'>GitHub Repo</button>
            </a>
            <a href='https://github.com/SmItH197/SteamAuthentication/releases'>
                <button class='btn btn-warning' style='margin: 2px 3px;' type='button'>Download</button>
            </a>
        </div>
        <br>
        <br>
        <h4 style='margin-bottom: 3px; float:left;'>Steam WebAPI-Output:</h4><span style='float:right;'><?php logoutbutton(); ?></span>
        <table class='table table-striped'>
            <tr>
                <td><b>Variable name</b></td>
                <td><b>Value</b></td>
                <td><b>Description</b></td>
            </tr>
            <tr>
                <td>$steamprofile['steamid']</td>
                <td><?=$steamprofile['steamid']?></td>
                <td>SteamID64 of the user</td>
            </tr>
            <tr>
                <td>$steamprofile['communityvisibilitystate']</td>
                <td><?=$steamprofile['communityvisibilitystate']?></td>
                <td>1 - Account not visible; 3 - Account is public (Depends on the relationship of your account to the others)</td>
            </tr>
            <tr>
                <td>$steamprofile['profilestate']</td>
                <td><?=$steamprofile['profilestate']?></td>
                <td>1 - The user has a Steam Community profile; 0 - if not</td>
            </tr>
            <tr>
                <td>$steamprofile['personaname']</td>
                <td><?=$steamprofile['personaname']?></td>
                <td>Public name of the user</td>
            </tr>
            <tr>
                <td>$steamprofile['lastlogoff']</td>
                <td><?=$steamprofile['lastlogoff']?></td>
                <td>
                    <a href='http://www.unixtimestamp.com/' target='_blank'>Unix timestamp</a> of the user's last logoff
                </td>
            </tr>
            <tr>
                <td>$steamprofile['profileurl']</td>
                <td><?=$steamprofile['profileurl']?></td>
                <td>Link to the user's profile</td>
            </tr>
            <tr>
                <td>$steamprofile['personastate']</td>
                <td><?=$steamprofile['personastate']?></td>
                <td>0 - Offline, 1 - Online, 2 - Busy, 3 - Away, 4 - Snooze, 5 - looking to trade, 6 - looking to play</td>
            </tr>
            <tr>
                <td>$steamprofile['realname']</td>
                <td><?=$steamprofile['realname']?></td>
                <td>"Real" name</td>
            </tr>
            <tr>
                <td>$steamprofile['primaryclanid']</td>
                <td><?=$steamprofile['primaryclanid']?></td>
                <td>The ID of the user's primary group</td>
            </tr>
            <tr>
                <td>$steamprofile['timecreated']</td>
                <td><?=$steamprofile['timecreated']?>
                </td>
                <td>
                    <a href='http://www.unixtimestamp.com/' target='_blank'>Unix timestamp</a> for the time the user's account was created
                </td>
            </tr>
            <tr>
                <td>$steamprofile['uptodate']</td>
                <td><?=$steamprofile['uptodate']?></td>
                <td>
                    <a href='http://www.unixtimestamp.com/' target='_blank'>Unix timestamp</a> for the time the user's account information was last updated
                </td>
            </tr>
            <tr>
                <td>$steamprofile['avatar']</td>
                <td>
                    <img src='<?=$steamprofile['avatar']?>'><br>
                    <?=$steamprofile['avatar']?>
                </td>
                <td>Address of the user's 32x32px avatar</td>
            </tr>
            <tr>
                <td>$steamprofile['avatarmedium']</td>
                <td>
                    <img src='<?=$steamprofile['avatarmedium']?>'><br>
                    <?=$steamprofile['avatarmedium']?>
                </td>
                <td>Address of the user's 64x64px avatar</td>
            </tr>
            <tr>
                <td>$steamprofile['avatarfull']</td>
                <td>
                    <img src='<?=$steamprofile['avatarfull']?>'><br>
                    <?=$steamprofile['avatarfull']?>
                </td>
                <td>Address of the user's 184x184px avatar</td>
            </tr>
        </table>
        <?php
        }    
        ?>
        <hr>
        <div class="pull-right">
            <i>This page is powered by <a href="http://steampowered.com">Steam</a></i>
        </div>
        <a href="https://github.com/SmItH197/SteamAuthentication">GitHub Repo</a><br>
        Demo page by <a href="https://github.com/blackcetha" target="_blank">BlackCetha</a>
    </div>
    </form>
    <!--Version 4.0--> 
  </body>
</html>


userinfo.php


<?php
if (empty($_SESSION['steam_uptodate']) or empty($_SESSION['steam_personaname'])) {
    require 'SteamConfig.php';
    $url = file_get_contents("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamauth['apikey']."&steamids=".$_SESSION['steamid']); 
    $content = json_decode($url, true);
    $_SESSION['steam_steamid'] = $content['response']['players'][0]['steamid'];
    $_SESSION['steam_communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate'];
    $_SESSION['steam_profilestate'] = $content['response']['players'][0]['profilestate'];
    $_SESSION['steam_personaname'] = $content['response']['players'][0]['personaname'];
    $_SESSION['steam_lastlogoff'] = $content['response']['players'][0]['lastlogoff'];
    $_SESSION['steam_profileurl'] = $content['response']['players'][0]['profileurl'];
    $_SESSION['steam_avatar'] = $content['response']['players'][0]['avatar'];
    $_SESSION['steam_avatarmedium'] = $content['response']['players'][0]['avatarmedium'];
    $_SESSION['steam_avatarfull'] = $content['response']['players'][0]['avatarfull'];
    $_SESSION['steam_personastate'] = $content['response']['players'][0]['personastate'];
    if (isset($content['response']['players'][0]['realname'])) { 
           $_SESSION['steam_realname'] = $content['response']['players'][0]['realname'];
       } else {
           $_SESSION['steam_realname'] = "Real name not given";
    }
    $_SESSION['steam_primaryclanid'] = $content['response']['players'][0]['primaryclanid'];
    $_SESSION['steam_timecreated'] = $content['response']['players'][0]['timecreated'];
    $_SESSION['steam_uptodate'] = time();
}

$steamprofile['steamid'] = $_SESSION['steam_steamid'];
$steamprofile['communityvisibilitystate'] = $_SESSION['steam_communityvisibilitystate'];
$steamprofile['profilestate'] = $_SESSION['steam_profilestate'];
$steamprofile['personaname'] = $_SESSION['steam_personaname'];
$steamprofile['lastlogoff'] = $_SESSION['steam_lastlogoff'];
$steamprofile['profileurl'] = $_SESSION['steam_profileurl'];
$steamprofile['avatar'] = $_SESSION['steam_avatar'];
$steamprofile['avatarmedium'] = $_SESSION['steam_avatarmedium'];
$steamprofile['avatarfull'] = $_SESSION['steam_avatarfull'];
$steamprofile['personastate'] = $_SESSION['steam_personastate'];
$steamprofile['realname'] = $_SESSION['steam_realname'];
$steamprofile['primaryclanid'] = $_SESSION['steam_primaryclanid'];
$steamprofile['timecreated'] = $_SESSION['steam_timecreated'];
$steamprofile['uptodate'] = $_SESSION['steam_uptodate'];

// Version 4.0
?>


steamauth.php


<?php
ob_start();
session_start();

include('bd/connexionDB.php'); // Fichier PHP contenant la connexion à votre BDD



    

function logoutbutton() {
    echo "<form action='' method='get'><button name='logout' type='submit'>Logout</button></form>"//logout button
}

function loginbutton($buttonstyle = "square") {
    $button['rectangle'] = "01";
    $button['square'] = "02";
    $button = "<a href='?login'><img src='https://steamcommunity-a.akamaihd.net/public/images/signinthroughsteam/sits_".$button[$buttonstyle].".png'></a>";
    
    echo $button;
}

if (isset($_GET['login'])){
    
    require 'openid.php';
    
    try {
        require 'SteamConfig.php';
        $openid = new LightOpenID($steamauth['domainname']);
        
        if(!$openid->mode) {
            $openid->identity = 'https://steamcommunity.com/openid';
            header('Location: ' . $openid->authUrl());
        } elseif ($openid->mode == 'cancel') {
            echo 'User has canceled authentication!';
        } else {
            if($openid->validate()) { 
                $id = $openid->identity;
                $ptn = "/^https?:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
                preg_match($ptn, $id, $matches);
                
                $_SESSION['steamid'] = $matches[1]; 
            
                $_SESSION['steam_realname'] = $matches[2];  
            
                $_SESSION['steam_profileurl'] = $matches[3];
                $req=$DB->query("SELECT * FROM users_steam WHERE steamid = ('" . $_SESSION['steamid'] . "')");
    
                $req=$req->fetch();
                
                if ($req<> "") {
                    $valid = true;
                }
       $DB->insert("INSERT INTO users_steam (steamid, name, lien) VALUES ('" . $_SESSION['steamid'] . "','" . $_SESSION['steam_realname'] . "','" . $_SESSION['steam_profileurl'] . "')");
                if (!headers_sent()) {
                    header('Location: '.$steamauth['loginpage']);
                    exit;
                } else {
                    ?>
                    <script type="text/javascript">
                        window.location.href="<?=$steamauth['loginpage']?>";
                    </script>
                    <noscript>
                        <meta http-equiv="refresh" content="0;url=<?=$steamauth['loginpage']?>" />
                    </noscript>
                    <?php
                    exit;
                }
                
            } else {
                echo "User is not logged in.\n";
            }
        }
    } catch(ErrorException $e) {
        echo $e->getMessage();
    }
}

if (isset($_GET['logout'])){
    require 'SteamConfig.php';
    session_unset();
    session_destroy();
    header('Location: '.$steamauth['logoutpage']);
    exit;
}

if (isset($_GET['update'])){
    unset($_SESSION['steam_uptodate']);
    require 'userInfo.php';
    header('Location: '.$_SERVER['PHP_SELF']);
    exit;
}

// Version 4.0

?>

Re:


@fredoloulou, quand tu auras appliquer ton code avec PDO et si tu as un problème avec celui-ci tu peux poster sur le topic 😉

Si tu n'as plus de problème, tu peux mettre alors en "Résolu" 😁

ok je vois donc la boucle est bonne le reste ne marche plus donc je vai mettre en PDO merci de votre aide précieuse


$_SESSION['name'] = $player->personaname;
            $_SESSION['steamid'] = $player->steamid;
            $_SESSION['avatar'] = $player->avatar;

Hello @fredoloulou,


Tu utilises MySQLI, il n'est plus recommandé de l'utiliser...

Il est recommandé d'utiliser PDO, consulte ça ou ça 😉

Cette pub permet au site de vivre ...