php echo javascript alert() not working -
i display popup message when user logged out, use
echo "<script>alert(\"you logged out\");</script>";
but doesn't work.
below coding. there logic problem in coding?
<?php session_start(); if(isset($_session['username']) == "admin") { ?> <!doctype html> <html> <head> <meta charset="utf-8"> <style type="text/css"> @import "../css/style.css"; @import "../css/admin.css"; </style> <title>admin home page</title> </head> <body> <div class="body"></div> <?php if(isset($_get['id']) == "logout") { session_destroy(); echo "<script>alert(\"you logged out\");</script>"; header("location: ..\main.php"); } else { ?> <div class="menu"> <a href="managestaff.php">manage staff</a> </div> <div class="menu2"> <a href="manageaccount.php">manage account</a> </div> <div class="logout"> <a href="adminhomepage.php?id=logout">logout</a> </div> <?php } } else { ?> <center> <p style="font-size:50px; font-weight:bold">access denied</p> <p style="font-size:18px">your request page has been denied because of access control</p> </center> <?php } ?> </body> </html>
the session destroyed , redirect main.php, alert()
not come out.
you're doing echo , writing relocate header. if did relocate in javascript (after user clicked alert), work way expect to.
echo "<script>alert('you logged out'); window.location.href='..\main.php';</script>";
also, way use isset
cause problems because isset
returns true or false (it checks if value present), rather returning value.
so instead of
if(isset($_session['username']) == "admin")
you need do:
if(isset($_session['username']) && $_session['username'] == "admin")