Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 6 of 6

Thread: Php help

  1. #1
    Join Date
    Feb 2008
    Location
    Derby
    Posts
    305
    Tokens
    0

    Default Php help

    On my admin page it shows this error:

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/habbohcp/public_html/test/admin.php:2) in /home/habbohcp/public_html/test/admin.php on line 3

    This is the code:

    PHP Code:
    <title>News Administration Panel</title>
    <?php
     session_start
    ();
     
    //Change this to what you wish.
    $_Username "user";
    $_Password "pass";
    //Check to see if the form was submitted.
    if ($_POST['Submitted'] == "True") {
    //Continues if the username and password are right.
        
    if ($_POST['Username'] == $_Username && $_POST['Password'] == $_Password) {
            
    $_SESSION['Logged_In'] = "True";
            
    $_SESSION['Username'] = $_Username;
        }
    }
    //Show the user the form if they are not logged in.
    if ($_SESSION['Logged_In'] != "True") {
        echo
    "<b>Please login:</b> <br>";
        echo 
    "<form method=\"post\" action=\"" $_SERVER['PHP_SELF'] . "\">
            Username: <input type=\"textbox\" name=\"Username\"><br />
            Password: <input type=\"password\" name=\"Password\"><br />
            <input type=\"hidden\" name=\"Submitted\" value=\"True\">
            <input type=\"Submit\" name=\"Login\">
        </form>"
    ;
    }
    else
    {
        echo 
    "You are logged in as: <b>" $_SESSION['Username'] . "</b>
        <br /><a href=\"" 
    $_SERVER['PHP_SELF'] . "?mode=logout\">Logout</a>";
        echo 
    "<br><br>";
    include(
    "config.php");
    include(
    "config.php");
            
    $result mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);
            while(
    $myrow mysql_fetch_array($result))
                 {
                   
    $i=$i 1;
                   echo 
    "<b>$i- Title: ";
                   echo 
    $myrow['title'];
                   echo 
    "</b><br>";
                   
    //We give the user some options.
                   
    echo "<a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>
                    || <a href=\"edit_news.php?newsid=
    $myrow[newsid]\">Edit</a>
                     || <a href=\"delete_news.php?newsid=
    $myrow[newsid]\">Delete</a><br><hr>";
                 }
      if(
    $submit)
      {
        
    //Set this to easier names for yourself.
          
    $title $_POST['title'];
          
    $long $_POST['long'];
          
    $short $_POST['short'];
                  
    //Check if the title is empty.
                  
    if(!$title){
                         echo 
    "Ouch! your news does need a title you know!";//Displays error message.
                         
    exit(); //Kills the script.
                  
    }
             
    $result mysql_query("INSERT INTO news (title, dtime, text1, text2)
                           VALUES ('
    $title',NOW(),'$text1','$text2')",$connect);
              
    //Echo success message.
              
    echo "<b>Your news has been added.<br>You'll be redirected to Home Page after (5) Seconds";
              echo 
    "<meta http-equiv=Refresh content=5;url=index.php>";
      }

      
    //The form hasnt been submitted, lets display it.
    else
      {
          
    ?>
          <br>
          <h3>Add some news?</h3>
          <form method="post" action="<?php echo $PHP_SELF ?>">
          Title: <input name="title" size="40" maxlength="255">
          <br>
          Long: <textarea name="text1"  rows="7" cols="30"></textarea>
          <br>
          Short: <textarea name="text2" rows="7" cols="30"></textarea>
          <br>
          <input type="submit" name="submit" value="Add News">
          </form>
          <?
      
    }
    }
    //If they want to logout.
    if ($_GET['mode'] == "logout") {
        
    //Starts the session.
        
    session_start();
        
    $_SESSION = array();
        
    //Destroys our session :(
        
    session_destroy();
        
    //Gives them the results.
        
    echo "<META HTTP-EQUIV=\"refresh\" content=\"1; URL=" $_SERVER['PHP_SELF'] . "\">";
    }
    ?>
    Win rares and lots more on this thread http://www.habboxforum.com/showthread.php?t=479892
    www.habbo-hc.com -LOOKING FOR STAFF

  2. #2
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Take away the <title></title> SESSION has to be at the top.
    Hi, names James. I am a web developer.

  3. #3
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?php
     session_start
    ();
     
    //Change this to what you wish.
    $_Username "user";
    $_Password "pass";
    //Check to see if the form was submitted.
    echo "<title>News Administration Panel</title>";
    if (
    $_POST['Submitted'] == "True") {
    //Continues if the username and password are right.
        
    if ($_POST['Username'] == $_Username && $_POST['Password'] == $_Password) {
            
    $_SESSION['Logged_In'] = "True";
            
    $_SESSION['Username'] = $_Username;
        }
    }
    //Show the user the form if they are not logged in.
    if ($_SESSION['Logged_In'] != "True") {
        echo
    "<b>Please login:</b> <br>";
        echo 
    "<form method=\"post\" action=\"" $_SERVER['PHP_SELF'] . "\">
            Username: <input type=\"textbox\" name=\"Username\"><br />
            Password: <input type=\"password\" name=\"Password\"><br />
            <input type=\"hidden\" name=\"Submitted\" value=\"True\">
            <input type=\"Submit\" name=\"Login\">
        </form>"
    ;
    }
    else
    {
        echo 
    "You are logged in as: <b>" $_SESSION['Username'] . "</b>
        <br /><a href=\"" 
    $_SERVER['PHP_SELF'] . "?mode=logout\">Logout</a>";
        echo 
    "<br><br>";
    include(
    "config.php");
    include(
    "config.php");
            
    $result mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);
            while(
    $myrow mysql_fetch_array($result))
                 {
                   
    $i=$i 1;
                   echo 
    "<b>$i- Title: ";
                   echo 
    $myrow['title'];
                   echo 
    "</b><br>";
                   
    //We give the user some options.
                   
    echo "<a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>
                    || <a href=\"edit_news.php?newsid=
    $myrow[newsid]\">Edit</a>
                     || <a href=\"delete_news.php?newsid=
    $myrow[newsid]\">Delete</a><br><hr>";
                 }
      if(
    $submit)
      {
        
    //Set this to easier names for yourself.
          
    $title $_POST['title'];
          
    $long $_POST['long'];
          
    $short $_POST['short'];
                  
    //Check if the title is empty.
                  
    if(!$title){
                         echo 
    "Ouch! your news does need a title you know!";//Displays error message.
                         
    exit(); //Kills the script.
                  
    }
             
    $result mysql_query("INSERT INTO news (title, dtime, text1, text2)
                           VALUES ('
    $title',NOW(),'$text1','$text2')",$connect);
              
    //Echo success message.
              
    echo "<b>Your news has been added.<br>You'll be redirected to Home Page after (5) Seconds";
              echo 
    "<meta http-equiv=Refresh content=5;url=index.php>";
      }

      
    //The form hasnt been submitted, lets display it.
    else
      {
          
    ?>
          <br>
          <h3>Add some news?</h3>
          <form method="post" action="<?php echo $PHP_SELF ?>">
          Title: <input name="title" size="40" maxlength="255">
          <br>
          Long: <textarea name="text1"  rows="7" cols="30"></textarea>
          <br>
          Short: <textarea name="text2" rows="7" cols="30"></textarea>
          <br>
          <input type="submit" name="submit" value="Add News">
          </form>
          <?
      
    }
    }
    //If they want to logout.
    if ($_GET['mode'] == "logout") {
        
    //Starts the session.
        
    session_start();
        
    $_SESSION = array();
        
    //Destroys our session :(
        
    session_destroy();
        
    //Gives them the results.
        
    echo "<META HTTP-EQUIV=\"refresh\" content=\"1; URL=" $_SERVER['PHP_SELF'] . "\">";
    }
    ?>
    Lets set the stage on fire, and hollywood will be jealous.

  4. #4
    Join Date
    Feb 2008
    Location
    Derby
    Posts
    305
    Tokens
    0

    Default

    Yes thanks i fixed it ealier but didnt want to double post to let people know
    Win rares and lots more on this thread http://www.habboxforum.com/showthread.php?t=479892
    www.habbo-hc.com -LOOKING FOR STAFF

  5. #5
    Join Date
    Apr 2008
    Location
    England.
    Posts
    1,324
    Tokens
    0

    Latest Awards:

    Default

    I did tell you this on urtut, you need to take out the <title></title> I forgot to take them out of the tutorial, sorry.

  6. #6
    Join Date
    Feb 2008
    Location
    Derby
    Posts
    305
    Tokens
    0

    Default

    Quote Originally Posted by Gork View Post
    I did tell you this on urtut, you need to take out the <title></title> I forgot to take them out of the tutorial, sorry.
    Lol i posed this before you told me read aboe posts
    Win rares and lots more on this thread http://www.habboxforum.com/showthread.php?t=479892
    www.habbo-hc.com -LOOKING FOR STAFF

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •