Php help

EHDEHD

Well-known member
  • Nov 3, 2007
    10,571
    2,957
    113
    බළපිටිය
    mata podi help ekak oneeeeee

    me thiyenne login page eka php code eke



    <?php
    $username = "you_asha";
    $password = "19950103";
    $hostname = "localhost";
    $con=mysql_connect($hostname,$username,$password) ;
    $select = mysql_select_db("you_good", $con);
    $result = mysql_query("select CreateUser,CreatePassword FROM gayan");
    while ($row = mysql_fetch_array($result)) {

    $u1= $row{'CreateUser'};
    $p1=$row{'CreatePassword'};

    }
    $user=$_POST['CreateUser'];
    $pass=$_POST['CreatePassword'];
    if ($user == $u1 && $pass ==$p1 )
    {
    echo "Welcome " . $user;

    }
    else
    {
    header("Location: invalid.php");
    }

    ?>


    meka hadala server ekata dala test karahama... user name eka harita gahuwama annawa waradiyata gahuwahama anne hadala thiyenne header("Location: invalid.php"); metethenta athe mehema error ekak anwa

    Warning: Cannot modify header information - headers already sent by (output started at /home/Youuser/public_html/register/welcom.php:6)
     

    isuru143

    Well-known member
  • May 6, 2007
    4,053
    68
    48
    In this Planet
    use ob_start at the begining of the page

    like
    <?php
    ob_start();
    ?>


    Output buffering is not supported on all servers. (Though most do).

    To test if you have Output buffering support try this on a php page on your server::

    Code:
    <?php
    
    ob_start();
    
    echo 'dummy content';
    
    if (headers_sent() || !ob_get_length()) {
       echo 'Your sever does not support output buffering';
    } else {
       echo 'Output buffering supported';
      ob_clean();
    }
    
    
    ?>

    If your server does support output buffering, then it may be that the buffer is being dumped prematurely before you're sending your headers. This could be happening if you're using flush() or ob_flush() before you use header().

    When you use the header() function, you should always check if headers have been sent or not...

    Here's an example function to use in place of header():

    Code:
    function safe_header($str) {
       if (!headers_sent()) {
          <strong class="highlight">header</strong>($str);
          return true;
       }
       return false;
    }

    What way you get a return of false if the header could not be sent.

    Example Use:

    Code:
    if (safe_header('Location: login.php')) {
       die;
    } else {
       echo '<script>location = 'login.php';</script>';
       echo 'Please <a href="login.php">Login</a>';
       die;
    }

    Note that if headers are already sent then you cannot send any more headers or you'll get the error you're getting. So instead you can send some content such as JS to try and redirect the page. If the user does not use JS, then you'll have to fallback to a link.
     

    manojdhrma

    Well-known member
  • Aug 26, 2011
    1,031
    560
    113
    මචං.. මේකට හේතු කීපයක් තියෙනව. ප්‍රධානම හේතුව තමයි... PHP වලින් header location එකක් දුන්නට පස්සෙ ඒක ආපහු loop වෙනකොට ඔහොම ප්‍රශ්නයක් එනව. හොඳම දේ server connection එක වෙනම file එකක හදල ඒක මෙතනට link කරන්න. code එකේ spacing එහෙම චෙක් කරල බලල අනවශ්‍ය space ඔක්කොම delete කරල දාන්න.
     

    manojdhrma

    Well-known member
  • Aug 26, 2011
    1,031
    560
    113
    pahadili madi bn pahadili karala kiyanna Plzzzzzzzzz

    මචං... මේ code එකේ හැටියට නම්... login එක success නම්... ඒ කිව්වෙ... user name & passwords හරි නම්.. welcome.php එකට නේද යන්න ඕනෙ...? නමුත් login එක success වුණාට welcome page එකට යන්නෙ නැහැ. error එකක් එනව. ඒ කියන්නෙ... මුලින් code කරල තියෙන page එකේ ඉඳන් ඔයා කලින් ම header location එකක් යවල ඉවරයි. දැන් ඔයා බලන්න welcome.php හරි log වුනාට පස්සෙ එන්න ඕනෙ page එකෙත් ආයෙමත් header location එකක් දීලද කියල. එතකොට loop වෙනව code එක. එතන හදල බලන්න. බොහෝ දුරට හරියයි...
     

    ishan001

    Active member
  • Sep 10, 2006
    327
    43
    28
    echo "<script language=\"javascript\" type=\"text/javascript\">document.location.replace('invalid.php');</script>";

    meka replace karapan

    else eke part ekata ( header("Location: invalid.php"); )
     

    EHDEHD

    Well-known member
  • Nov 3, 2007
    10,571
    2,957
    113
    බළපිටිය
    මචං... මේ code එකේ හැටියට නම්... login එක success නම්... ඒ කිව්වෙ... user name & passwords හරි නම්.. welcome.php එකට නේද යන්න ඕනෙ...? නමුත් login එක success වුණාට welcome page එකට යන්නෙ නැහැ. error එකක් එනව. ඒ කියන්නෙ... මුලින් code කරල තියෙන page එකේ ඉඳන් ඔයා කලින් ම header location එකක් යවල ඉවරයි. දැන් ඔයා බලන්න welcome.php හරි log වුනාට පස්සෙ එන්න ඕනෙ page එකෙත් ආයෙමත් header location එකක් දීලද කියල. එතකොට loop වෙනව code එක. එතන හදල බලන්න. බොහෝ දුරට හරියයි...
    Reply With Quote

    Puluwan nam hadala denawada
     

    EHDEHD

    Well-known member
  • Nov 3, 2007
    10,571
    2,957
    113
    බළපිටිය
    echo "<script language=\"javascript\" type=\"text/javascript\">document.location.replace('invalid.ph p');</script>";

    meka replace karapan

    else eke part ekata ( header("Location: invalid.php"); )
    Reply With Quote
    wdeeeeee hari machan thanks