My page has no code but there is php code in index.php

Hi,
My website is accessible and it finds my page but not my code.
For an example, my index.php isn’t empty at all but i just find a white page with nothing.
I dont understand why. My website is : strong text
Thank you,
Halfade

maybe your code doesnt work?

It works on my localhost. And if it doesn’t work, it should send an error at least…

well ig your code dont like IF hosting lol

So how do i fix this problem ? Is it because i have the free version ?

1 Like

First thing I’d try it reuploading your index.php, to make sure it didn’t get corrupted during the upload.

Secondly, is the inedex.php file in the root of the htdocs folder?

Have you added any custome .htaccess rules?

I have reuploaded my index.php file, but it still doesn’t work. It’s in the htdocs folder and my .htaccess file isn’t custom. There is just :
php_value display_errors On
php_value mbstring.http_input auto
php_value date.timezone Europe/Paris

I don’t suppose you’d be willing to share the php code?

Because PHP is executed server side, it sounds like for some reason theres no output being generated.

4 Likes

This is an high school project, so it doesn’t matter :
Here is my index.php code :

<?php
include 'database.php';
include 'navigateur.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/styles-sidebar.css">
    <link rel="stylesheet" href="css/styles.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200">
    <link rel="icon" type="image/png" href="img/fav-epee.png"/>
    <script src="scripts/send_request.js" defer></script>
    <title>KHAOS | Page principale</title>
</head>
<body id="body_pp">
    <!-- Informations du matchmaking / Bandeau de la partie -->
    <div class="in_queue">
        <h2 class="nb_players">0/8</h2>
        <h3>En attente de joueurs...</h3>
    </div>
    <!-- Bouton Jouer -->
    <button class="play" onclick="p = play(p);">Jouer</button>
</body>
<script>
// Quand le bouton "jouer" est cliqué : 
function play(p){
    // Envoyer dans une autre base avec les joueurs
    // Si le joueur est libre (il n'est pas dans une partie) :
    if (p == 1) {
        p = 0
        send_request("enregistrer");
        document.querySelector(".play").innerHTML = "Annuler";
        document.querySelector(".in_queue").style.display = "inherit";
        document.querySelector(".sidebar").style.display = "none";
        interval_id_show_players = setInterval(function () {
            send_request("check_nb_players");
        }, 500);
    }else{
        var p = 1
        send_request("enregistrer");
        document.querySelector(".play").innerHTML = "Jouer";
        document.querySelector(".sidebar").style.display = "flex";
        clearInterval(interval_id_show_players);
        document.querySelector(".in_queue").style.display = "none";
    }
    return p;
}

// Si le joueur quitte la page :
window.addEventListener("beforeunload", function (e) {
        if (p == 0) {
        // Retirer de l'inscription (et prévenir) :
        e.preventDefault();
        e.returnValue = '';
        send_request("enregistrer"); 
    }
});
</script>
<?php
// Si le joueur est libre : p = 1, sinon p = 0
echo "<script>var p = ".$_SESSION["is_free"].";</script>";
// Si p = 0, on met le bouton "Jouer" en "Annuler" car le joueur est déja dans une partie
if ($_SESSION["is_free"] == 0) {
    echo "<script>document.querySelector('.play').innerHTML = 'Annuler';
        document.querySelector('.in_queue').style.display = 'inherit';
        interval_id_show_players = setInterval(function () {
            send_request('check_nb_players');
        }, 1000);</script>";
}
?>
</html>

Couple of potential errors I can see, but they may be handed in one of:
include ‘database.php’;
include ‘navigateur.php’;

Your using $_SESSION["is_free"], but don’t seem to be starting the session with session_start anywhere

this may also result in var p in your javascript not being set properly. which might cause it to fall over.

other than that, I’m stumped

6 Likes

Thank you ! I fixed my problem ! It was because my username/password wasn’t correct in my database.php file.

ah… that’ll do it haha.

Glad you fixed it :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.