Creating a Membership ERROR

Hi everyone,
I have worked with php for about 2 months now and have stepped into created membership websites. I have learned allot from developphp.com and the thenewboston.com including many books. Anyways so I have been building this basic membership profile login when I go back to the home page it shows the user is logged in and I can view all the profile information but when i come to the login page and enter the user info and password for some reason every time I log in I get the error :

Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/younga8/public_html/membersystem/connect_to_mysql.php:20) in /home/younga8/public_html/membersystem/login.php on line 24

Warning: Cannot modify header information - headers already sent by (output started at /home/younga8/public_html/membersystem/connect_to_mysql.php:20) in /home/younga8/public_html/membersystem/login.php on line 33

I tried relinking variables, checking for any spaces, and extra lines. Again I am a little new so maybe this may just be something simple. Here is my php code :

<?php if ($_POST['email']) { //Connect to the database through our include include_once "connect_to_mysql.php"; $email = stripslashes($_POST['email']); $email = strip_tags($email); $email = mysql_real_escape_string($email); $password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters $password = md5($password); // Make query and then register all database data that - // cannot be changed by member into SESSION variables. // Data that you want member to be able to change - // should never be set into a SESSION variable. $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$password' AND emailactivated='1'"); $login_check = mysql_num_rows($sql); if($login_check > 0){ while($row = mysql_fetch_array($sql)){ // Get member ID into a session variable $id = $row["id"]; session_register('id'); $_SESSION['id'] = $id; // Get member username into a session variable $username = $row["username"]; session_register('username'); $_SESSION['username'] = $username; // Update last_log_date field for this member now mysql_query("UPDATE members SET lastlogin=now() WHERE id='$id'"); // Print success message here if all went well then exit the script header("www.youngamme.com/membersystem/member_profile.php?id=$id"); exit(); } // close while } else { // Print login failure message to the user and link them back to your login page print '

No match in our records, try again

Click here to go back to the login page.'; exit(); } }// close if post ?> Login to your profile



Log in to your account here

Email Address:
Password:
 

Thanks everyone any help is greatly appreciated

2 things offhand.
1 -
$password = ereg_replace("[^A-Za-z0-9]", “”, $_POST[‘password’]);

isn’t filtering, its replacing, and ereg is deminished. use preg_match instead. You also don’t have any trap code to determine if it matches or not. Needs to be something more like
[php]if(preg_match("[^A-Za-z0-9]", $_POST[‘password’])) {
$password = md5($_POST[‘password’]);
} else {
$error[] = “Invalid Password”;
}[/php]

You’ll need to check the pattern to make sure that’s right for preg_match.

Don’t need to use session_register. Just put session_start(); at the very top of the page. You can’t have any text output to the screen before using either one. No prints, echoe’s, etc.

Also, I think your redirection line is incorrect…

This:
[php]
header(“www.youngamme.com/membersystem/member_profile.php?id=$id”);
[/php]

Should be:
[php]
header(“Location: www.youngamme.com/membersystem/member_profile.php?id=$id”);
[/php]

In some cases the "Location: " is not needed, but, for compatibility, you need it…

Lastly, please post your code INSIDE of the PHP or # brackets. (PHP for php code, # for html+PHP code)
This helps us copy it and use it in our own systems for debugging… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service