andy5000_uk15 Posted March 16, 2008 Share Posted March 16, 2008 Hi everyone, im new to PHP and these forums, but im in a desperate plee for some help. I have an intel mac and installed the latest version of MAMP. so i could test some php that i have made, well followed a tutorial on how to make a login system. Heres the link of the tutorial. http://www.roscripts.com/PHP_login_script-143.html i have followed it pretty much to the dot but im getting this error. Warning: include(functions.php) [function.include]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/login.php on line 3 Warning: include() [function.include]: Failed opening 'functions.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/login.php on line 3 i have been told that MAMP sometimes misses some of the pear files out on the install. and have already created a db.php that was missing thanks to some help but as i dont know what files should be there i think i will get these errors for quite some time. Anybody know where i can get a list, preferably with the files of the missing .php files. thanks for the help Andrew Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/ Share on other sites More sharing options...
Orio Posted March 16, 2008 Share Posted March 16, 2008 Are you sure you have a file called functions.php in the same directory of this script? (login.php) Orio. Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493379 Share on other sites More sharing options...
BlueSkyIS Posted March 16, 2008 Share Posted March 16, 2008 I use MAMP every day and have used it for years. MAMP is fully contained, there is no 'missing' anything. It's not like the installer selects which files it's going to install; it installs them all. Your problem probably that the file doesn't exist in the document root or relative location on your virtual server. what is your apache document root and where is this script and function.php in relation to document root and each other? Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493398 Share on other sites More sharing options...
andy5000_uk15 Posted March 16, 2008 Author Share Posted March 16, 2008 i dont have a file called functions.php anywhere. i dont know what it does or is supposed to do. like i say i am a newbie. this is the login.php <?php require_once('db.php'); include('functions.php'); if(isset($_POST['Login'])) { if($_POST['username']!='' && $_POST['password']!='') { //Use the input username and password and check against 'users' table $query = mysql_query('SELECT ID, Username, Active FROM users WHERE Username = "'.mysql_real_escape_string($_POST['username']).'" AND Password = "'.mysql_real_escape_string(md5($_POST['password'])).'"'); if(mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); if($row['Active'] == 1) { $_SESSION['user_id'] = $row['ID']; $_SESSION['logged_in'] = TRUE; header("Location: members.php"); } else { $error = 'Your membership was not activated. Please open the email that we sent and click on the activation link'; } } else { $error = 'Login failed !'; } } else { $error = 'Please user both your username and password to access your account'; } } ?> <?php if(isset($error)){ echo $error;}?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <input type="text" id="username" name="username" size="32" value="" /> <input type="password" id="password" name="password" size="32" value="" /> <input type="submit" name="Login" value="Login" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493435 Share on other sites More sharing options...
peranha Posted March 16, 2008 Share Posted March 16, 2008 From a quick glance, this is what goes in the functions.php page. <?php function checkLogin($levels) { if(!$_SESSION['logged_in']) { $access = FALSE; } else { $kt = split(' ', $levels); $query = mysql_query('SELECT Level_access FROM users WHERE ID = "'.mysql_real_escape_string($_SESSION['user_id']).'"'); $row = mysql_fetch_assoc($query); $access = FALSE; while(list($key,$val)=each($kt)) { if($val==$row['Level_access']) {//if the user level matches one of the allowed levels $access = TRUE; } } } if($access==FALSE) { header("Location: login.php"); } else { //do nothing: continue } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493440 Share on other sites More sharing options...
andy5000_uk15 Posted March 16, 2008 Author Share Posted March 16, 2008 right now we are getting somewhere, no errors on the login page now, but im getting an error on the registration page (shown below). Fatal error: Call to undefined function valid_email() in /Applications/MAMP/htdocs/registration.php on line 7 here is the registration file. <?php require_once('db.php'); include('functions.php'); if(isset($_POST['register'])) { if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE) { $query = mysql_query("INSERT INTO users (`Username` , `Password`, `Email`, `Random_key`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error()); $getUser = mysql_query("SELECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error()); if(mysql_num_rows($getUser)==1) {//there's only one MATRIX :PP $row = mysql_fetch_assoc($getUser); $headers = 'From: webmaster@ourdomainhere.com' . "\r\n" . 'Reply-To: webmaster@ourdomainhere.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Activation email from ourdomainhere.com"; $message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: http://www.ourdomainhere.com/confirm.php?ID=".$row['ID']."&key=".$row['Random_key']." Thank you for joining"; if(mail($row['Email'], $subject, $message, $headers)) {//we show the good guy only in one case and the bad one for the rest. $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.'; } else { $error = 'I created the account but failed sending the validation email out. Please inform my boss about this cancer of mine'; } } else { $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.'; } } else { $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match'; } } ?> <?php if(isset($error)){ echo $error;}?> <?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br /> Password: <input type="password" id="password" name="password" size="32" value="" /><br /> Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br /> Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br /> <input type="submit" name="register" value="register" /><br /> </form> <? } ?> (how do you show code like the previous poster has done?) i presume i need to change the bits where it says ourdomainhere.com but will i be able to change them if i am only hosting it on a local server. thanks again for the help Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493445 Share on other sites More sharing options...
BlueSkyIS Posted March 16, 2008 Share Posted March 16, 2008 there is no function called valid_email anywhere in your code. here is the one i use. you might copy/paste it into your functions.php file. function valid_email($eaddr) { if (!ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $eaddr)) { return false; } return true; } Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493447 Share on other sites More sharing options...
peranha Posted March 16, 2008 Share Posted March 16, 2008 Put it in code tags When you reply, it is the # button. You will have to go back to the roscripts page, and the valid_email function is linked in the 11th paragraph right at the end. There are 2 other functions that you will have to get as well. They are also linked there. Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493448 Share on other sites More sharing options...
andy5000_uk15 Posted March 16, 2008 Author Share Posted March 16, 2008 ok, so i copied those 3 functions into the functions.php when i try to register i get: Warning: Missing argument 3 for checkUnique(), called in /Applications/MAMP/htdocs/registration.php on line 7 and defined in /Applications/MAMP/htdocs/functions.php on line 70 Notice: Undefined variable: compared in /Applications/MAMP/htdocs/functions.php on line 72 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/functions.php on line 73 Warning: Missing argument 3 for checkUnique(), called in /Applications/MAMP/htdocs/registration.php on line 7 and defined in /Applications/MAMP/htdocs/functions.php on line 70 Notice: Undefined variable: compared in /Applications/MAMP/htdocs/functions.php on line 72 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/functions.php on line 73 No database selected any clues? Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493472 Share on other sites More sharing options...
peranha Posted March 16, 2008 Share Posted March 16, 2008 Post the functions.php page in the code tag # sign when you reply Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493474 Share on other sites More sharing options...
andy5000_uk15 Posted March 16, 2008 Author Share Posted March 16, 2008 <#><?php function checkLogin($levels) { if(!$_SESSION['logged_in']) { $access = FALSE; } else { $kt = split(' ', $levels); $query = mysql_query('SELECT Level_access FROM users WHERE ID = "'.mysql_real_escape_string($_SESSION['user_id']).'"'); $row = mysql_fetch_assoc($query); $access = FALSE; while(list($key,$val)=each($kt)) { if($val==$row['Level_access']) {//if the user level matches one of the allowed levels $access = TRUE; } } } if($access==FALSE) { header("Location: login.php"); } else { //do nothing: continue } } function valid_email($eaddr) { if (!ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $eaddr)) { return false; } return true; } function random_string($type = 'alnum', $len = { switch($type) { case 'alnum' : case 'numeric' : case 'nozero' : switch ($type) { case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; break; case 'nozero' : $pool = '123456789'; break; } $str = ''; for ($i=0; $i < $len; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; break; case 'unique' : return md5(uniqid(mt_rand())); break; } } function checkUnique($table, $field, $compared) { $query = mysql_query('SELECT '.mysql_real_escape_string($field).' FROM '.mysql_real_escape_string($table).' WHERE "'.mysql_real_escape_string($field).'" = "'.mysql_real_escape_string($compared).'"'); if(mysql_num_rows($query)==0) { return TRUE; } else { return FALSE; } } ?> </#> Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493494 Share on other sites More sharing options...
sasa Posted March 16, 2008 Share Posted March 16, 2008 try checkUnique('users','Username', $_POST['username']) Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493497 Share on other sites More sharing options...
andy5000_uk15 Posted March 16, 2008 Author Share Posted March 16, 2008 im not quite sure where you mean? replace function checkUnique($table, $field, $compared) with checkUnique('users','Username', $_POST['username']) ? Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493498 Share on other sites More sharing options...
sasa Posted March 16, 2008 Share Posted March 16, 2008 in registration.php, line 7 Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493503 Share on other sites More sharing options...
andy5000_uk15 Posted March 16, 2008 Author Share Posted March 16, 2008 <code> if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE) </code> that is line 7 at the moment, are you saying remove that and instead put <code>checkUnique('users','Username', $_POST['username'])</code> thanks im really not getting how to put it into code am i Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493512 Share on other sites More sharing options...
peranha Posted March 16, 2008 Share Posted March 16, 2008 instead of using < use [ You can also click on the # button above the smilies. Put that on line 7 of the functions.php file Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493514 Share on other sites More sharing options...
andy5000_uk15 Posted March 16, 2008 Author Share Posted March 16, 2008 ah ok, thanks Parse error: syntax error, unexpected T_IF in /Applications/MAMP/htdocs/registration.php on line 7 this is the error now.ahhhh will this ever end.lol. { checkUnique('users','Username', $_POST['username']) if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE) { thats line 6-8 thanks Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493517 Share on other sites More sharing options...
BlueSkyIS Posted March 16, 2008 Share Posted March 16, 2008 an unexpected 'if'. where is the if and what's wrong with it? Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493521 Share on other sites More sharing options...
sasa Posted March 16, 2008 Share Posted March 16, 2008 no i say that ad 'users' as 1st argument in function checkUnique in that line look definition of function checkUnique, 1st argument is table name 'users' is name of table where you data, isn't it? Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493522 Share on other sites More sharing options...
peranha Posted March 16, 2008 Share Posted March 16, 2008 { checkUnique('users','Username', $_POST['username']) {if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE) } { You can try that, not sure why the if statement is there though Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493524 Share on other sites More sharing options...
andy5000_uk15 Posted March 16, 2008 Author Share Posted March 16, 2008 yeh users is the name of the table where the registration data should end up. if i change the code to peranha's code i get. Parse error: syntax error, unexpected '{' in /Applications/MAMP/htdocs/registration.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493528 Share on other sites More sharing options...
sasa Posted March 16, 2008 Share Posted March 16, 2008 this lines { if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('users','Username', $_POST['username'])==TRUE && checkUnique('users','Email', $_POST['email'])==TRUE) { Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493530 Share on other sites More sharing options...
andy5000_uk15 Posted March 16, 2008 Author Share Posted March 16, 2008 sorry shall i put that in line 7??? Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493540 Share on other sites More sharing options...
peranha Posted March 16, 2008 Share Posted March 16, 2008 yeah, replace your line 7 with the one sasa suggested. Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493548 Share on other sites More sharing options...
andy5000_uk15 Posted March 16, 2008 Author Share Posted March 16, 2008 error recieved Parse error: syntax error, unexpected T_ELSE in /Applications/MAMP/htdocs/registration.php on line 39 do you think this is ever going to work. im learning fast here.really appreaciate it. <?php require_once('db.php'); include('functions.php'); if(isset($_POST['register'])) { { if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('users','Username', $_POST['username'])==TRUE && checkUnique('users','Email', $_POST['email'])==TRUE) { } $query = mysql_query("INSERT INTO users (`Username` , `Password`, `Email`, `Random_key`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error()); $getUser = mysql_query("SELECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error()); if(mysql_num_rows($getUser)==1) {//there's only one MATRIX :PP $row = mysql_fetch_assoc($getUser); $headers = 'From: webmaster@ourdomainhere.com' . "\r\n" . 'Reply-To: webmaster@ourdomainhere.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Activation email from ourdomainhere.com"; $message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: http://www.ourdomainhere.com/confirm.php?ID=".$row['ID']."&key=".$row['Random_key']." Thank you for joining"; if(mail($row['Email'], $subject, $message, $headers)) {//we show the good guy only in one case and the bad one for the rest. $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.'; } else { $error = 'I created the account but failed sending the validation email out. Please inform my boss about this cancer of mine'; } } else { $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.'; } } else { $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match'; } } ?> <?php if(isset($error)){ echo $error;}?> <?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br /> Password: <input type="password" id="password" name="password" size="32" value="" /><br /> Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br /> Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br /> <input type="submit" name="register" value="register" /><br /> </form> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/96404-functionsphp/#findComment-493553 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.