I have the following code:
<!DOCTYPE html>
<html lang="cs">
<head>
<title>Hardware audit - přihlášení</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="js/myPureScript.js"></script>
</head>
<body onload="setAutoSession">
<?php
if(file_exists("config.dat")){
header('Location: login.php');
}
else{
header('Location: setup.php');
}
?>
</body>
</html>
Part of myPureScript.js
function setAutoSession(){
localStorage.setItem("username", "auto");
console.log("nastavil jsem session"); // "I set the session"
}
The function setAutoSession is ignored, because I have log.console there and it is not displayed in my console. So where could be the problem. I think that only problem could be, that the PHP header is started before my function.
Thank you for your advice.
<body onload="setAutoSession()">(Note the parentheses)Locationheader, then the browser wouldn't need to load thebodyanyway. I'd expect this to result in an error from PHP. What is actually being sent to the client? What actually happens in the browser for you?