I have a logout function that looks like this.
if ($_GET["argument"]=='logOut'){ if(session_id() == '') { session_start(); } session_unset(); session_destroy(); $host = $_SERVER['HTTP_HOST']; $extra = 'index.php'; header("Location: http://$host/$extra"); exit; }
My problem is that, If I inspect the page and look at the Network preview and response, it looks 'fine'.
There are two php files listed that was processed.
http://localhost:5000/inc/mainScripts.php?argument=logOut
which is where the function is located.
and http://localhost:5000/index.php
Which is where i would like to be redirected.
The Response tab in the Network of the inspect page area in chrome
contains the full login html page login.php but in the browser it remains in the same place. Like the header command has never been called.
What Am I doing wrong?
HTML AJAX call to this function:
$("#logout_btn").click(function() { $.ajax({ url: './inc/mainScripts.php?argument=logOut' }) });
SOLUTION
AJAX
$("#logout_btn").click(function() { $.ajax({ url: './inc/mainScripts.php?argument=logOut', success: function(data){ window.location.href = data; } }); });
PHP
if ($_GET["argument"]=='logOut'){ if(session_id() == '') { session_start(); } session_unset(); session_destroy(); $host = $_SERVER['HTTP_HOST']; $link = "http://$host/index.php"; echo $link; }
$extrawhen you use it?'index.php'index.phpwhen you expected it to showlogin.phpor the browser is still reporting it asmainScripts.php?argument=logOutwhen it should beindex.php?http://localhost:5000/Main.phpmain content page. but inspecting the page thenetworktab shows php calling the function and then showingindex.phpbut nothing changes on the browser. I will append a image