johnsmith153 Posted December 2, 2008 Share Posted December 2, 2008 Does anyone have a script that allows a user to download a file but have some sort of session control? Ie if($_SESSION['a']==1) { //download } else { //do not download } etc. must work with sessions - which seems to be the problem. Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/ Share on other sites More sharing options...
jjacquay712 Posted December 2, 2008 Share Posted December 2, 2008 have a script set a session, then do this <?php session_start(); if ($_SESSION['download']) { echo '<script type="text/javascript">document.location="download link.exe"</script>'; } ?> Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-703927 Share on other sites More sharing options...
johnsmith153 Posted December 2, 2008 Author Share Posted December 2, 2008 I need it without javascript. Is that possible? Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-703929 Share on other sites More sharing options...
waynew Posted December 2, 2008 Share Posted December 2, 2008 <?php session_start(); if ($_SESSION['download']) { header('Location: filename.exe'); } ?> Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-703931 Share on other sites More sharing options...
jjacquay712 Posted December 2, 2008 Share Posted December 2, 2008 sure, you can use this: <?php session_start(); if ($_SESSION['download']) { header("location: download_link.exe"); } ?> Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-703932 Share on other sites More sharing options...
jjacquay712 Posted December 2, 2008 Share Posted December 2, 2008 beat me to it Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-703936 Share on other sites More sharing options...
johnsmith153 Posted December 2, 2008 Author Share Posted December 2, 2008 <?php session_start(); if ($_SESSION['download']) { header("location: jpeg-image.jpg"); } ?> jpeg-image.jpg Hardly going to work though, is it? Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-703938 Share on other sites More sharing options...
johnsmith153 Posted December 2, 2008 Author Share Posted December 2, 2008 Any ideas anyone? Need to download a file, NOT just link to it. But must be able to use $_SESSION on the page - it seems to mess it up if you do. Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-704020 Share on other sites More sharing options...
revraz Posted December 2, 2008 Share Posted December 2, 2008 Sessions have nothing to do with opening files, so not sure what you mean by "mess up". Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-704027 Share on other sites More sharing options...
unkwntech Posted December 2, 2008 Share Posted December 2, 2008 <?php session_start(); if ($_SESSION['download']) { header('Content-Disposition: attachment; filename="file.ext"'); readfile('path/to/file.ext'); } ?> Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-704045 Share on other sites More sharing options...
johnsmith153 Posted December 2, 2008 Author Share Posted December 2, 2008 I agree there should not be any relation between file download and $_SESSION, but: The below scripts are the full code that is on the page. This WORKS great: //session_start(); $fileurl = "/home/account/folder1/folder2/file.xlsx"; $file= "file.xlsx"; header("Content-Disposition: attachment; filename=$file"); readfile($fileurl); This DOES NOT: session_start(); $fileurl = "/home/account/folder1/folder2/file.xlsx"; $file= "file.xlsx"; header("Content-Disposition: attachment; filename=$file"); readfile($fileurl); Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-704145 Share on other sites More sharing options...
revraz Posted December 2, 2008 Share Posted December 2, 2008 Define DOES NOT. What does or does it not do? Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-704148 Share on other sites More sharing options...
johnsmith153 Posted December 2, 2008 Author Share Posted December 2, 2008 It does not work. It does not do the file download. Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-704153 Share on other sites More sharing options...
johnsmith153 Posted December 2, 2008 Author Share Posted December 2, 2008 Surely either I'm the idiot, or PHP is. Which one? I would appreciate if someone can try this, I just can not understand why the below script will not download the file just because I set session_start() Works fine, unless you set session_start() //session_start(); $fileurl = "/home/account/folder1/folder2/file.xlsx"; $file= "file.xlsx"; header("Content-Disposition: attachment; filename=$file"); readfile($fileurl); Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-704168 Share on other sites More sharing options...
johnsmith153 Posted December 2, 2008 Author Share Posted December 2, 2008 Thanks to www.sitepoint.com, the answer is: Place: session_cache_limiter('public'); before the session_start() call Link to comment https://forums.phpfreaks.com/topic/135157-solved-_session-problem/#findComment-704211 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.