Page 1 of 1

Redirection error.

Posted: Fri May 06, 2011 12:35 am
by Temor
So, I've got this ( probably really stupid ) problem that I just can't solve.
I have a really simple login script attached to an index.php page by including it in the header. Whenever I try to login chrome gives me this error:
The website encountered an error while retrieving <-Insert url here -!> . It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this web page later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

The script works fine on localhost, the error is only shown when run on a paid webhost. Does anyone have an idea of what might be wrong?

Re: Redirection error.

Posted: Fri May 06, 2011 3:36 am
by Tino
What's your code?

Re: Redirection error.

Posted: Fri May 06, 2011 9:53 am
by jacek
Error 500 means nothing to do with php.

Are you using a .htaccess file ?

Re: Redirection error.

Posted: Fri May 06, 2011 11:45 am
by Temor
jacek wrote:Error 500 means nothing to do with php.

Are you using a .htaccess file ?


No, I am not.
And I only get this error when I submit the login form( it redirects from index.php TO index.php ).


/E I just realized I have the same problem when I use the Register form.

Re: Redirection error.

Posted: Fri May 06, 2011 12:00 pm
by jacek
Can you post your code ?

Although I can't think of anything that would cause that, it might be worth contacting your host.

Re: Redirection error.

Posted: Fri May 06, 2011 12:23 pm
by Temor
[/syntax]
jacek wrote:Can you post your code ?

Although I can't think of anything that would cause that, it might be worth contacting your host.

I have tons of sites running on that host, and none of them are having any errors.

The index page looks like this : [syntax=php]<?php
include('design/header.php');
?>[/syntax]

followed by some static HTML.

Header( I think the login is from your tutorials even ) :[syntax=php]<?php
/* Initialization */
include('core/init.inc.php');

$errors = array();

if (isset($_POST['username'], $_POST['password'])){
if (empty($_POST['username'])){
$errors[] = 'Du måste skriva in ett användarnamn.';
}

if (empty($_POST['password'])){
$errors[] = 'Du måste skriva in ett lösenord.';
}

if (valid_credentials($_POST['username'], $_POST['password']) === false){
$errors[] = 'Fel användarnamn eller lösenord.';
}

if(empty($errors)){
$_SESSION['username'] = htmlentities($_POST['username']);

Header('Location: index.php');
die();
}
}
?>
<html>
<body>
<td width='50%'>
<?php

if(isset($_SESSION['username']))
{
echo "
<table id='welcomeTable'>
<td>
<font size='2' face='arial'> <div align='center'>Välkommen, <b> ".$_SESSION['username']."</b>! <a href='logout.php'>Logga ut</a>
</td>
</table>";

}

else
{
?>
<form action="index.php" method="POST">
<table id="loginTable">
<tr>
<td>
<label for='username'>Användarnamn:</label>
</td>
<td>
<font size='2' face='arial'> <input type='text' name='username' size='16' maxlength='25'/><a href='register.php'>Registerera.</a></font>
</td>
</tr>
<tr>
<td>
<label for='password'>Lösenord:</label>
</td>
<td>
<font size='2' face='arial'> <input type='password' name='password' size='16' maxlength='15'/> <input type='submit' value='Log In'/></font>
</td>
</tr>
</table>
</form>
<div id="indexPageLoginErrors">
<?php
if (empty($errors) === false){
?>
<ul>
<?php

foreach ($errors as $error){
echo "<li>{$error}</li>";
}

?>

</ul>
<?php
}

}


?>
</div>


</td>

</tr>
</table>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>

</body>
</html>[/syntax]

Its probably something really silly. If it is, please don't rub it in my face :) And please do ignore all the Swedish mumbojumbo. I did this site for a friend, and he totally refuses to have anything in english.

Re: Redirection error.

Posted: Fri May 06, 2011 12:34 pm
by jacek
Well the code looks fine :? (except the use of table and the font tag obviously)

[syntax=php]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<pre><?php print_r($_POST); ?></pre>
<div>
<form action="" method="post">
<p>
<input type="text" name="test" value="something" />
</p>
<p>
<input type="submit" value="Go" />
</p>
</form>
</div>
</body>
</html>[/syntax]
You could try this on your host and see if it has the same problem, something else to try would be changing the names of the inputs (mainly username and password)

If the above script causes the problem, you will have to ask your host though.

Re: Redirection error.

Posted: Fri May 06, 2011 12:52 pm
by Temor
jacek wrote:Well the code looks fine :? (except the use of table and the font tag obviously)

[syntax=php]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<pre><?php print_r($_POST); ?></pre>
<div>
<form action="" method="post">
<p>
<input type="text" name="test" value="something" />
</p>
<p>
<input type="submit" value="Go" />
</p>
</form>
</div>
</body>
</html>[/syntax]
You could try this on your host and see if it has the same problem, something else to try would be changing the names of the inputs (mainly username and password)

If the above script causes the problem, you will have to ask your host though.


Your script works just fine, and changing the input names makes no difference.
Tried this on 2 other hosts aswell, both have the same issue. So I doubt its server-side.
I think its in the code somewhere.

Re: Redirection error.

Posted: Fri May 06, 2011 12:59 pm
by Tino
I've heard of people having trouble with sending headers when not using a full absolute path. Try redirecting to http://www.google.com/ and see what happens.

To be honest I doubt this is your problem, but it's always worth a shot, right?

Re: Redirection error.

Posted: Fri May 06, 2011 1:05 pm
by jacek
Very odd problem.

Do you get redirected ? Or does the error happen before you get to that point.

Re: Redirection error.

Posted: Fri May 06, 2011 1:14 pm
by Temor
Tino wrote:I've heard of people having trouble with sending headers when not using a full absolute path. Try redirecting to http://www.google.com/ and see what happens.

To be honest I doubt this is your problem, but it's always worth a shot, right?

It redirects me to google, and then it gives me an 405 error since I tried to pass my own $_POST info and it did not like that very much.

jacek wrote:Very odd problem.

Do you get redirected ? Or does the error happen before you get to that point.

I do get redirected to the index.php, and THEN get the error message. Sometimes I even catch a glimpse of the site before getting shown the error message.

And its not just on my pc, I've had some friends try it and they all have the same problem.

Re: Redirection error.

Posted: Fri May 06, 2011 1:16 pm
by jacek
Can you post the fill code of index.php then I guess it has to be something to do with that :?

Re: Redirection error.

Posted: Fri May 06, 2011 1:18 pm
by Temor
jacek wrote:Can you post the fill code of index.php then I guess it has to be something to do with that :?

Sure, but I really doubt that HTML, no matter how badly written, can crash a browser :S
[syntax=xhtml]

<html>
<head>

<title>PhearCIII Designs</title>
<link rel="shortcut icon" href="./icone.jpg">
<link href="design/mall.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="hela">

<div id="meny">
<ul>
<li><a href="index.php">Index</a></li>
<?php if(!empty($_SESSION['username'])){
echo"
<li><a href='uppgifter.php'>Uppgifter</a></li>";
}
?>
<li><a href="kontakt.php">Kontakt</a></li>
</ul>
</div>

<div id="linje">
<IMG SRC="design/header.jpg" WIDTH="617" HEIGHT="186" BORDER="0"></div>

<div id="text">
<div id="rubrik">Nyheter</div>
<p><b>25 November 2010</b> <br><br>- Jag gör om hela designen på hemsidan, den börjar ta form! Ska även lägga till fler funktioner så som att förhindra högerklick och ctrl + tangenttryckningar på sidan för att stoppa alla klåfingrade besökare.


<br><br><br>© Oliwer Erichsen 2010

</p>
</div>
</div>

<div id="text2">
<div id="rubrik">Välkommen</div>
<p>När du ändå har tagit dig tid till och titta in här kan jag förklara varför jag ens har hemsidan.
Eftersom att jag går en linje där vi har datorinriktning så har vi webbdesign som ett ämne och då måste vi ju ha en hemsida där vi lägger upp uppgifter och sånt.
Anledningen till att "uppgifter" är lösenordsskyddat är för att jag inte vill att någon ska kopiera källkoder från mina uppgifter bara för att dom ska få det lättare i skolan, man får helt enkelt arbeta själv.
Utöver det så tycker jag att kodning är kul, så utvecklar sidan mer än vad som behövs hela tiden.


<br><br>Vid frågor så får du kontakta mig, tryck på fliken "kontakt" så finns det information så att du enkelt kan komma i kontakt med mig.</p>
</div>
</div>
</body>

</html>[/syntax]

Re: Redirection error.

Posted: Fri May 06, 2011 1:23 pm
by jacek
Irritatingly I have no idea then !

Are you sure there is no .htaccess file in your site root anywhere, they are generally hidden ? that's the only thing I can think of that would cause that problem.

Re: Redirection error.

Posted: Fri May 06, 2011 1:31 pm
by Temor
jacek wrote:Irritatingly I have no idea then !

Are you sure there is no .htaccess file in your site root anywhere, they are generally hidden ? that's the only thing I can think of that would cause that problem.

There could be a hidden one, but It does not interfere with any of the 12 other pages I have on that domain. And how would I go about deleting/editing this hidden .htaccess file?

Re: Redirection error.

Posted: Fri May 06, 2011 1:58 pm
by jacek
Via FTP or the web based file manager thing.

If it exists just rename it to see if it fixes the problem.

you may have to mess with the settings of your FTP client to get it to show up.

Re: Redirection error.

Posted: Fri May 06, 2011 2:05 pm
by Temor
jacek wrote:Via FTP or the web based file manager thing.

If it exists just rename it to see if it fixes the problem.

you may have to mess with the settings of your FTP client to get it to show up.

Alright, I'll try this.

Heading off to the gym now. Will try this when I get back. In the meantime, if anyone got any ideas. Feel free to post them!