I have a variable session called index that is created in another file with the value 1, and sisque index is equal to 1 it shows me a response <H4>Respuesta</H4>
, and with a button I call a javascript function that change the value of variable , when reloading the page should not show me the answer, but my code does not work, as I have everything vien, The problem esq without using the button the variable already starts with another value
<?php
session_start();
function Main()
{
if($_SESSION['index'] == 1){
echo "<h1>Respuesta</h1>";} else {echo "Ya no se muestra la respuesta";}
}
Main(); ?>
<input type="submit" onclick="clickk();">
<input type="submit" onclick="clickb();">
<script type="text/javascript">
function clickk() {
alert('<?php $_SESSION['index'] = 1; ?>');
}
function clickb() {
alert('<?php ; $_SESSION['index'] = 2; ?>');
}
</script>