Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Impossible php problem

This one takes the cake. I am obviously missing something obvious.

Pieces:

(1) Simple php program

<?php
// proj_summary_mu.php
error_reporting(E_ERROR);
session_start();
include "db_connect_nb.php";
$pid = $_GET['pid'];
include "pdf_MU_project.php";
// use fpdf_merge to put together
include "merge_MU_pdfs.php";
?> 

Open in new window


(2) File pdf_MU_project.php attached.

Note there is ONE echo in this file. It never shows.

(3) The last few lines of pre_package_mu.php. This is significant, because the real problem shows this as the program being executed, which is NOT true.

	// do the project summaries
	header("Location: proj_summary_mu.php?pid=". $pid);
	//header("Location: package.php?pid=" . $pid);
	exit;
?>

Open in new window


(4) Browser display of code as run (attached) . Earlier today I had echos that show this; they have bee removed, I have checked source on the server, they are NOT there. I ran it in FireFox AFTER clearing the cache. Don't know how to clear cache in chrome. Ran it there, identical result

As best I can see, this is impossible.
pdf_MU_project.php
execution.PNG
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

I don't understand what is wrong by reading your post.  ??
Avatar of Richard Korts

ASKER

The echos shown in the png or jpg do not exist in those programs on the server now.

So when I open the preceding programs in a browser, & get there, it is showing a physical impossibility, or so it seems.

I am happy to provide you or any other Expert with a logon & the steps required to get there, but not posted openly on EE. I need a private email or ?? so only you will see it.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Richard,

If you need to send us login details, you can do that with a private message. Simply click on the name of the person you want to sent the details to and click on the Message button. Only that person will be able to see your message so it's safe. I would still suggest you use temporary login details though so you can easily change it later.
I showed you the last few lines of the program pre_package_mu.php, where is has a header taking it to another location. Everything is there from that point forward.

My point is the echo's that show when I run it are PHYSICALLY not on the server.

As I told Dave, give me an email or ??? & I will send you a logon & the steps to get to this.

Thanks
I just sent you a message, but I would suggest that you use file_put_contents() to write log entries to a text file on the server so you can see how the code is being executed. Take this single line:
file_put_contents("/tmp/pdf_problem.log", __FILE__ . ":" . __LINE__ . "\n", FILE_APPEND);

Open in new window


And copy and paste it into various parts of your program:
1. As the first line of code in pre_package_mu.php, and at the top of any other script involved.
2. Immediately after any header() line that redirects, like the one sending you to proj_summary_mu.php.
3. Before and after any require() / require_once() / include() / include_once() lines.

Then re-run the process to produce the problem. When you're done, look at /tmp/pdf_problem.log. That should tell you which files executed and which lines. The key here is to look for lines that SHOULD have executed but didn't, and then look at the previous logged line and see what is happening between the logging lines.
You showed us that last few lines of the program, but it looks like your script is never reaching that point (the browser isn't redirecting), which is why we'd need to see what comes before it.

I don't give out my email details on here. I only accept private messages directly through EE. Sorry!
Mmhhh... I believe the problem lies in you use of header.
This function must be called before any character is sent to the client.

If you send any character before header, then this is simply ignored.
https://www.php.net/manual/en/function.header.php

The most common way to achieve sending charcters unwantedly, is to end your included files with the closing tag "?>"
If you do, than any character after ?> (inclidung the nomal line return) is assumed to be html code to send to the client.
(Of course the same applies to any character possibly preceding the initial <?
          which in some cases might simply happen because the included  file is eg, UTF8 with BOM while the including is not UTF8)

Of course, it also happens that some html code is sent to the client. This was certainly the case when you got the screen capture provided

Looking at the code you provide:
1 - The main program ends with ?> but this should have no impact since it is the main including program. Check if the first included program db_connect_nb.php starts directly with <?php (no char before) and does not end with ?>
2 -  Second included program pdf_MU_project.php has itself an included file ( fpdf.php ).
You say that the uncommented echo (at the end of the code) should print but doesnot. This seems like an error in your reporting here, No evident reason for the program stopping with no error displayed. Unless the required file fpdf.php is missing, But then the E_ERROR flag should force the display of an error message while stopping the program.

3 - Your screen capture does not fit with the other elements provided. Where was the code displaying that? It is not present in the copy of pdf_MU_project.php
4 - If the header() does not work... while php says that the program that has it works... then I presume  that yes the program works but that it somehow prints something not visisble, which then prevents the header function to have any impact.

If you feel comfortable with Command Line Interface and have access to using it, I suggest that you run your program (say simple.php) as follows:
- cd to the directory which hosts simple.php
- run the code check
php -l simple.php
It would spot any error in your code also inclided files (as far as I remember)
- then run
php simple.php
(if needed wit th earguments)
Hi Richard,

Just an advice, you should do your include before the session session_start

<?php
// proj_summary_mu.php
error_reporting(E_ERROR);
include "db_connect_nb.php";
$pid = $_GET['pid'];
include "pdf_MU_project.php";
// use fpdf_merge to put together
include "merge_MU_pdfs.php";
session_start();
?> 

Open in new window


And if you have need session_start() in the other include file:
if (!isset($_SESSION))
  {
    session_start();
  }

Open in new window

@Nicolas

Calling session_start() at the end of the program makes no sense!
I agree - I don't understand the comment about the session_start() being moved to the end...
@Chris Stanyon
I meet this problem one time, and the sessions start before require_once and include was the problem, but I understand why you say that.

So he can try to see.
Moving the session_start() further up -before- a require/include would potentially make sense, if the included/required files had white space in them, but moving it down doesn't accomplish anything and would break any earlier code that relied on session variables.
To all,

Where do you see session_start() at the END in my code?

Of course that is clearly a possible HUGE problem.

I can't see it anywhere.

Thank You
No, no...Hi Richard,
I just want you to test session_start at the bottom like I say in my previous message, but others experts say that it's a non sense, I'm agree.

But I just say that I meet a problem before with session_start and require_once order, and I put the session_start after the require_once to fix a problem of object class.

Your code don't have any problem don't worry.
Nicolas Lecanu,

Obviously my programming has a HUGE problem, we just haven't found it yet.

Thanks to you all, I'm going to try some of your suggestions this PM.
To all,

Problem solved, I was looking in "all the wrong places".

FYI, the way I found it, since I was CERTAIN those echos had been removed or commented out, but just to make sure, I downloaded every php for that application from the host server to my local machine, did a global search (over 800 files), it found one file with them in it, I removed those (with egg on my face), uploaded them & it's all OK.

I still have the original problem that made me put the echos in in the first place, that is another issue, I may post tomorrow on EE if I can't figure it out.

Thank you!!
Message in previous post.

Thank you ALL!!