php - header(...) not work

craberic

New Member
Messages
3
Reaction score
0
Points
0
Hi This is my first post.<br><br>I have script like:<br><br>index.html<br>{<br>&nbsp;if ($_GET[id]=="LOGIN") include("login.php");<br>&nbsp;if ($_GET[id]=="HOME") include("home.php");<br>}<br><br>home.php<br>{<br>&nbsp;echo"HOME;)";<br>}<br><br>login.php<br>{<br><br>&nbsp;if (isset($_POST[sbmt_login])) &nbsp;<br>&nbsp;{<br>&nbsp; // logged ok now display HOME !!!!!!!!!!!<br><br>&nbsp; &nbsp;header("lacation:index.html?id=HOME");<br>&nbsp; &nbsp;exit;<br>&nbsp;}<br><br>&nbsp;&lt;form action="index.html?id=LOGIN"&gt;<br>&nbsp; .....<br>&nbsp; .....&nbsp;<br>&nbsp; &lt;input type"submit" name"sbmt_login" ...&gt;<br>&nbsp;&lt;/form&gt;<br><br>}<br><br>After click login botton HOME string is displayed.<br>This work on my local Apahe instalation, but when move to&nbsp;x10hosting deos not.<br><br>I search solution all day and can't find.<br>Please help.<br>

---------- Post added at 01:14 AM ---------- Previous post was at 12:59 AM ----------

Hi This is my first post.

I have script like:

index.html
{
if ($_GET[id]=="LOGIN") include("login.php");
if ($_GET[id]=="HOME") include("home.php");
}

home.php
{
echo"HOME;)";
}

login.php
{

if (isset($_POST[sbmt_login]))
{
// logged ok now display HOME !!!!!!!!!!!
header("lacation:index.html?id=HOME");
exit;
}

<form action="index.html?id=LOGIN" ... >
.....
.....
<input type"submit" name"sbmt_login" ... >
</from>

}

After click login botton HOME string is displayed.
This work on my local Apahe instalation, but when move to x10hosting deos not.
I search solution all day and can't find

Please help.

---------- Post added at 01:29 AM ---------- Previous post was at 01:14 AM ----------

... and in index.html i have:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<meta name="Description" content="......." />
<meta name="Keywords" content="......" />
<title> TITLE </title>

<script language="JavaScript" src="scripts/somescript.js" type="text/javascript"></script>
<script src="scripts/ajax.js" type="text/javascript"></script>
</head>

<body>
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
header("lacation:index.html?id=HOME");

Problem #1

while Problem #2 is that .html files here are not parsed as PHP files. The extension must be .php
 
Last edited:

craberic

New Member
Messages
3
Reaction score
0
Points
0
THANKS

Problem#1 not exist: in orginal source i have location not lacation.
Problem#2 not exist: in .htaccess i have AddType application/x-httpd-php .html

Any other ideas ?
 

craberic

New Member
Messages
3
Reaction score
0
Points
0
I think this is not programming problem but something other.

I have:


str1.html

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<meta name="Description" content="...."/>
<meta name="Keywords" content="...."/>
<title> TITLE </title>
</head>
<body bgcolor="gray">
<?php
header("location:str2.html");
?>
</body>
</html>


and str2.html

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<meta name="Description" content="...."/>
<meta name="Keywords" content="...."/>
<title> TITLE </title>
</head>
<body bgcolor="gray">
<center>
THIS IS str2.html
</body>
</html>


when open http://localhost/str1.html on my local Apahe instalation it's ok (move to str2.html)

but when I try this (http://mydomian.x10.mx/str1.html) on my x10hosting.com account, this does't work

Do x10hosting.com serve function header() in free account?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
I go to your str1.html and the page you presented above is not what is sent.

It is a programming problem. header() works on the free accounts where the person knows what to do.
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Unless you have output buffering turned on (it's off by default), then sending header information after sending anything else (including white space or the byte order mark for a Unicode file) is not going to work—you'll just get the "headers already sent" error.

You can't always count on being able to turn on output buffering (it depends on the host, since it claims memory until the page is complete), so the safest thing to do is to put all of your header-munging code right at the top of the file. There should be nothing but an opening <?php tag and the logic leading up to the header() statements at the top of the file. Any HTML output, echos, or any includes/requires that generate output should come after your header() statements have finished.
 

ellescuba27

Member
Messages
273
Reaction score
3
Points
18
They're right, this code will work in Apache but on any hosting server you try I guarantee headers have to be before anything.

HTML:
<?php
// put any code here, but do not use anything that will output to the page eg print echo etc.
header("put header here");
?>
<body>
<head>
<title>Page title</head>
</head>
<body>
</body>
</html>
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
@craberic: Please use
PHP:
, [html] or [code] tags (as appropriate) to separate and format code.

Giving PHP scripts the correct extension is simpler and more efficient overall. There isn't much of a performance loss with your configuration, but all HTML files will still be processed as PHP, which is needlessly wasteful.

[quote="craberic, post: 883295"]
[php]
 if (isset($_POST[sbmt_login]))
[/QUOTE]
Array indexes (the value of an expression within square brackets) must be strings or integers. sbmt_login isn't either. PHP interprets it as an undefined constant, giving it the value of a string equivalent to the constant, but may also issue a notice depending on the error reporting setting. If it does, the error is output in the body, which will naturally make it impossible for headers (such as the "Location" header) to work. Make sure you read up on arrays in the PHP manual.


HTML:
 <script language="JavaScript" src="scripts/somescript.js" type="text/javascript"></script>
The language attribute is deprecated in HTML4 and nonexistent in HTML5. Leave it out.
 
Top