Jump to content

Header error


nander

Recommended Posts

Hello I am getting this error in my script. Can anyone help?

 

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb25b/b904/ipg.votpservicescom/listing15.8.php:12) in /hermes/bosweb25b/b904/ipg.votpservicescom/listing15.8.php on line 39

 

 

if ((!$_POST[username]) || (!$_POST[password])) {

    header("Location: listing15.7.php");

exit;

}

//connect to server and select database

$link = mysql_connect('servicescom.ipagemysql.com', 'ssap', 'pass');

if (!$link) {

die('Could not connect: ' . mysql_error());

}

echo 'Connected successfully';

mysql_select_db(formlogin);

 

//create and issue the query

$sql = "select f_name, l_name from auth_users where username =

    '$_POST[username]' AND password = password('$_POST[password]')";

$result = mysql_query($sql, $link) or die(mysql_error());

 

//get the number of rows in the result set; should be 1 if a match

if (mysql_num_rows($result) == 1) {

 

//if authorized, get the values of f_name l_name

$f_name = mysql_result($result, 0, 'f_name');

    $l_name = mysql_result($result, 0, 'l_name');

 

//set authorization cookie

setcookie("auth", "1", 0, "/", "votpservices.com", 0);

 

//prepare message for printing, and user menu

    $msg = "<P>$f_name $l_name is authorized!</p>";

    $msg .= "<P>Authorized Users' Menu:";

    $msg .= "<ul><li><a href=\"listing15.8.php\">secret page</a></ul>";

 

}

else {

 

//redirect back to login form if not authorized

    header("Location: listing15.7.php");

exit;

}

?>

<html>

<head>

<title>Listing 15.8 User Login</title>

</head>

<body>

<?php print "$msg"; ?>

</body>

</html>

Link to comment
Share on other sites

<?php

//check for required fields from the form
   if ((!$_POST[username]) || (!$_POST[password])) {
header("Location: listing15.7.php");
      exit;
}
//connect to server and select database
$link = mysql_connect('votpservicescom.ipagemysql.com', 'logindb', 'password'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
} 
echo 'Connected successfully';
mysql_select_db(formslogin); 


//create and issue the query
   $sql = "select f_name, l_name from auth_users where username =
    '$_POST[username]' AND password = password('$_POST[password]')";
   $result = mysql_query($sql, $link) or die(mysql_error());

//get the number of rows in the result set; should be 1 if a match
   if (mysql_num_rows($result) == 1) {

//if authorized, get the values of f_name l_name
   $f_name = mysql_result($result, 0, 'f_name');
    $l_name = mysql_result($result, 0, 'l_name');

//set authorization cookie
   setcookie("auth", "1", "0", "/", "votpservices.com", 0);

//prepare message for printing, and user menu
    $msg = "<P>$f_name $l_name is authorized!</p>";
    $msg .= "<P>Authorized Users' Menu:";
    $msg .= "<ul><li><a href=\"listing15.8.php\">secret page</a></ul>";

}
else {
//redirect back to login form if not authorized
    header("Location: listing15.7.php");
      exit;
}
?>
<html>
<head>
   <title>Listing 15.8 User Login</title>
</head>
<body>
<?php print "$msg"; ?>
</body>
</html>

 

MOD EDIT:

 . . . 

tags added.

Link to comment
Share on other sites

Pikachu2000

 

 

Ok here is my code now its ridirecting me to the 2nd header page instead of showing me the successfull login page?

 

<?php

ob_start() ;

//check for required fields from the form

if ((!$_POST[username]) || (!$_POST[password])) {

header("Location: listing15.7.php");

exit;

}

//connect to server and select database

$link = mysql_connect('servicescom.ipagemysql.com', 'enter', 'password');

if (!$link) {

    die('Could not connect: ' . mysql_error());

 

}

mysql_select_db(formlogin);

 

 

//create and issue the query

$sql = 'SELECT `auth_users` . `f_name` , `auth_users` . `l_name` '

        . ' FROM auth_users '

        . ' LIMIT 0, 30 ';

$result = mysql_query($sql, $link) or die(mysql_error());

 

//get the number of rows in the result set; should be 1 if a match

if (mysql_num_rows($result) == 1) {

 

//if authorized, get the values of f_name l_name

$f_name = mysql_result($result, 0, 'f_name');

    $l_name = mysql_result($result, 0, 'l_name');

 

//set authorization cookie

setcookie("auth", "1", 0, "/", "services.com", 0);

 

//prepare message for printing, and user menu

    $msg = "<P>$f_name $l_name is authorized!</p>";

    $msg .= "<P>Authorized Users' Menu:";

    $msg .= "<ul><li><a href=\"listing15.8.php\">secret page</a></ul>";

 

}

else {

//redirect back to login form if not authorized

    header("Location: topiclist.php");

exit;

}

ob_end_flush();

?>

<html>

<head>

<title>Listing 15.8 User Login</title>

</head>

<body>

<?php print "$msg";?>

</body>

</html>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.