Page 1 of 3 123 LastLast
Results 1 to 10 of 22
  1. #1
    Elite Member
    Join Date
    Mar 2008
    Gender
    Female
    Posts
    1,136

    Default help me in php, am a newbie


    I have found this tutorials in the internet when i run the registration page i dont have the problem whatsoever... but when i try to run this login.php there's an error saying....below..


    Warning: Cannot send session cookie - headers already sent by (output started at c:\apache\htdocs\login\login.php:2) in c:\apache\htdocs\login\login.php on line 3

    Warning: Cannot send session cache limiter - headers already sent (output started at c:\apache\htdocs\login\login.php:2) in c:\apache\htdocs\login\login.php on line 3

    can you please help me how to debug this error. the code below....


    for register.php




    <form action='actions.php' method='post'>
    <table cellpadding='2' cellspacing='0'>
    <tr>
    <td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
    Username
    </td>
    <td>
    <input type='text' name='f_username'>
    </td>
    </tr>
    <tr>
    <td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
    Password
    </td>
    <td>
    <input type='password' name='f_password'>
    </td>
    </tr>
    <tr>
    <td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
    First name
    </td>
    <td>
    <input type='text' name='f_fname'>
    </td>
    </tr>
    <tr>
    <td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
    Last name
    </td>
    <td>
    <input type='text' name='f_sname'>
    </td>
    </tr>
    <tr>
    <td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
    E-mail adress
    </td>
    <td>
    <input type='text' name='f_email'>
    </td>
    </tr>
    <tr>
    <td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>

    </td>
    <td>
    <input type='submit' name='f_save' value='Save'>
    </td>
    </tr>
    </table>
    </form>

    for login.php


    <?php
    session_start();

    echo"
    <form action='actions.php' method='post'>
    <table cellpadding='2' cellspacing='0'>
    <tr>
    <td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
    Username
    </td>
    <td>
    <input type='text' name='f_username'>
    </td>
    </tr>
    <tr>
    <td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
    Password
    </td>
    <td>
    <input type='password' name='f_password'>
    </td>
    </tr>
    <tr>
    <td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>

    </td>
    <td>
    <input type='submit' name='f_login' value='login'>
    </td>
    </tr>
    </table>
    </form>
    <br>".$_SESSION['login_error'];

    ?>


    and for the actions.php


    <?php
    session_start();// We need the session to keep the user logged in.
    include('connect.php'); // We need to connection to execute queries

    if($_POST['f_save'])
    {
    // First we check if all fields are not empty.
    if(!empty($_POST['f_username'])
    && !empty($_POST['f_password'])
    && !empty($_POST['f_fname'])
    && !empty($_POST['f_sname'])
    && !empty($_POST['f_email']))
    {
    // If not empty we will execute this code.

    // Here we will convert the password to an md5 encrypted code.
    $password = md5($_POST['f_password']);

    if(!mysql_query("INSERT INTO users
    (username,password,firstname,lastname,email)
    VALUES('".$_POST['f_username']."',
    '".$password."',
    '".$_POST['f_fname']."',
    '".$_POST['f_sname']."',
    '".$_POST['f_email']."') "))
    {
    echo "There was an error tryign to write the information to the database.";
    }
    else
    {
    echo $_POST['f_username']." has succesfully been added.";
    }
    }
    else
    {
    // Not all information has been given.. you will
    // automaticly return to the register page.
    header("Location: ".$_SERVER['HTTP_REFERER']." ");
    }
    }
    elseif($_POST['f_login'])
    {
    $get_user = mysql_query("SELECT * FROM users WHERE
    username='".$_POST['f_username']."'
    AND password='".md5($_POST['f_password'])."' ");

    if(mysql_num_rows($get_user) > 0)// Means it's got result.
    {
    $_SESSION['s_username'] = $_POST['f_username'];
    $_SESSION['s_password'] = md5($_POST['f_password']);

    // The session variables have been made.
    // You can send your user to the wanted page, in this case.. index.php.
    // Please change the domain to your own.
    header("Location: http://www.domain.com/index.php");
    }
    else
    {
    $_SESSION['login_error'] = "Your login information was incorrect.";
    // Please change the domain to your own.
    header("Location: http://www.domain.com/login.php");
    }
    }

    ?>

    for index.php


    <?php
    session_start();// We need the session to keep the user logged in.
    include('connect.php'); // We need to connection to execute queries

    $get_user = mysql_query("SELECT * FROM users WHERE
    username='".$_SESSION['s_username']."'
    AND password='".$_SESSION['s_password']."' ");

    if(mysql_num_rows($get_user) > 0)// Means it's got result.
    {
    $row_user = mysql_fetch_array($get_user);// provides you with user info
    echo "
    Welcome ".$row_user['firstname']." ".$row_users['lastname']."
    <br><br>
    Click <a href='logout.php'>here</a> to log out!";

    // This will output a welcome message plus the link to the logout file.
    }
    else
    {
    // The user is not logged in.. so that means he has got to go to the login page.
    // Please change the domain to your own.
    header("Location: http://www.domain.com/login.php");
    }
    ?>


    for the logout.php


    <?php
    session_start();// You need to open the session.. if not it wont get destroyed.

    /*session_destroy() is the function to destroy all current session values
    instead of this you could also use the unset() function.
    With unset you will have to specify what variables you want to be desroyed.
    Example: unset($string,$string2);*/
    session_destroy();
    // Please change the domain into your own.
    header("Location: http://www.domain.com/login.php");

    ?>

  2. #2
    try daw ilisdi ng $_SESSION['login_error'] sa !empty($_SESSION['login_error'])?$_SESSION['login_error']:''.

  3. #3
    hmmm.. sabton sa nko imo code bro.. tapos post ko bag.o reply.. ^__^

  4. #4
    first imo jud ipa execute ang php script nimo mao nang hi hatag siya ug headers already sent nimo nga error.

    mao na si sulti siya nga "Cannot send session cookie" kay naa na kay na send nga http headers. naa rana sa code placement nimo bro.

  5. #5
    Elite Member
    Join Date
    Mar 2008
    Gender
    Female
    Posts
    1,136
    Ondoy error manlang gihapon ...

  6. #6
    Elite Member
    Join Date
    Mar 2008
    Gender
    Female
    Posts
    1,136
    Tin tin i find, its hard to understand what you mean about.. can you please be more specific please....

  7. #7
    Naa kay space before sa <?php tag nimo sa login.php?

  8. #8
    Elite Member
    Join Date
    Mar 2008
    Gender
    Female
    Posts
    1,136
    doomsweek wla man tingali

  9. #9
    I tried running your login.php pero okay raman.

  10. #10
    sa actions.php, dli man cguro pwede mag echo nya mag header() pa jud... la noon ko sure!!! hehehe

  11.    Advertisement

Page 1 of 3 123 LastLast

Similar Threads

 
  1. Help me in Assembly
    By mondray in forum Programming
    Replies: 33
    Last Post: 11-03-2011, 03:49 PM
  2. please help me in this" vista os for internet cafe ok lang ba?
    By EnterBEN in forum Software & Games (Old)
    Replies: 46
    Last Post: 01-21-2008, 03:29 PM
  3. Help me in getting out the virus
    By mondray in forum Software & Games (Old)
    Replies: 8
    Last Post: 09-21-2007, 10:38 AM
  4. MOVED: Help me in Assembly
    By vern in forum Software & Games (Old)
    Replies: 0
    Last Post: 09-13-2007, 02:45 PM
  5. Please help me in martial arts.
    By Chalil in forum Sports & Recreation
    Replies: 11
    Last Post: 09-20-2006, 10:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top