Jump to content

HEADER PROBLEM


robert_gsfame

Recommended Posts

<?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??

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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??

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.