|
How can I build tab & menu in php?please write html code
|
|
|
|
|
elhammemariyan wrote: please write html code
You can't program in HTML. Start here[^]
I are Troll
|
|
|
|
|
Hey guys!
I am working on a dynamic website which fetches content from its database.
When the content for a specific request cannot be found I would like to display a custom 404 page. I have added the following lines at the top of my 404 script for SEO purposes:
if (substr(php_sapi_name(), 0, 3) == 'cgi')
header("Status: 404 Not Found");
else
header("HTTP/1.1 404 Not Found");
This has been working fine for me, but the website that I am working on at the moment is causing me problems. It is an Apache server running PHP 5.2 (FastCGI) on Linux CentOS.
Instead of showing the error page I get Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error.
In an attempt to isolate the problem I have created the following standalone page for testing this. This very simple script is failing:
<?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>
Any help would be greatly appreciated!
Kind regards,
|
|
|
|
|
If your HTML or PHP has any whitespace before the opening <?php tag,
header() will fail to do what you expect.
Quoting the PHP manual:
Remember that header() must be called before any actual output is sent, either by normal HTML tags,
blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(),
functions, or another file access function, and have spaces or empty lines that are output before header()
is called. The same problem exists when using a single PHP/HTML file.
Cheers,
Peter (bitten by this more than once!)
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Hi Peter,
Thank you for your response.
I have double-checked and there is no output (not even whitespace) above. The test script is working fine on other web servers, but is failing on just this one.
I cannot make any sense of it. And there are no errors being logged on the server. It is a shared hosting Linux package with FastHosts (if this makes any difference).
Many thanks,
Lea
|
|
|
|
|
If it works on one server but not another, it smells like a server config is contributing to the problem. I suggest you put one or more echo('x') statements in strategic places and use something like WireShark to see exactly what the server is returning. You should be able to spot the difference between good and bad servers pretty quickly.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
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.
|
|
|
|
|
|