Hello everybody,
I know they are two different programing languages, but is it possible, lets say, translate PHP to JavaScript?
I’ve got this php code and i would do the same in JS.
Anybody understand me…?
<?php include("sesion.php"); ?>
Bienvenido:
<?php echo $_SESSION["usuario"]; ?>
<br /><br />
Estas en una página segura con sesiones en PHP
<br /><br />
<a href="archivo-protegido2.php">Ir a otra página segura</a>
<br /><br />
<a href="salir.php">SALIR</a>
Well, you can’t really do that, since PHP is a server-side language incorporated into a frontend language while JavaScript does have a server-side part (NodeJS) and a frontend part, they can’t be used together like PHP.
PHP is actually pretty similar to JavaScript, with vanilla, browser JavaScript you won’t be able to do any of the server-side actions PHP can, but with NodeJS you could.
Your example could easily be translated to JavaScript, it would look something like this:
Bienvenido:
<script>
document.write(window.sessionStorage.getItem("usuario"));
// although document.write is deprecated and I would recommend something more like this:
const span = document.createElement("span");
span.textContent = window.sessionStorage.getItem("usuario");
document.body.append(span); // append is the same as appendChild
</script>
<br /><br />
Estas en una página segura con sesiones en PHP
<br /><br />
<a href="archivo-protegido2.php">Ir a otra página segura</a>
<br /><br />
<a href="salir.php">SALIR</a>