Hi, I am moving my site from dreamhost to bluehost. The php code working fine on DH is not working as expected on BH. I am attaching the code below for review. Kindly have a look at the code and reply me the problem with the code and correction. <?php if (isset($_POST['submit']) && !empty($_POST['admin']) && !empty($_POST['password'])){ if ((trim($_POST['admin'])=='myusername') && (sha1(trim($_POST['password']))=='1xyz9084a710c02e5bcfkp5a3feds039e059trsd')) { echo 'correct login'; setcookie("admin", "myusername", time()+3600); header("location: admin.php");} } if ($_COOKIE['admin']=='myusername') header("location: admin.php"); ?> <html> <form method = "POST" action="<?php $_SERVER['PHP_SELF'] ?>"> <label>Username: </label> <input type="text" name="admin" /> <label>Password: </label> <input type="password" name = "password" /> <input type="submit" name="submit" value="login" /> </html> PHP: The following error message is displayed when I tried to login.
Thanks a lot Nick, that worked fine. There is another page which has similar issue. But in that case, the echo is needed. In this page, as I am the only person accessing this page, removing the echo works, but visitors should be able to see that echo in other page. How can I handle that?
Hi arp059, In the other page you've to check are cookies OK and if yes then echo some text,if not - exit or redirect to log-in page. Regards, Nick
u should not have any output before your header('loction:xx'); use output buffering, OR adapt your script, if its just 1 echo, im sure u'll find a way, i have this problem all the time, and usually just fix it by switching things around. harldy ever do i use buffering i dont get the point of your first echo anyway u are echoing, and then redirecting ? so who is gonna see the echo ? anyways, feel free to ask me for help.
At the top of your php code place: <?php ob_start(); ?> PHP: and at the end of your php code place: <?php ob_flush(); ?> PHP: