For an unknown reason, my PHP won't work when I "attach" it with any session-things. (It works perfectly when I take out all the session-related codes.)
I did put the session_start() at the first line of the document. But it still gives me the same error.
Is there anything I need to enable on the server before using those session-related functions?
Thanks for your help in advance!
p.s. I did NOT use any cookies with the session.
[SOLVED] Another question on session start
Moderator: General Moderators
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
Ooops!!!
Forgot that one.
It just gives me a blank page when I click "Submit" in the first page.
First page (login.php):
The processing page:
It just gives me a blank page when I click "Submit" in the first page.
First page (login.php):
Code: Select all
<?php echo "<?xml version="1.0" encoding="iso-8859-1"?".">"; ?>
<!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>
<title>Login Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form name="loginForm" id="loginForm" method="post" action="sfLoginProcess.php">
<p align="center">Sutton Farms Login Page</p>
<p align="center">Username:
<input name="username" type="text" id="username" />
<br />
Password:
<input name="password" type="password" id="password" />
</p>
<p align="center">
<input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Clear" value="Reset" />
</p>
</form>
<p> </p>
</body>
</html>The processing page:
Code: Select all
<?php
// Session begins
// Avoid weird error occurs
session_start();
// Get variables from previous page
import_request_variables("p", "login_");
// Connection to database
// Database variables
$serverAddress = "localhost";
$user = "username";
$pwd = "password";
$database = "db";
$table = "table";
// Establish connection
mysql_connect($serverAddress, $user, $pwd) or die("Cannot connect to MySQL database.");
// Select target database
mysql_select_db($database) or die("Cannot select target database.");
// Verifying username and password
// Get username & password from previous form
$username = $login_username;
$password = $login_password;
// Setup query
$query = "SELECT password, type FROM " . $table . " WHERE USERNAME = '". $username . "'";
// Query the database
$result = mysql_query($query) or die("Cannot submit query.");
// Check if the passwords match
if ($password != mysql_result($result, 0, 'password')) {
// Does not match.
// Close the database connection.
mysql_close();
// Redirect to fail page.
header("Location: fail.html");
} else {
// Passwords match.
// Close the database connection.
mysql_close();
/*
// Storing variables in sessions
// Register variables with the session
session_register('username') = $login_username;
session_register('password') = $login_password;
session_register('type') = $mysql_result($result, 0, 'type');
*/
/*
// Make sure the session variables have been written
session_write_close();
*/
// If the user is an admin
if (mysql_result($result, 0, 'type') == "admin") {
// Direct to the admin page
header("Location: admin.php");
} else {
// Direct to the user page
header("Location: user.php");
}
}
?>-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC