Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Closing browser window using a java script inside a PHP code also including session_start();

Mousa Alfhaily:

So this is my whole setup :

I'm on a HTML page and i'm opening a POST request using JS inside the same HTML page and i'm opening it in a new window like this :




Now inside test.php i'm downloading an app referring to the GET request for the App var in the URL, also the POST request works just fine, but after start downloading the file i need to close the window, so i used :


echo "";

Now i tested it and it worked Closing the window just fine, but now here is my problem... inside the test.php file i'm also using sessions (session_start();) and when i do use that line (session_start();) the java script code for closing the window does not work any more!!, i'v tried commenting all the code but keeping session_start(); and i really found out that it's what preventing the window from closing, which is very weird, they are not related at all, or this is what i think at least, here is my test.php file :


session_start();
if($_SESSION["TEMP"] == "Yes"){
if(isset($_GET['App'])){
$fileName = $_GET['App'] . " - Setup.exe";
if(basename($_GET['App']) == $_GET['App']){
$path = 'download_directory/' . $fileName;
$size = filesize($path);
header('Content-Type: application/octet-stream');
header('Content-Length: ' . $size);
header('Content-Disposition: attachment; filename=' . $fileName);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
ob_clean();
$file = @ fopen($path, 'rb');
if($file){
fpassthru($file);
$_SESSION["TEMP"] = "No";
}
}
}
}
echo "";
?>

Downloading the file also worked!

Can someone please explain to me what's happening and help me go around this because i really need to use sessions?!



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Closing browser window using a java script inside a PHP code also including session_start();

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×