PDA

View Full Version : [PHP] Whats wrong with this?



Blinger1
14-11-2008, 04:27 AM
G'day y'all.. Why doesn't this code work? Well, it works but I can't have this part..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Testing</title>
</head>

<body>


<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Testing</title>
</head>

<body>
<?php


// Includes the mysql connection page
include("includes/connect.php");

// Check if the submit button was pressed
if (isset($_GET['submit'])) {
..
}else{
$_SESSION['user_id'] = $user_id;

// Redirect to userpanel.php
header('location: userpanel.php');
}
}

}else{
...

?><br />
</body>
</html>

Why is it that that doesn't work? (obviously there is more coding than just that. The error I get is:
Warning: Cannot modify header information - headers already sent by (output started at /home/username/public_html/members/login.php:10) in /home/username/public_html/members/login.php on line 37


line 10: <?php
line 37: header('location: userpanel.php');

+rep when i can :)

Iszak
14-11-2008, 04:37 AM
Well besides your opening and closing tags seem to be incorrect in the second block of PHP, the problem is you're redirecting after the headers are sent as the error states, to fix this simply add at the top prior to session_start(); "ob_start();" this will turn output buffer on and will stop your error.

e.g.


<?php

ob_start();
session_start();

?>

Blinger1
14-11-2008, 04:40 AM
okay thanks!! And what do you mean by "your opening and closing tags seem to be incorrec"?

Iszak
14-11-2008, 04:58 AM
Sorry - yeah I worded that badly.


<?php


// Includes the mysql connection page
include("includes/connect.php");

// Check if the submit button was pressed
if (isset($_GET['submit'])) {

}else{
$_SESSION['user_id'] = $user_id;

// Redirect to userpanel.php
header('location: userpanel.php');
}
}

}else{


?>
That code has closing brackets "}" that you don't need and also is missing one for the last else.

Blinger1
14-11-2008, 05:06 AM
oh yeah, sorry! I just removed half of the code :P! It all works now, i'll +rep you when this stupid caution is removed -.-'

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