1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Freak php problem in bluehost

Discussion in 'PHP' started by arp059, Feb 7, 2010.

  1. #1
    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.

     
    arp059, Feb 7, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi,

    Just remove:
    echo 'correct login';
    PHP:
    for correct login.
    Regards,
    Nick
     
    koko5, Feb 7, 2010 IP
  3. arp059

    arp059 Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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?
     
    arp059, Feb 7, 2010 IP
  4. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #4
    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
     
    koko5, Feb 7, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    Although not recomended, you can also use output buffering, to overcome that.
     
    danx10, Feb 7, 2010 IP
  6. hostgenius

    hostgenius Guest

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    hostgenius, Feb 8, 2010 IP
  7. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #7
    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:
     
    danx10, Feb 8, 2010 IP