Search the Community
Showing results for tags 'header()'.
-
I have seen the header("Location: http://example.com") takes some time to reach the browser but in the meantime the php script (if there is code after the header statement) continues to execute. So I recently started putting a die() immediately following the header() statement. I want to know if this a good practice? Do any of you experienced guys already do this?
-
Hi Everyone am having errors with this: Warning: Cannot modify header information - headers already sent by (output started at /------/--------/public_html/-------------------------.com/--------------------/classes/mobile.php:15) in /------/--------/public_html/-------------------------.com/--------------------/classes/mobile.php on line 6 Here is mobile.php <?php // line 1 // mobile.php // line 2 class mobile_redirection { // line 3 function __construct($pagename = NULL){ // line 4 if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT'])) { // line 5 if(isset($pagename)){ header('Location: http://www.----------------------------.com/mobile/'.$pagename); } else { header('Location: http://www.-------------------------------.com/mobile/'); } // line 6 } else { // line 7 return false; // line 8 } // line 9 } // line 10 } // line 11 ?> // line 13 I dont understand why there is an error on line fifteen as it doesn't exist and I dont know whats wrong on line 6. When someone goes to my domain it the index file the error comes up but what should happen is if they are a mobile they are redirected to a mobile sub directory or if they aren't a mobile they should be redirected to form.php. <?php // Login or Sign Up require('classes/mobile.php'); $mobile = new mobile_redirection('form.php'); if($mobile === false){ header('Location: form.php'); } ?> Any ideas why this isn't happening? Also, it isnt redirecting to form.php yet but if they get there and submit it will be using sessions: is it okay to use headers to redirect from 1.php to 2.php and then on 2.php start_session()? Thanks for reading and for any help in advance, Timothy
-
When I try to display PDF , not working when pdf contains path, just working if the file is in the same index This Works <a href="myfile.pdf" target="_blank">View PDF</a> The below not working .. ERROR The requested URL was not found on this server. <a href="admin/assets/cvs/myfile.pdf" target="_blank">View PDF</a> I am sure that the path is right and I tested with .png extensions. Also I tried to use header function to display PDF with PHP but got also error even if the file in the same directory index Failed to load PDF document. $fileName = "myfile.pdf"; header('Content-type: application/pdf'); header('Content-Disposition: inline; filename="' .urlencode($fileName). '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($fileName)); header('Accept-Ranges: bytes'); @readfile($fileName);