Hi all, I'm trying to set up a simple registration page and I'm using the book PHP Solutions by David Powers to help. It seems I'm missing the corefuncs.php file but cant locate it anywhere. (many books give problems like this). Hope you can help. Thanks. (hopefully the codes are ok otherwise). My errors are: Warning: include(../includes/corefuncs.php) [function.include]: failed to open stream: No such file or directory in /home/crikle/public_html/register.php on line 5 Warning: include(../includes/corefuncs.php) [function.include]: failed to open stream: No such file or directory in /home/crikle/public_html/register.php on line 5 Warning: include() [function.include]: Failed opening '../includes/corefuncs.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/crikle/public_html/register.php on line 5 Fatal error: Call to undefined function nukemagicquotes() in /home/crikle/public_html/register.php on line 6 My code is: <?php // execute script only if form has been submitted if (array_key_exists('register', $_POST)) { // remove backslashes from the $_POST array include('../includes/corefuncs.php'); nukeMagicQuotes(); // check length of username and password $username = trim($_POST['user_name']); $pwd = trim($_POST['password']); if (strlen($username) < 6 || strlen($pwd) < 6) { $result = 'Username and password must contain at least 6 characters'; } // check that the passwords match elseif ($pwd != $_POST['conf_pwd']) { $result = 'Your passwords don\'t match'; } // continue if OK else { // encrypt password, using username as salt $pwd = sha1($username.$pwd); // define filename and open in read-write append mode $filename = 'C:/private/encrypted.txt'; $file = fopen($filename, 'a+'); // if filesize is zero, no names yet registered // so just write the username and password to file if (filesize($filename) === 0) { fwrite($file, "$username, $pwd"); } // if filesize is greater than zero, check username first else { // move internal pointer to beginning of file rewind($file); // loop through file one line at a time while (!feof($file)) { $line = fgets($file); // split line at comma, and check first element against username $tmp = explode(', ', $line); if ($tmp[0] == $username) { $result = 'Username taken - choose another'; break; } } // if $result not set, username is OK if (!isset($result)) { // insert line break followed by username, comma, and password fwrite($file, "\r\n$username, $pwd"); $result = "$username registered"; } // close the file fclose($file); } } } ?> HTML code is: <!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=iso-8859-1" /> <title>Register user</title> </head> <body> <h1>Register user</h1> <?php if (isset($result)) { echo "<p>$result</p>"; } ?> <form method="POST" action="register.php"> <p> <label for="user_name">Username:</label> <input type="text" name="user_name" id="user_name" /> </p> <p> <label for="password">Password:</label> <input type="password" name="password" id="password" /> </p> <p> <label for="conf_pwd">Confirm password:</label> <input type="password" name="conf_pwd" id="conf_pwd" /> </p> <p> <input name="register" type="submit" id="register" value="Register" /> </p> </form> </body> </html>
Hi buddingphp I just bought the same book too but found only these two files were missing from the includes folder of the downloadable exercise files. I found the solution to corefuncs.php Copy this and save it as corefuncs.php within the includes folder: <?php function nukeMagicQuotes() { if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); $_GET = array_map('stripslashes_deep', $_GET); $_COOKIE = array_map('stripslashes_deep', $_COOKIE); } } ?> OK, for the other file, I can't track it down either. Perhaps write to the author. I would comment out the missing include. I think it will work without it. //comment out the missing include. //include('includes/title.inc.php'); include('includes/corefuncs.php'); OH, I just found out that title.inc.php is just for building a dynamic title. Just remove it along with the insides of the content tag: <title>Japan Journey<?php if (isset($title)) {echo "—{$title}";} ?></title> <title>Japan Journey</title> Hope that helps. Please reply if you have any more solutions. Michael dolcemedia ltd