PDA

View Full Version : Php help



=Collecting=
25-04-2008, 11:08 AM
On my admin page it shows this error:

Warning: session_start() [function.session-start (http://habbo-hc.com/test/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:


<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'] . "\">";
}
?>

Protege
25-04-2008, 03:15 PM
Take away the <title></title> SESSION has to be at the top.

Decode
25-04-2008, 05:19 PM
<?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'] . "\">";
}
?>

=Collecting=
25-04-2008, 05:27 PM
Yes thanks i fixed it ealier but didnt want to double post to let people know

Excellent
25-04-2008, 05:33 PM
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.

=Collecting=
25-04-2008, 08:17 PM
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 :P read aboe posts

Want to hide these adverts? Register an account for free!