|
It seems to be the very first call to header that fails. It fails even if I stick an echo before it (and echoed text is not displayed). If I used echo 'x'; die; it displays x, but obviously doesn't attempt to change headers.
Do you know if there are required permissions to use header function?
Thanks again
|
|
|
|
|
lhayes00 wrote: It fails even if I stick an echo before it (and echoed text is not displayed).
Aha! If the echoed text is not displayed for an echo() BEFORE the first header(), then it seems that code is not being entered. An echo() should output something recognisable, even if the total result is a mangled chunk of HTML. This also ties in with the ERR_EMPTY_RESPONSE you mentioned in your original question.
The next place I would go looking is Apache and PHP version differences between the working and failing sites.
AFAIK, there are no special permissions required to use header(). ie, from a permissions point of view, header() is as good or bad as echo().
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
The working server is using PHP 5.2.17 / The non-working is using PHP 5.2.6. They are both running CGI/FastCGI.
Apart from that, phpinfo() shows basically the same thing for both.
Many thanks,
|
|
|
|
|
Sorry, I may have confused you with my last reply. Should have put in dot points?
1. The first thing to look for is why the first echo() doesn't.
2. If you got nowhere looking for that, then look for differences between the servers (which now appear to be irrelevant.)
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
The following works (even though invalid HTML):
<?php
echo 'Hello';
?>
<!DOCTYPE html>
<html>
<head>
<title>My 404!!</title>
</head>
<body>
<h1>My 404!!!</h1>
</body>
</html>
The following doesn't work:
<?php
echo 'Hello';
if (substr(php_sapi_name(), 0, 3) == 'cgi')
header("Status: 404 Not Found");
else
header("HTTP/1.1 404 Not Found");
?>
<!DOCTYPE html>
<html>
<head>
<title>My 404!!</title>
</head>
<body>
<h1>My 404!!!</h1>
</body>
</html>
Thanks,
|
|
|
|
|
I have the same problem with no error output and I just receive a white screen. I have to check the apache error log.
On my system the path is /var/log/apache2/error.log
|
|
|
|
|
The error log doesn't show any related errors. The access log shows the following (I called the test file t404.php):
[05/Feb/2011:00:59:51 +0000] 92.232.71.252 - - "GET /t404.php HTTP/1.1" 404 - "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.84 Safari/534.13"
This indicates that the header status is being changed, but for some reason the content is not being presented to end-user.
The following code is still producing blank output in Chrome, but it IS creating the "test.txt" file with the contents 'Hello World!'. So this indicates that the script is in fact being executed.
<?php
if (substr(php_sapi_name(), 0, 3) == 'cgi')
header("Status: 404 Not Found");
else
header("HTTP/1.1 404 Not Found");
?>
<!DOCTYPE html>
<html>
<head>
<title>My 404!!</title>
</head>
<body>
<h1>My 404!!!</h1>
</body>
</html>
<?php
$fp = fopen('test.txt', 'w');
fwrite($fp, 'Hello World!');
fclose($fp);
?>
This doesn't make any sense at all to me...
|
|
|
|
|
|
Hello experts. Is it possible to create file headers in PHP? In C, I could rely on size of data types to create file headers so that if I want a specific information from the file header, I had to seek to the appropriate byte location and read what I wanted.
I am seeing this to be difficult in PHP. I don't know how I can save, for instance, the length of a string in a file header and later retrieve it at a known byte location.
I started with something like the following:
class FileHeader
{
private $contentSize;
private $titleLength;
private $headerLength;
}
Because the variables can take different data types in PHP, I don't know how I can read the header information before dealing with the file. I can't tell the length that will take me to, for instance, $headerLength in the file so that I can read it since I wouldn't know the length of a particular data. It seems the number of bytes can vary for different headers of different files. Actually, I am a newbie in PHP and I don't know if there is any other way that will make such a task possible. Please help.
|
|
|
|
|
I am not sure you can read the header with any php based functions. But maybe you can use the system(), exec(), or passthru() to call a system resource to return what you are looking for.
Chris J
www.redash.org
|
|
|
|
|
If you really need to work with binary files in PHP you need to use the pack and unpack functions, along with the C like file functions (fopen, fseek, fread etc.), however if you need to work with binary files you probably really need to consider whether PHP is an appropriate language for your application.
Niall
|
|
|
|
|
I think I cannot use PHP for my task. I tried to write an integer value which could have occupied 4 bytes (or 2 bytes) of memory but the value was written as two sequence of characters. This means that I cannot rely on writing such values in PHP. 27 was saved as it is of two characters '2' and '7'. So 274 will also be saved as 3 characters where in C I would have assumed that to be of 4 sequence of bytes. I think PHP is unsuitable for such a task. Or maybe there are other ways around which I don't know and need to be taught.
modified on Monday, January 31, 2011 7:58 PM
|
|
|
|
|
This bit of code shows you how to write an integer to an ASCII text file, then (as a four byte long) to a binary file. The key thing is that pack is used to convert the integer into a character array equivalent to its binary representation before writing it. The default behavior of PHP when writing variables to a file is to convert them to strings.
<?php
$myinteger = 234;
$fp1 = fopen("ascii_text_file.txt", "w");
fwrite($fp1,$myinteger);
fclose($fp1);
$fp2 = fopen("binary_file.dat", "w");
$data = pack("l",$myinteger);
fwrite($fp2, $data);
fclose($fp2);
?>
|
|
|
|
|
Narr, it works. Now I believe reading the file requires
unpack()
function.
I tried to read about this function but I get confused with the format that is to be specified to it but I am trying to understand it. Thanks a lot.
|
|
|
|
|
Hi all. I am a beginner in php programming. Given a web page with links, I would like to know how I can send the selected link to a php script so that it will return the appropriate page requested. I don't if this can be done in an anchor ( <a> ) tag. Please help.
|
|
|
|
|
Ok I'm not quite sure what you mean. A link on a page already loads a file from the webserver (eg: <a href="http://www.somesite.com/mypage.php">MyLink</a> ). The link I gave in the sample would load mypage.php from the webserver.
If you mean you wish to use one single entry point (eg: index.php) for all page requests then you could do this using the querystring. Just set a parameter with the page you want to load and put the entire url in the A tag.
So in the second case you would end up with something like:
<a href="http://www.somesite.com/index.php?page=mypage">MyLink</a>
|
|
|
|
|
Ok been working on this for about 2 hours and I'm officially stuck.
What I'm trying to do is bild a calendar (got that part working how I want) where I can change the month.
I have the following code:
function startTable2($currentMonth,$currentYear) {
$month = date("F", mktime(0,0,0, date($currentMonth), date("t"), date($currentYear)));
echo "<table border=1 align=\"center\">";
echo "<form action=\"Calendar2.php\" method=\"post\">";
echo "<tr>";
echo "<td align=\"left\"><input type=\"submit\" name=\"previous\" id=\"previous\" value=\"Previous Month\" />";
if ($currentMonth == 1) {
$currentYear = $currentYear - 1;
$currentMonth = 12;
}
else
{
$currentMonth = date("m", mktime(0,0,0, date($currentMonth)-1, date("1"), date($currentYear)));
}
echo "<input type=\"hidden\" name=\"month\" id=\"month\" value=$currentMonth /></td>";
echo "<input type=\"hidden\" name=\"year\" id=\"year\" value=$currentYear /></td>";
echo "<input type=\"hidden\" name=\"day\" id=\"day\" value=\"01\" /></td>";
echo "</form>";
echo "<td colspan=5 align=center>$month $currentYear</td>";
echo "<form action=\"Calendar3.php\" method=\"post\">";
if ($currentMonth == 12) {
$currentYear = $currentYear + 1;
$currentMonth = 1;
}
else
{
$currentMonth = date("m", mktime(0,0,0, date($currentMonth)+1, date("1"), date($currentYear)));
}
echo "<td align=\"right\"><input type=\"submit\" name=\"next\" id=\"next\" value=\"Next Month\" />";
echo "<input type=\"hidden\" name=\"month1\" id=\"month1\" value=$currentMonth /></td>";
echo "<input type=\"hidden\" name=\"year1\" id=\"year1\" value=$currentYear /></td>";
echo "<input type=\"hidden\" name=\"day1\" id=\"day1\" value=\"01\" /></td>";
echo "</td></form></tr>";
echo "<tr><td align=center>Sunday</td><td align=center>Monday</td><td align=center>Tuesday</td><td align=center>Wednesday</td><td align=center>Thursday</td><td align=center>Friday</td><td align=center>Saturday</td></tr>";
}
As of now the "previous" works for every other month (i.e. December, October, August... etc) and the "next" is not working at all (blank screen). I've tried different methods for getting the new date and month but with no luck. Any help is greatly appreciated.
Thank You!
|
|
|
|
|
I've made some code changes and the next no longer comes up blank, it's not right but it's not blank... I also tried to make it more readable.
function startTable2($currentMonth,$currentYear) {
$month = date("F", mktime(0,0,0, date($currentMonth), date("t"), date($currentYear)));
$year = $currentYear;
echo "<table border=1 align=\"center\">";
echo "<tr>";
echo "<td align=\"left\">";
echo "<form action=\"Calendar2.php\" method=\"post\">";
echo "<input type=\"submit\" name=\"previous\" id=\"previous\" value=\"Previous Month\" />";
if ($currentMonth == 1) {
$currentYear = $currentYear - 1;
$currentMonth = 12;
}
else
{
$currentMonth = date("m", mktime(0,0,0, date($currentMonth)-1, date("1"), date($currentYear)));
}
echo "<input type=\"hidden\" name=\"month\" id=\"month\" value=$currentMonth />";
echo "<input type=\"hidden\" name=\"year\" id=\"year\" value=$currentYear />";
echo "<input type=\"hidden\" name=\"day\" id=\"day\" value=\"01\" />";
echo "</form>";
echo "</td>";
echo "<td colspan=5 align=center>$month $year";
echo "</td>";
echo "<td align=\"right\">";
echo "<form action=\"Calendar3.php\" method=\"post\">";
echo "<input type=\"submit\" name=\"next\" id=\"next\" value=\"Next Month\" />";
if ($currentMonth == 12) {
$currentYear = $currentYear + 1;
}
else
{
$currentMonth = $currentMonth + 1;
}
echo "<input type=\"hidden\" name=\"month1\" id=\"month1\" value=$currentMonth />";
echo "<input type=\"hidden\" name=\"year1\" id=\"year1\" value=$currentYear />";
echo "<input type=\"hidden\" name=\"day1\" id=\"day1\" value=\"01\" />";
echo "</form>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=center>Sunday</td><td align=center>Monday</td><td align=center>Tuesday</td><td align=center>Wednesday</td><td align=center>Thursday</td><td align=center>Friday</td><td align=center>Saturday</td>";
echo "</tr>";
}
hope that helps a little.
|
|
|
|
|
|
For your information, I doubt anyone on this forum is gonna click a link for a file from a person they don't know.
Anyway, what is preventing you from opening the file? Is it encrypted?
Even Notepad* is able to open PHP files:
- Right-click on the file, point to "Open with..."
- Select "Notepad" from the list (if it is not visible, click "Choose standard application" and find Notepad in the list)
If that doesn't solve your issue, you're going to have to elaborate a bit.
*Instead of Notepad, I recommend Notepad++[^] which is a great text editor with line numbering, syntax coloring and a lot of other neat features.
|
|
|
|
|
<?php
$to = "someone@domain.com";
$subject = "Test";
$message = "Hello";
$from = "someonelse@domain.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
as far as i understand this is a valid mail function, but on the server it won't send anything to anyone, even my hotmail account .....What am i doing wrong ? this is all the code i have for this particular function so that i can test if it will work to submit feedback results to another mailbox....
(obviously the mail $to email is the one i am only using for this forum post )
i have asked the server support team and they say that this should work?
any ideas what else to try ...
|
|
|
|
|
I have a similar setup and I don't see anything wrong with what you have, so unless I'm blind it looks like it should indeed work. In fact what you have is almost identical to the php documentation.
Are you sure the server email system is working and has the correct settings in the php.ini file?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
turns out the server people lied to me, thanks for your help anyway .... any idea what i could do to get an SMTP?
could i send the information to another website easily or ?
|
|
|
|
|
|
look for class.smtp.php from Chris Ryan.
that s good one for start to send mails using your smtp server.
|
|
|
|
|