Jump to content


Photo

setting cookies


  • Please log in to reply
2 replies to this topic

#1 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 19 March 2006 - 02:56 AM

The php in this file works, as long as the html is gone, whats wrong with the html?

<html>
<head>

<link rel='stylesheet' type='text/css' href='mreds.css' />
<link rel='alternate stylesheet' type='text/css' media='screen' title='mmilds' href='mmilds.css' />
<link rel='alternate stylesheet' type='text/css' media='screen' title='mmenthollights' href='mmenthollights.css' />
<link rel='alternate stylesheet' type='text/css' media='screen' title='mno27s' href='mno27s.css' />

</head>
<body onLoad='goforit()' align=center>

<table border=0 height=100% width=100%><tr><td vAlign=middle align=center>

<table border=0 cellspacing=0 cellpadding=0 bgcolor='#ffffff'>
<tr>
<td><img src='images/layout/cornerleft.png' height='26' width='31'></img></td><td><img src='images/layout/top.png' height='26' width='100%'></img></td><td><img src='images/layout/cornerright.png' height='26' width='31'></img></td></tr>
<tr>
<td class='loginoroutleft'></td><td align=center>

<!-- start shit -->
        <table border=0 width=300 cellspacing=0 cellpadding=0>
        <tr>
        <td align=left vAlign=top width=100% cellspacing=0 cellpadding=0>
                    <table border=1 width=100% cellspacing=0 cellpadding=0><tr><td align=left vAlign=top class='menuheadertop' width=100%>
            <b>Status</b>
                    </td></tr></table>
        </td>
        </tr>
        <tr>
        <td align=left width=100%>
                    <table border=1 width=100% height=100 cellspacing=0 cellpadding=0><tr><td vAlign=top class='menuheaderbottom' width=100% align=center>

<?php

$user = $_POST["UserName"];
$pass = $_POST["PassWord"];
$UID = 1;

if ($_POST["UserName"] == "user" && $_POST["PassWord"] == "pass") {

    setcookie("UserName", $user, time()+3600);
    setcookie("Password", $pass, time()+3600);
    setcookie("UID", $UID, time()+3600);

    echo "Logged in as $user.";
    echo "<br><br><a href='index.php' align=left>Continue</a>";

   } else {

    echo "Invalid username or password.";
    echo "<br><br><a href='index.php' align=left>Continue</a>";

   }

?>

                </td></tr></table>
        </td>
        </tr>
        </table>
<!-- end shit -->

</td><td class='loginoroutright'></td></tr>
<tr><td><img src='images/layout/cornerleftbottom.png' height='26' width='31'></img></td><td><img src='images/layout/bottom.png' height='26' width='100%'></img></td><td><img src='images/layout/cornerrightbottom.png' height='26' width='31'></img></td>
</tr>
</table></td></tr></table>
<center><font color='#ffffff'><b>Best Viewed In:: Mozilla Firefox - Resolution:: 1024x768</b></font></center>

</body>
</html>


#2 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 19 March 2006 - 06:00 AM

Fixed! This code works:

<?php

$user = $_POST["UserName"];
$pass = $_POST["PassWord"];
$UID = 1;

if ($_POST["UserName"] == "Thomas" && $_POST["PassWord"] == "**killedbyuse**") {

    setcookie("UserName", $user, time()+3600);
    setcookie("Password", $pass, time()+3600);
    setcookie("UID", $UID, time()+3600);

echo "<html>
<head>

<link rel='stylesheet' type='text/css' href='mreds.css' />
<link rel='alternate stylesheet' type='text/css' media='screen' title='mmilds' href='mmilds.css' />
<link rel='alternate stylesheet' type='text/css' media='screen' title='mmenthollights' href='mmenthollights.css' />
<link rel='alternate stylesheet' type='text/css' media='screen' title='mno27s' href='mno27s.css' />

</head>
<body onLoad='goforit()' align=center>

<table border=0 height=100% width=100%><tr><td vAlign=middle align=center>

<table border=0 cellspacing=0 cellpadding=0 bgcolor='#ffffff'>
<tr>
<td><img src='images/layout/cornerleft.png' height='26' width='31'></img></td><td><img src='images/layout/top.png' height='26' width='100%'></img></td><td><img src='images/layout/cornerright.png' height='26' width='31'></img></td></tr>
<tr>
<td class='loginoroutleft'></td><td align=center>

<!-- start shit -->
        <table border=0 width=300 cellspacing=0 cellpadding=0>
        <tr>
        <td align=left vAlign=top width=100% cellspacing=0 cellpadding=0>
                    <table border=1 width=100% cellspacing=0 cellpadding=0><tr><td align=left vAlign=top class='menuheadertop' width=100%>
            <b>Status</b>";
if ($UID == 1) {

echo "[admin]";

} else {

echo "[guest]";

}

echo "              </td></tr></table>
        </td>
        </tr>
        <tr>
        <td align=left width=100%>
                    <table border=1 width=100% height=100 cellspacing=0 cellpadding=0><tr><td vAlign=top class='menuheaderbottom' width=100% align=center>";

    echo "Logged in as $user.";
    echo "<br><br><a href='index.php' align=left>Continue</a>";

   } else {

echo "<html>
<head>

<link rel='stylesheet' type='text/css' href='mreds.css' />
<link rel='alternate stylesheet' type='text/css' media='screen' title='mmilds' href='mmilds.css' />
<link rel='alternate stylesheet' type='text/css' media='screen' title='mmenthollights' href='mmenthollights.css' />
<link rel='alternate stylesheet' type='text/css' media='screen' title='mno27s' href='mno27s.css' />

</head>
<body onLoad='goforit()' align=center>

<table border=0 height=100% width=100%><tr><td vAlign=middle align=center>

<table border=0 cellspacing=0 cellpadding=0 bgcolor='#ffffff'>
<tr>
<td><img src='images/layout/cornerleft.png' height='26' width='31'></img></td><td><img src='images/layout/top.png' height='26' width='100%'></img></td><td><img src='images/layout/cornerright.png' height='26' width='31'></img></td></tr>
<tr>
<td class='loginoroutleft'></td><td align=center>

<!-- start shit -->
        <table border=0 width=300 cellspacing=0 cellpadding=0>
        <tr>
        <td align=left vAlign=top width=100% cellspacing=0 cellpadding=0>
                    <table border=1 width=100% cellspacing=0 cellpadding=0><tr><td align=left vAlign=top class='menuheadertop' width=100%>
            <b>Status</b>";
if ($UID == 1) {

echo "[admin]";

} else {

echo "[guest]";

}

echo "              </td></tr></table>
        </td>
        </tr>
        <tr>
        <td align=left width=100%>
                    <table border=1 width=100% height=100 cellspacing=0 cellpadding=0><tr><td vAlign=top class='menuheaderbottom' width=100% align=center>";

    echo "Invalid username or password.";
    echo "<br><br><a href='index.php' align=left>Continue</a>";

   }

?>

                </td></tr></table>
        </td>
        </tr>
        </table>
<!-- end shit -->

</td><td class='loginoroutright'></td></tr>
<tr><td><img src='images/layout/cornerleftbottom.png' height='26' width='31'></img></td><td><img src='images/layout/bottom.png' height='26' width='100%'></img></td><td><img src='images/layout/cornerrightbottom.png' height='26' width='31'></img></td>
</tr>
</table></td></tr></table>
<center><font color='#ffffff'><b>Best Viewed In:: Mozilla Firefox - Resolution:: 1024x768</b></font></center>

</body>
</html>

But only if this is in there, for some odd reason:

if ($UID == 1) {

echo "[admin]";

} else {

echo "[guest]";

}

Could anyone explain to me why?

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 March 2006 - 10:26 AM

Because you cant send headers/set cookies when something has been outputted before the uses of header/session_start or setcookie, ie HTML or spaces.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users