Jump to content
Larry Ullman's Book Forums

Chpt 4 Register.Php (Error When Trying To Connect To Mailserver)


Recommended Posts

I get the following error when trying to register on the website. Mercury in running in my xampp. In my register.php file on line 59, I have:

mail ($_POST['email'], 'Registration Confirmation', $body, 'From: me@example.com');

 

In my php.ini file, I have the mailserver set to me@example.com

 

The following is the message I get when registering:

Thanks!

 

Thank you for registering! You may now log in and access the site's content.

An error occurred in script 'C:\xampp\htdocs\register.php' on line 59:

mail() [function.mail]: Failed to connect to mailserver at "me@example.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

Array

 

(

 

[0] => Array

 

(

 

[function] => my_error_handler

 

[args] => Array

 

(

 

[0] => 2

 

[1] => mail() [function.mail]: Failed to connect to mailserver at "me@example.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

 

[2] => C:\xampp\htdocs\register.php

 

[3] => 59

 

[4] => Array

 

(

 

[GLOBALS] => Array

 

*RECURSION*

 

[_POST] => Array

 

(

 

[first_name] => Lesley

 

[last_name] => Pallies

 

[username] => Lesley

 

=> Lesley@example.com

 

[pass1] => Lesley45

 

[pass2] => Lesley45

 

[submit_button] => Next →

 

)

 

 

 

[_GET] => Array

 

(

 

)

 

 

 

[_COOKIE] => Array

 

(

 

[phpSESSID] => i08v7ule9inqpddlocj3i5kha5

 

)

 

 

 

[_FILES] => Array

 

(

 

)

 

 

 

[_SERVER] => Array

 

(

 

[MIBDIRS] => C:/xampp/php/extras/mibs

 

[MYSQL_HOME] => \xampp\mysql\bin

 

[OPENSSL_CONF] => C:/xampp/apache/bin/openssl.cnf

 

[php_PEAR_SYSCONF_DIR] => \xampp\php

 

[phpRC] => \xampp\php

 

[TMP] => \xampp\tmp

 

[HTTP_HOST] => localhost

 

[HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.25) Gecko/20111212 Firefox/3.6.25

 

[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

 

[HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5

 

[HTTP_ACCEPT_ENCODING] => gzip,deflate

 

[HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7

 

[HTTP_KEEP_ALIVE] => 115

 

[HTTP_CONNECTION] => keep-alive

 

[HTTP_REFERER] => http://localhost/register.php

 

[HTTP_COOKIE] => PHPSESSID=i08v7ule9inqpddlocj3i5kha5

 

[CONTENT_TYPE] => application/x-www-form-urlencoded

 

[CONTENT_LENGTH] => 137

 

[PATH] => C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files (x86)\QuickTime\QTSystem\;

 

[systemRoot] => C:\Windows

 

[COMSPEC] => C:\Windows\system32\cmd.exe

 

[PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

 

[WINDIR] => C:\Windows

 

[sERVER_SIGNATURE] => Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 Server at localhost Port 80

 

 

 

[sERVER_SOFTWARE] => Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1

 

[sERVER_NAME] => localhost

 

[sERVER_ADDR] => 127.0.0.1

 

[sERVER_PORT] => 80

 

[REMOTE_ADDR] => 127.0.0.1

 

[DOCUMENT_ROOT] => C:/xampp/htdocs

 

[sERVER_ADMIN] => postmaster@localhost

 

[sCRIPT_FILENAME] => C:/xampp/htdocs/register.php

 

[REMOTE_PORT] => 50534

 

[GATEWAY_INTERFACE] => CGI/1.1

 

[sERVER_PROTOCOL] => HTTP/1.1

 

[REQUEST_METHOD] => POST

 

[QUERY_STRING] =>

 

[REQUEST_URI] => /register.php

 

[sCRIPT_NAME] => /register.php

 

[php_SELF] => /register.php

 

[REQUEST_TIME] => 1327891244

 

)

 

 

 

[live] =>

 

[contact_email] => you@example.com

 

[_SESSION] => Array

 

(

 

[user_admin] => 1

 

)

 

 

 

[page_title] => Register

 

[pages] => Array

 

(

 

[Home] => index.php

 

[About] => about.php

 

[Contact] => contact.php

 

[Register] => register.php

 

)

 

 

 

[this_page] => register.php

 

[v] => register.php

 

[k] => Register

 

[dbc] => mysqli Object

 

(

 

[affected_rows] => 1

 

[client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $

 

[client_version] => 50008

 

[connect_errno] => 0

 

[connect_error] =>

 

[errno] => 0

 

[error] =>

 

[field_count] => 0

 

[host_info] => localhost via TCP/IP

 

[info] =>

 

[insert_id] => 8

 

[server_info] => 5.5.16

 

[server_version] => 50516

 

[sqlstate] => 00000

 

[protocol_version] => 10

 

[thread_id] => 10

 

[warning_count] => 1

 

)

 

 

 

[reg_errors] => Array

 

(

 

)

 

 

 

[fn] => Lesley

 

[ln] => Pallies

 

=> Lesley

 

[e] => Lesley@example.com

 

[p] => Lesley45

 

[q] => INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('Lesley', 'Lesley@example.com', '��3K@�3���ea��{z�\"Tv|�R5��', 'Lesley', 'Pallies', ADDDATE(NOW(), INTERVAL 1 MONTH))

 

[r] => 1

 

[rows] => 0

 

[body] => Thank you for registering at . Blah. Blah.

 

 

 

 

 

)

 

 

 

)

 

 

 

)

 

 

 

[1] => Array

 

(

 

[file] => C:\xampp\htdocs\register.php

 

[line] => 59

 

[function] => mail

 

[args] => Array

 

(

 

[0] => Lesley@example.com

 

[1] => Registration Confirmation

 

[2] => Thank you for registering at . Blah. Blah.

 

 

 

 

 

[3] => From: me@example.com

 

)

 

 

 

)

 

 

 

)

Link to comment
Share on other sites

I still get an error & am confused. Please clarify:

 

Error:

An error occurred in script 'C:\xampp\htdocs\register.php' on line 59:

mail() [function.mail]: Failed to connect to mailserver at "lkkerns@mchsi.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

 

I set my php.ini file to my email address:

 

[mail function]

; For Win32 only.

; http://php.net/smtp

SMTP = lkkerns@mchsi.com

; http://php.net/smtp-port

smtp_port = 25

 

; For Win32 only.

; http://php.net/sendmail-from

;sendmail_from = postmaster@localhost

 

 

My email variable in my config.inc.php file is:

$contact_email='lkkerns@mchsi.com';

 

In my register.php file (line 59) is:

mail ($_POST['email'], 'Registration Confirmation', $body, 'From: lkkerns@mchsi.com');

Link to comment
Share on other sites

I have windows 7. I am confused because last semester in my PHP class, I didn't have a problem. I had my php.ini file set to me@example.com. So if I only need it for class and testing on localhost, what do I need to change? So if I only test on my localhost, what do I put for SMTP server and why didn't I have a problem last semester when testing my files?

 

Sorry I am not understanding. So if I have a gmail account, this doesn't work either.

 

[mail function]

; For Win32 only.

; http://php.net/smtp

SMTP = lynaekern@gmail.com

; http://php.net/smtp-port

smtp_port = 25

 

; For Win32 only.

; http://php.net/sendmail-from

;sendmail_from = postmaster@localhost

Link to comment
Share on other sites

Okay, I called my isp and got the address below. This took care of the previous error. Is this the only thing I need to change with the setting below? So the e-mail address in my config.inc.php and register.php files don't really matter? I have two more issues described below.

 

[mail function]

; For Win32 only.

; http://php.net/smtp

SMTP = mail.mediacombb.net

; http://php.net/smtp-port

smtp_port = 25

 

; For Win32 only.

; http://php.net/sendmail-from

;sendmail_from = postmaster@localhost

 

 

Chpt 4 logging in:

When I type a previously registered email address (I verified that these email addresses are in my user table) and click forgot password, I get the following error. Example of e-mail address: Brooke@mchsi.com. (this is what I am entering as it is in the user table).

Object not found!

 

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404

localhost

01/30/12 20:51:22

Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1

 

Error when logging in with password (This file is according to the book and my dbc is defined in my config.inc.php file and my user table is updating when the users register the first time.):

An error occurred in script 'C:\xampp\htdocs\includes\login.inc.php' on line 6:

Undefined variable: dbc

 

This is the first part of my login.inc.php file:

 

<?php

//empty errors for storing errors:

$login_errors = array();

//Validate email address:

if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){

$e = mysqli_real_escape_string($dbc,$_POST['email']);

}else{

$login_errors['email'] = 'Please enter a valid email address!';

}

Link to comment
Share on other sites

Your first error is a file not found error. The error appears to be in index.php, and indicates that the link to your forgot password script is incorrect.

 

Your second error, "Undefined variable: dbc" <-- this is your database connection variable, but your login.inc.php does not have your login code. You need to include your config.inc.php file before you use mysqli_real_escape_string() because it needs the database connection resource ($dbc).

Link to comment
Share on other sites

Okay, I called my isp and got the address below. This took care of the previous error. Is this the only thing I need to change with the setting below? So the e-mail address in my config.inc.php and register.php files don't really matter? I have two more issues described below.

 

[mail function]

; For Win32 only.

; http://php.net/smtp

SMTP = mail.mediacombb.net

; http://php.net/smtp-port

smtp_port = 25

 

; For Win32 only.

; http://php.net/sendmail-from

;sendmail_from = postmaster@localhost

 

 

Chpt 4 logging in:

When I type a previously registered email address (I verified that these email addresses are in my user table) and click forgot password, I get the following error. Example of e-mail address: Brooke@mchsi.com. (this is what I am entering as it is in the user table).

Object not found!

 

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404

localhost

01/30/12 20:51:22

Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1

 

Error when logging in with password (This file is according to the book and my dbc is defined in my config.inc.php file and my user table is updating when the users register the first time.):

An error occurred in script 'C:\xampp\htdocs\includes\login.inc.php' on line 6:

Undefined variable: dbc

 

This is the first part of my login.inc.php file:

 

<?php

//empty errors for storing errors:

$login_errors = array();

//Validate email address:

if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){

$e = mysqli_real_escape_string($dbc,$_POST['email']);

}else{

$login_errors['email'] = 'Please enter a valid email address!';

}

 

My old thread may help on the dbc undefined error http://www.larryullman.com/forums/index.php?/topic/940-undefined-variable-dbc/

Link to comment
Share on other sites

Hi Edward,

 

I appreciate your patients! Okay. This class is going to send me over the edge!

 

I get this error when logging in with my password:

 

Problem #1. Fatal error: Cannot redeclare my_error_handler() (previously declared in C:\xampp\htdocs\includes\config.inc.php:18) in C:\xampp\htdocs\includes\config.inc.php on line 38

 

This is my config.inc.php file:

 

//Define variables:

$live=false;

$contact_email='postmaster@localhost.com';

 

//Define constants:

 

define ('BASE_URI', 'http://localhost/');

define ('BASE_URL','/www/');

define ('MYSQL','/includes/mysql.inc.php');

 

//start session:

session_start();

 

 

//Define error handling (max of 5 arguments):

function my_error_handler($e_number,$e_message,$e_file,$e_line,$e_vars){

global $live,$contact_email;

//Detailed error message:

$message="An error occurred in script '$e_file' on line $e_line:\n$e_message\n";

//add backtrace (information that happended up until this point) info:

$message .= "

" .print_r(debug_backtrace(),1) . "

\n";

 

//If site isn't live, show error message in browser:

if(!$live){

echo'

'.nl2br($message).'

';

 

//If site is live, send error to an email (1 means email),(0 means operating system's log):

}else{

error_log($message,1,$contact_email, 'From:postmaster@localhost.com');

//If site is live, show generic message if error not a notice:

if($e_number!=E_NOTICE){

echo '

A system error occurred. We apologize for the inconvenience.

';

}

}//End $live IF-ELSE

return true;

}//End my_error_handler()definition

 

//Apply error handler (tells PHP to use the custom function for handling errors instead of its default):

set_error_handler('my_error_handler'); (Should this be in here since the error says the set_error_handler shouldn't be redeclared?)

//Redirect invalid users (checks for user_id, redirect to index.php page):

function redirect_invalid_user($check = 'user_id', $destination = 'index.php', $protocol = 'http://'){

if (!isset($_SESSION[$check])){

$url = $protocol . BASE_URL . $destination;

//header () function redirects:

header ("Location: $url");

// exit () terminates the script. If you don't terminate the script, the header() function will continue to execute the script.

exit();

}

}

 

 

 

Problem #2. When logging in and clicking forgot password, I still get object not found error.

 

This is index.php file:

 

require('./includes/config.inc.php');

 

//include the login file:

if($_SERVER['REQUEST_METHOD'] == 'POST'){

include ('./includes/login.inc.php'); (this is the correct path)

}

 

include ('./includes/header.html');

 

//database connection:

require (MYSQL);

?>

 

Welcome

 

 

Welcome to Knowledge is Power, a site dedicated to keeping you up to date on the Web security and programming information you need to know.

 

 

include ('./includes/footer.html');

?>

 

This is my login.inc.php file:

 

require('./includes/config.inc.php');

 

//database connection:

require (MYSQL);

 

 

//empty errors for storing errors:

$login_errors = array();

 

//Validate email address:

if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){

$e = mysqli_real_escape_string($dbc,$_POST['email']);

}else{

$login_errors['email'] = 'Please enter a valid email address!';

}

//Validate password:

if (!empty($_POST['pass'])){

$p = mysqli_real_escape_string($dbc, $_POST['pass']);

}else{

$login_errors['pass'] = 'Please enter your password!';

}

//If no errors, query database (date_expired if greater than or equal to this moment, the value is true if not it is false):

if (empty($login_errors)){

$q = "SELECT id, username, type, IF(date_expires >= NOW(), true, false) FROM users WHERE (email ='$e' AND pass ='" . get_password_hash($p) . "')";

$r = mysqli_query ($dbc, $q);

//If one row is returned by database query, get data and store in session:

if (mysqli_num_rows($r) == 1){

$row = mysqli_fetch_array($r, MYSQLI_NUM);

 

//If administrator, create a new session ID for safety:

if($row[2] == 'admin'){

session_regenerate_id(true);

$_SESSION['user_admin'] = true;

}

$_SESSION['user_id'] = $row[0];

$_SESSION['username'] = $row[1];

if($row[3] == 1)$_SESSION['user_not_expired'] = true;

//If no row was returned, create error message:

}else{

$login_errors['login'] = 'The email address and password do not match those on file.';

}

}//End of $login_errors IF.

Link to comment
Share on other sites

Are you using this book in a class? This book does assume complete comfort with PHP and MySQL, by the way. It's not really for learning either.

 

As for your first problem, you've declared the same function twice, although I don't see it in the code you've posted.

 

As for the second problem, what is the actual and complete error?

 

Also, your BASE_URI and BASE_URL values are wrong.

Link to comment
Share on other sites

Okay one more thing, what about the BASE_URL for a localhost, just put it like:

 

define ('BASE_URL','http://localhost/knowledge_is_power/');

 

so Lynae

 

should be

 

define ('BASE_URL','http://localhost/');

 

"lol i have more problems with paths and directories than i do with programming, funny stuff this, yes it looks worrying but i do get it now. I just finished the knowledge is power site, so onto the MVC coffeeshop now with a bit more experience."

  • Upvote 1
Link to comment
Share on other sites

Yes, this book is for a class. I don't think this is for me but I need to get through the class.

 

How is this incorrect if my database is updating? URL is website and URI is path, correct?

//Define constants:

 

define ('BASE_URI', 'http://localhost/');

define ('BASE_URL','/www/');

define ('MYSQL','/includes/mysql.inc.php');

 

Another error (God help me!):

When registering a user, I get the following error:

 

An error occurred in script 'C:\xampp\htdocs\register.php' on line 59:

mail() [function.mail]: SMTP server response: 550 5.1.1 <gen@mchsi.com> Suspect mail not accepted for Mediacom domains or invalid recipient - POL112

 

Array

 

(

 

[0] => Array

 

(

 

[function] => my_error_handler

 

[args] => Array

 

(

 

[0] => 2

 

[1] => mail() [function.mail]: SMTP server response: 550 5.1.1 <gen@mchsi.com> Suspect mail not accepted for Mediacom domains or invalid recipient - POL112

 

[2] => C:\xampp\htdocs\register.php

 

[3] => 59

 

[4] => Array

 

(

 

[GLOBALS] => Array

 

*RECURSION*

 

[_POST] => Array

 

(

 

[first_name] => Gen

 

[last_name] => Koenig

 

[username] => Gen

 

=> Gen@mchsi.com

 

[pass1] => Gen1900

 

[pass2] => Gen1900

 

[submit_button] => Next →

 

)

 

 

 

[_GET] => Array

 

(

 

)

 

 

 

[_COOKIE] => Array

 

(

 

[phpSESSID] => 76k03qejg1kk8uk1ub14nflcg7

 

)

 

 

 

[_FILES] => Array

 

(

 

)

 

 

 

[_SERVER] => Array

 

(

 

[MIBDIRS] => C:/xampp/php/extras/mibs

 

[MYSQL_HOME] => \xampp\mysql\bin

 

[OPENSSL_CONF] => C:/xampp/apache/bin/openssl.cnf

 

[php_PEAR_SYSCONF_DIR] => \xampp\php

 

[phpRC] => \xampp\php

 

[TMP] => \xampp\tmp

 

[HTTP_HOST] => localhost

 

[HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.25) Gecko/20111212 Firefox/3.6.25

 

[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

 

[HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5

 

[HTTP_ACCEPT_ENCODING] => gzip,deflate

 

[HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7

 

[HTTP_KEEP_ALIVE] => 115

 

[HTTP_CONNECTION] => keep-alive

 

[HTTP_REFERER] => http://localhost/register.php

 

[HTTP_COOKIE] => PHPSESSID=76k03qejg1kk8uk1ub14nflcg7

 

[CONTENT_TYPE] => application/x-www-form-urlencoded

 

[CONTENT_LENGTH] => 123

 

[PATH] => C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files (x86)\QuickTime\QTSystem\;

 

[systemRoot] => C:\Windows

 

[COMSPEC] => C:\Windows\system32\cmd.exe

 

[PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

 

[WINDIR] => C:\Windows

 

[sERVER_SIGNATURE] => Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 Server at localhost Port 80

 

 

 

[sERVER_SOFTWARE] => Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1

 

[sERVER_NAME] => localhost

 

[sERVER_ADDR] => 127.0.0.1

 

[sERVER_PORT] => 80

 

[REMOTE_ADDR] => 127.0.0.1

 

[DOCUMENT_ROOT] => C:/xampp/htdocs

 

[sERVER_ADMIN] => postmaster@localhost

 

[sCRIPT_FILENAME] => C:/xampp/htdocs/register.php

 

[REMOTE_PORT] => 58936

 

[GATEWAY_INTERFACE] => CGI/1.1

 

[sERVER_PROTOCOL] => HTTP/1.1

 

[REQUEST_METHOD] => POST

 

[QUERY_STRING] =>

 

[REQUEST_URI] => /register.php

 

[sCRIPT_NAME] => /register.php

 

[php_SELF] => /register.php

 

[REQUEST_TIME] => 1328140273

 

)

 

 

 

[live] =>

 

[contact_email] => postmaster@localhost.com

 

[_SESSION] => Array

 

(

 

)

 

 

 

[page_title] => Register

 

[pages] => Array

 

(

 

[Home] => index.php

 

[About] => about.php

 

[Contact] => contact.php

 

[Register] => register.php

 

)

 

 

 

[this_page] => register.php

 

[v] => register.php

 

[k] => Register

 

[dbc] => mysqli Object

 

(

 

[affected_rows] => 1

 

[client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $

 

[client_version] => 50008

 

[connect_errno] => 0

 

[connect_error] =>

 

[errno] => 0

 

[error] =>

 

[field_count] => 0

 

[host_info] => localhost via TCP/IP

 

[info] =>

 

[insert_id] => 22

 

[server_info] => 5.5.16

 

[server_version] => 50516

 

[sqlstate] => 00000

 

[protocol_version] => 10

 

[thread_id] => 82

 

[warning_count] => 1

 

)

 

 

 

[reg_errors] => Array

 

(

 

)

 

 

 

[fn] => Gen

 

[ln] => Koenig

 

=> Gen

 

[e] => Gen@mchsi.com

 

[p] => Gen1900

 

[q] => INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('Gen', 'Gen@mchsi.com', '��]E7�#�8���H�(��Z(0�B�V�c�', 'Gen', 'Koenig', ADDDATE(NOW(), INTERVAL 1 MONTH))

 

[r] => 1

 

[rows] => 0

 

[body] => Thank you for registering at . Blah. Blah.

 

 

 

 

 

)

 

 

 

)

 

 

 

)

 

 

 

[1] => Array

 

(

 

[file] => C:\xampp\htdocs\register.php

 

[line] => 59

 

[function] => mail

 

[args] => Array

 

(

 

[0] => Gen@mchsi.com

 

[1] => Registration Confirmation

 

[2] => Thank you for registering at . Blah. Blah.

 

 

 

 

 

[3] => From: postmaster@localhost

 

)

 

 

 

)

 

 

 

)

This is line#59 in my register.php file:

 

mail ($_POST['email'], 'Registration Confirmation', $body, 'From: postmaster@localhost');

 

These are my settings in my php.ini file:

 

[mail function]

; For Win32 only.

; http://php.net/smtp

SMTP = mail.mediacombb.net (I called my isp and they told me that this is my SMTP.)

; http://php.net/smtp-port

smtp_port = 25

 

; For Win32 only.

; http://php.net/sendmail-from

;sendmail_from = postmaster@localhost

 

Please explain in detail what is wrong and why I am changing it.

 

Error (previously error 1):

Fatal error: Cannot redeclare my_error_handler() (previously declared in C:\xampp\htdocs\includes\config.inc.php:18) in C:\xampp\htdocs\includes\config.inc.php on line 38

 

Line #38 of my config.inc.php file (This is a comment):

 

}//End my_error_handler()definition

 

 

 

Error (previously error 2): When logging in and clicking forgot password, I still get object not found error.

Object not found!

 

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404

Link to comment
Share on other sites

Okay, well, you're really going to have a hard time with this book (and possibly the class) if you aren't solid with PHP and MySQL. And the reason you're getting the second error is almost certainly because you have those wrong values in your configuration file.

Link to comment
Share on other sites

I don't get the error when registering anymore. The problem was I put MYSQL connection was after the header file. (errata in book corrects this)

 

Still getting the other two errors?

 

I get this error when logging in with my password:

Problem #1.

Fatal error: Cannot redeclare my_error_handler() (previously declared in C:\xampp\htdocs\includes\config.inc.php:18) in C:\xampp\htdocs\includes\config.inc.php on line 38

I listed the config.inc.php file in previous post so is this coming from the login.inc.php which is the following:

<?php

 

require('./includes/config.inc.php');

 

//database connection:

require (MYSQL);

 

 

//empty errors for storing errors:

$login_errors = array();

 

//Validate email address:

if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){

$e = mysqli_real_escape_string($dbc,$_POST['email']);

}else{

$login_errors['email'] = 'Please enter a valid email address!';

}

//Validate password:

if (!empty($_POST['pass'])){

$p = mysqli_real_escape_string($dbc, $_POST['pass']);

}else{

$login_errors['pass'] = 'Please enter your password!';

}

//If no errors, query database (date_expired if greater than or equal to this moment, the value is true if not it is false):

if (empty($login_errors)){

$q = "SELECT id, username, type, IF(date_expires >= NOW(), true, false) FROM users WHERE (email ='$e' AND pass ='" . get_password_hash($p) . "')";

$r = mysqli_query ($dbc, $q);

//If one row is returned by database query, get data and store in session:

if (mysqli_num_rows($r) == 1){

$row = mysqli_fetch_array($r, MYSQLI_NUM);

 

//If administrator, create a new session ID for safety:

if($row[2] == 'admin'){

session_regenerate_id(true);

$_SESSION['user_admin'] = true;

}

$_SESSION['user_id'] = $row[0];

$_SESSION['username'] = $row[1];

if($row[3] == 1)$_SESSION['user_not_expired'] = true;

//If no row was returned, create error message:

}else{

$login_errors['login'] = 'The email address and password do not match those on file.';

}

}//End of $login_errors IF.

Link to comment
Share on other sites

Use these setting for the BASE contants:

 

define ('BASE_URI', 'C:\xampp\htdocs');

define ('BASE_URL', 'http://localhost/');

 

After let us know what errors are still coming up. You may also get errors coming up as some of the database tables need to be populated before use.

Link to comment
Share on other sites

Thanks Edward but I get this error (when accessing the index.php) if I change it to that:

arse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\includes\config.inc.php on line 9 (first line iine in define for the constants)

 

According to our instructor, it should be how I have it below. I am not having a problem registering it is just my other two errors in my previous post.

 

define ('BASE_URI', 'http://localhost/');

define ('BASE_URL','/www/');

define ('MYSQL','/includes/mysql.inc.php');

Link to comment
Share on other sites

Change setting from this:

 

define ('BASE_URI', 'http://localhost/');

define ('BASE_URL','/www/');

define ('MYSQL','/includes/mysql.inc.php');

 

to

 

define ('BASE_URI', 'C:\xampp\htdocs');

define ('BASE_URL', 'http://localhost/');

define ('MYSQL', '/includes/mysql.inc.php');

Link to comment
Share on other sites

I resolved this error: Fatal error: Cannot redeclare my_error_handler() (previously declared in C:\xampp\htdocs\includes\config.inc.php:18) in C:\xampp\htdocs\includes\config.inc.php on line 38

 

I figured out I was including the config.inc.php file and MYSQL in the login.inc.php file. I took these out and it fixed the error.

 

 

 

I also resolved my invalid path error: I had the path for the link to the forgot_password.php with an extra s (forgot_passsword.php).

 

Frustrating but finally got it!

Link to comment
Share on other sites

 Share

×
×
  • Create New...