mardi 28 août 2018

Mysterious PHP Function execution [duplicate]

This question already has an answer here:

First I will show only a part of my code,

index.html

<html>
<body>
    <?php require "PHP/music_lists.php"; ?>
    <script>
        var music = document.createElement('audio');
        music.src = 'data:audio/mp3;base64,<?php echo base64_encode(file_get_contents($current_music));?>';
        music.muted = false;
        function media_next_button_pressed() {
                document.getElementById("music-elapsed").value = 0;
                music.ontimeupdate = null;
                music.src = 'data:audio/mp3;base64,<?php getNextMusic();echo base64_encode(file_get_contents($current_music));?>';
                music.load();
                music.play();
                music.ontimeupdate = progressUpdate;
                document.getElementById('music-player-mini').getElementsByClassName('media-play-button')[0].style.background = 'url("../IMGS/pause-button.svg")'
        }
    </script>
    <button class='media-next-button' onclick="media_next_button_pressed()"></button>
</body>
</html>

music_lists.php

<?php
function getNextMusic() {
    fopen("abc.txt", "w");
}
?>

Problem
I am running the web page using Apache server and just when i open it in my browser it creates 'abc.txt', but why i have not even clicked anything.
Why is it happening ?

What I am trying to do
I am trying to make a music player.
I have the PHP function to provide me with a number +1 more than the previous one.
Like when i click it first time a variable $musicIndex stores 1, then on next click it should store 2 and so on. I am trying to do that using session.
But in reality, even before i click i get 1 in that variable and when i click next i still get 1. Then when i restart my browser and one that same page i get 2.




Aucun commentaire:

Enregistrer un commentaire