/    Sign up×
Community /Pin to ProfileBookmark

sessions throwing out the page

hey guys,

i understand you must always start a session (for cookies) before the HTML tags – BUT its throwing out my whole page. ie – my form was nicely centered now its skewed to the left ?

please advise how to rectify this

here is the opening code

[code=php]
<?php
//check for required fields from the form
if (!isset($_POST[username]) || !isset($_POST[password])) {
header(“Location: login.html”);
exit;
}

//connect to server and select database

DEFINE (DB_USER, “”);
DEFINE (DB_PASSWORD, “”);
DEFINE (DB_HOST, “localhost”);
DEFINE (DB_TEST, “test”);

$conn = mysql_connect (‘localhost’, ”,”) or die (‘could not connect to MYSQL because: ‘ . mysql_error());

mysql_select_db (blueprintdb) or die (‘could not select the DB because: ‘ . mysql_error());

//create and issue the query
$sql = “select first_name, last_name from users where username = ‘$_POST[username]’ AND password = ‘$_POST[password]'”;
$result = mysql_query($sql,$conn) or die(“User Query Error “.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
$first_name = mysql_result($result, 0, ‘first_name’);
$last_name = mysql_result($result, 0, ‘last_name’);

//set authorization cookie
setcookie(“auth”, “1”, 0, “/”, “questionnaireproject.com”, 0);
print “Cookie status: authorised-“.$_COOKIE[auth];

//prepare message for printing, and user menu
$msg = “Welcome to Dynamic Homes $first_name!”;
$msg .= “Authorised Users Menu:”;
$msg .= “<ul><li><a href=”index.html”>Return to Home Page</a></ul>”;
} else
{
//redirect back to login form if not authorised
header(“Location: wrong.html”);
//print “Wrong user name or password. Please try login again</a>”;
exit;
}
?>

<!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>[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@bokehApr 15.2006 — Post the URI.
Copy linkTweet thisAlerts:
@NogDogApr 15.2006 — This line...
[code=php]
print "Cookie status: authorised-".$_COOKIE[auth];
[/code]

...is outputting text to the browser before your HTML doctype, head, and body tags are being output, rendering your HTML markup invalid. You'll need to move it down into the body of your HTML.

PS: You should probably get rid of the space between the end of the of the PHP and the start of the doctype line, or IE may go into "quirks mode":
[code=php]
<?php
// code here
?><!doctype.......>
[/code]
×

Success!

Help @DMP23 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...