robert_gsfame Posted December 6, 2009 Share Posted December 6, 2009 <?php session_start(); ?> <?php require_once('config.php'); $session=$_SESSION['MM_Username']; $id=$_GET['id']; if(empty($session)){ print "<script>"; print "self.location='index.php'"; print "</script>";}else $query=sprintf("SELECT * FROM table1 WHERE email='%s'", mysql_real_escape_string($session)); $sql=mysql_query($query); $num=mysql_num_rows($sql); if(empty($num)){print "<script>"; print "self.location='index.php'"; print "</script>"; session_destroy();}else{ $query1=sprintf("SELECT * FROM table2 WHERE corp_email='%s' AND id='%d'", mysql_real_escape_string($session), mysql_real_escape_string($id)); $sql1=mysql_query($query1); $num1=mysql_num_rows($sql1); if(empty($num1)){print "<script>"; print "self.location='error.php'"; print "</script>";}else{ $query2=sprintf("SELECT * FROM table2 WHERE corp_email='%s' AND id='%d'", mysql_real_escape_string($session), mysql_real_escape_string($id)); $sql2=mysql_query($query2); $array2=mysql_fetch_array($sql2); $fileName=$array2['attachment']; $mimeType = 'application/msword'; header('content-disposition: attachment; filename="' . $fileName . '"'); LINE 39 header('content-type: ' . $mimeType); LINE 40 header('content-length: ' . filesize("upload/{$fileName}")); LINE 41 readfile("upload/{$fileName}");}} ?> AND I GOT THIS MESSAGE Warning: Cannot modify header information - headers already sent by xxxxxxxxx on line 39 Warning: Cannot modify header information - headers already sent by xxxxxxxxx on line 40 Warning: Cannot modify header information - headers already sent by xxxxxxxxx on line 41 By the way, when i tried on my local server no problem occured but then i upload the file into my domain cpanel and this problem occur Can anyone help me?? Quote Link to comment https://forums.phpfreaks.com/topic/184174-header-problem/ Share on other sites More sharing options...
mrMarcus Posted December 6, 2009 Share Posted December 6, 2009 go here: PHP Coding Help, and look at the post directly above your post. Quote Link to comment https://forums.phpfreaks.com/topic/184174-header-problem/#findComment-972354 Share on other sites More sharing options...
Mchl Posted December 6, 2009 Share Posted December 6, 2009 Did you read this? http://www.phpfreaks.com/forums/index.php/topic,37442.0.html You have used print several times before headers. It's workong on your localhost probably because you have output buffering enabled in php.ini (using WampServer?) Quote Link to comment https://forums.phpfreaks.com/topic/184174-header-problem/#findComment-972355 Share on other sites More sharing options...
robert_gsfame Posted December 6, 2009 Author Share Posted December 6, 2009 i am stil newbie and not sure which part is wrong :'( Quote Link to comment https://forums.phpfreaks.com/topic/184174-header-problem/#findComment-972361 Share on other sites More sharing options...
Mchl Posted December 6, 2009 Share Posted December 6, 2009 Any header() instructions must be before script outputs anything. That is before any echo or print instructions. Quote Link to comment https://forums.phpfreaks.com/topic/184174-header-problem/#findComment-972362 Share on other sites More sharing options...
robert_gsfame Posted December 6, 2009 Author Share Posted December 6, 2009 <?php session_start(); ?> <?php require_once('config.php');?> <?php $id=$_GET['id']; $query2="SELECT * FROM table1 WHERE corp_email='$session' AND id='$id'"; $sql2=mysql_query($query2); $array2=mysql_fetch_array($sql2); $fileName=$array2['attachment']; $mimeType = 'application/msword'; header('content-disposition: attachment; filename="' . $fileName . '"'); header('content-type: ' . $mimeType); header('content-length: ' . filesize("upload/{$fileName}")); readfile("upload/{$fileName}"); ?> no echo or print but still create the same error Quote Link to comment https://forums.phpfreaks.com/topic/184174-header-problem/#findComment-972363 Share on other sites More sharing options...
phant0m Posted December 6, 2009 Share Posted December 6, 2009 what about.... this: ?> <? Quote Link to comment https://forums.phpfreaks.com/topic/184174-header-problem/#findComment-972366 Share on other sites More sharing options...
Mchl Posted December 6, 2009 Share Posted December 6, 2009 There might be something in config.php. Your error message should containn something like 'Output started in (filename) on line (line#). Also I might be wrong (it's hard to say without proper indenting of your code) that you're missing a { after 'else' here if(empty($session)){ print "<script>"; print "self.location='index.php'"; print "</script>";}else Instead of print "<script>"; print "self.location='index.php'"; print "</script>"; you can use header('Location: index.php'); Quote Link to comment https://forums.phpfreaks.com/topic/184174-header-problem/#findComment-972367 Share on other sites More sharing options...
robert_gsfame Posted December 6, 2009 Author Share Posted December 6, 2009 this is my config <? $host="localhost"; $username="myusername"; $password="mypassword"; $db_name="mydatabase"; mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB");?> is there something wrong in the config?? Quote Link to comment https://forums.phpfreaks.com/topic/184174-header-problem/#findComment-972528 Share on other sites More sharing options...
PFMaBiSmAd Posted December 6, 2009 Share Posted December 6, 2009 Your error message should contains something like 'Output started in (filename) on line (line#). Until you read or post the part of the error message that states where the output is occurring at that is preventing the headers from working, you cannot solve the problem. Quote Link to comment https://forums.phpfreaks.com/topic/184174-header-problem/#findComment-972529 Share on other sites More sharing options...
robert_gsfame Posted December 6, 2009 Author Share Posted December 6, 2009 thanks everyone, i got some whitespace in my config Quote Link to comment https://forums.phpfreaks.com/topic/184174-header-problem/#findComment-972545 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.