PHP function to run in Javascript code even if the Distance variable is greater than 0

Asked

Viewed 98 times

0

After an Submit button on the previous page, it will execute all the Java Script code you can see below and that is integrated into a file. php , I invoke the function in the JS code and it even runs with the variable "Distance" greater than 0 , I debugged to actually see if Distance was greater than 0 with the console.log() method and really the distance is greater than 0. How does my function perm_private() is being executed?

This is the PHP function :

function perm_private($value){

//*LOGIN


$getRequest = get_headers("https://whateverDomain.adobeconnect.com/api/xml?action=login&login=whateverlogin&password=whateverpass");

preg_match("/=([0-9a-zA-Z]+)/",$getRequest[1],$match);

$result = file_get_contents("https://whateverDomain.adobeconnect.com/api/xml?action=report-meeting-summary&sco-id=whateverID&session".$match[0]);

//echo "<div>"."This is the Cookie ".$match[0]."</div>";

//echo "<br>";

//echo htmlentities($result);

//----------------------------------//-------------------------------//-----------------------------------//----------------------------------------

//*CHANGE PERM TO PRIVATE

$perm = file_get_contents("https://whateverDOMAIN.adobeconnect.com/api/xml?action=permissions-update&principal-id=public-access&permission-id=denied&acl-id=".$value."&session".$match[0]);

//echo htmlentities($perm);}

**This is the code in JAVASCRIPT **

<?php
if($_SERVER['REQUEST_METHOD'] == "POST" and isset ($_POST['go']))
{
$date = date('F d ').'4:45:55 AM WEST';
$exp_date = strtotime($date);
$now = time();
}
if ($now < $exp_date) {
?>
<script>
// Count down milliseconds = server_end - server_now = client_end - client_now
var server_end = <?php echo $exp_date; ?> * 1000;
var server_now = <?php echo time(); ?> * 1000;
var client_now = new Date().getTime();
var end = server_end - server_now + client_now; // this is the real end time

var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour *24
var timer;

function showRemaining()
{
    var now = new Date();
    var distance = Math.round((end - now)/1000)*1000;
    //RIGHT HERE MY PHP FUNCTION EXECUTES EVEN THOUGH DISTANCE IS GREATER THAN 0 
if (distance < 0 )
    {
       clearInterval(timer);
       var changePriv = <?php echo perm_private($value); ?>

       document.getElementById('countdown').innerHTML = 'Link Closed';


        return;
    }

    var days = Math.floor(distance / _day);
    var hours = Math.floor( (distance % _day ) / _hour );
    var minutes = Math.floor( (distance % _hour) / _minute );
    var seconds = Math.floor( (distance % _minute) / _second );

    var countdown = document.getElementById('countdown');
    countdown.innerHTML = '';
    if (days) {
        countdown.innerHTML += 'Days: ' + days + '<br />';
    }
    countdown.innerHTML += 'Hours: ' + hours+ '<br />';
    countdown.innerHTML += 'Minutes: ' + minutes+ '<br />';
    countdown.innerHTML += 'Seconds: ' + seconds+ '<br />';
}

timer = setInterval(showRemaining, 1000);

</script>
<?php
} else {
    echo "Times Up";




}
?>

I remind you again that all this code is written in the same file . php!

I’d appreciate a hand.

Thank you.

  • 1

    Please ask the question in English.

1 answer

0

PHP is a "server-side" language so it runs on the server-side, it creates data (HTML, JS...) and the result is sent in the browser.

The browser will show this on the user screen, and will run Javascript, which is a language "client side".

When Javascript is running in the browser, PHP has already been run.

if (distance < 0 )
    {

and a Javascript line that will run in the browser and it cannot call PHP because PHP has already finished its execution.

To solve your problem, you must do it with a different logic. For example test "Distance" with PHP and conform in value, produce different HTML or Javascript code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.