Skip to main content
edited tags
Link
Christophe
  • 82.3k
  • 11
  • 136
  • 202

I'm new to PHP and JS and I'm currently working on a gym management web app for our project in school. I'm adding a bit of QR functionality that sees if the user is eligible to enter the gym or not by checking if the user has paid. I want to know if it is good to escape PHP code in inline JS, or would it be better to get the id via ajax and store it into a js variable?

</script><script> // ... new QRCode(document.getElementById("qr-code"),  "./functions/check_if_paid_qr.php?id=<?php echo $_SESSION["member_id"] ?>"); // ... </script> 

I'm using qrcode.js btw.

I'm new to PHP and JS and I'm currently working on a gym management web app for our project in school. I'm adding a bit of QR functionality that sees if the user is eligible to enter the gym or not by checking if the user has paid. I want to know if it is good to escape PHP code in inline JS, or would it be better to get the id via ajax and store it into a js variable?

</script> ... new QRCode(document.getElementById("qr-code"), "./functions/check_if_paid_qr.php?id=<?php echo $_SESSION["member_id"] ?>"); </script> 

I'm using qrcode.js btw.

I'm new to PHP and JS and I'm currently working on a gym management web app for our project in school. I'm adding a bit of QR functionality that sees if the user is eligible to enter the gym or not by checking if the user has paid. I want to know if it is good to escape PHP code in inline JS, or would it be better to get the id via ajax and store it into a js variable?

<script> // ... new QRCode(document.getElementById("qr-code"),  "./functions/check_if_paid_qr.php?id=<?php echo $_SESSION["member_id"] ?>"); // ... </script> 

I'm using qrcode.js btw.

Tweeted twitter.com/StackSoftEng/status/1360831152211300352
Question Protected by gnat
Became Hot Network Question
Source Link
therealtsuki
  • 458
  • 1
  • 4
  • 7

Is it good practice to echo PHP code into inline JS?

I'm new to PHP and JS and I'm currently working on a gym management web app for our project in school. I'm adding a bit of QR functionality that sees if the user is eligible to enter the gym or not by checking if the user has paid. I want to know if it is good to escape PHP code in inline JS, or would it be better to get the id via ajax and store it into a js variable?

</script> ... new QRCode(document.getElementById("qr-code"), "./functions/check_if_paid_qr.php?id=<?php echo $_SESSION["member_id"] ?>"); </script> 

I'm using qrcode.js btw.