runnerjp Posted May 21, 2007 Share Posted May 21, 2007 how do i create a function for key?? <?php function randomkeys($length){ $pattern="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; for($i=0; $i<$length; $i++) $key.=$pattern{rand(0,61)}; return $key; } function addNewUser($username, $password, $email){ $time=time(); if(strcasecmp($username, ADMIN_NAME) == 0) $ulevel=ADMIN_LEVEL; else $ulevel=USER_LEVEL; $key=$this->randomkeys(30); $status = 0; $q="INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', $time, $status,'$key')"; $result = mysql_query($q, $this->connection) or die(mysql_error()); return $result; }?> so that im able to but it into an email like so ."http://runnerselite.com/login/activate.php?id=".$key."\n\n"; Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/ Share on other sites More sharing options...
Wuhtzu Posted May 21, 2007 Share Posted May 21, 2007 You have created that function? function randomkeys($length){ $pattern="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; for($i=0; $i<$length; $i++) $key.=$pattern{rand(0,61)}; return $key; } Now you either change the function to specifically echo/print the output (the key) or you just asign the output to $key which will be the smartest in my opinion: $key = randomkeys(16); "http://runnerselite.com/login/activate.php?id=" . $key . "\n\n"; Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258034 Share on other sites More sharing options...
runnerjp Posted May 21, 2007 Author Share Posted May 21, 2007 i seem to get n Parse error: syntax error, unexpected T_STRING in /home/runnerse/public_html/website/login/include/mailer.php on line 19 <?php class Mailer { /** * sendWelcome - Sends a welcome message to the newly * registered user, also supplying the username and * password. */ function sendNewPass($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "runnerselite - registration"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to runnerselite.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n" ."$key = randomkeys(16); "http://runnerselite.com/login/activate.php?id=" . $key . "\n\n"; return mail($email,$subject,$body,$from); /** * sendNewPass - Sends the newly generated password * to the user's email address that was specified at * sign-up. */ function sendNewPass($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "Jpmaster77's Site - Your new password"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to Jpmaster77's Site.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n" ."It is recommended that you change your password " ."to something that is easier to remember, which " ."can be done by going to the My Account page " ."after signing in.\n\n" ."- Jpmaster77's Site"; return mail($email,$subject,$body,$from); } }; /* Initialize mailer object */ $mailer = new Mailer; ?> <? /** * Mailer.php * * The Mailer class is meant to simplify the task of sending * emails to users. Note: this email system will not work * if your server is not setup to send mail. * * If you are running Windows and want a mail server, check * out this website to see a list of freeware programs: * <http://www.snapfiles.com/freeware/server/fwmailserver.html> * * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) * Last Updated: August 19, 2004 */ class Mailer { /** * sendWelcome - Sends a welcome message to the newly * registered user, also supplying the username and * password. */ function sendWelcome($user, $email, $pass, $key){ $send = mail($email , "Registration Confirmation" , "Thank you for registering with YourWebsite.\n\nYour username and password is below, along with details on how to activate your account.\n\nUser: ".$username."\nPass: ".$pass."\n\nClick the link below to activate your account:\nhttp://scrowler.biorust.com/user/activate.php?id=".$act."\n\nPlease do not reply, this is an automated mailer.\n\nThanks", "FROM: auto@mailer.com"); /** * sendNewPass - Sends the newly generated password * to the user's email address that was specified at * sign-up. */ function sendNewPass($user, $email, $pass){ $from = "From: "admin@runnerselite.com"; $subject = "Jpmaster77's Site - Your new password"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to Jpmaster77's Site.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n" ."It is recommended that you change your password " ."to something that is easier to remember, which " ."can be done by going to the My Account page " ."after signing in.\n\n" ."- Jpmaster77's Site"; return mail($email,$subject,$body,$from); } }; /* Initialize mailer object */ $mailer = new Mailer; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258040 Share on other sites More sharing options...
Wuhtzu Posted May 21, 2007 Share Posted May 21, 2007 Thats is because you have done this: ."$key = randomkeys(16); "http://runnerselite.com/login/activate.php?id=" . $key . "\n\n"; instead of $key = $randomkeys(16); ."http://runnerselite.com/login/activate.php?id=" . $key . "\n\n"; Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258046 Share on other sites More sharing options...
runnerjp Posted May 21, 2007 Author Share Posted May 21, 2007 oh yer but now im gettn ing yntax error, unexpected T_VARIABLE in $key = $randomkeys(16); Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258047 Share on other sites More sharing options...
Wuhtzu Posted May 21, 2007 Share Posted May 21, 2007 Well my mistake, a function is called without $: $key = randomkeys(16) $key = $randomkeys(16) If you are creating classes you should have been able to spot that syntax error - but of course we can all stare our selves blind Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258059 Share on other sites More sharing options...
akitchin Posted May 21, 2007 Share Posted May 21, 2007 if you're generating the $key in the query, you'll need to pass this to the sendNewPass() function as well; otherwise, you'll just be creating a new random key in sendNewPass() which doesn't correspond to the one for that user. Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258060 Share on other sites More sharing options...
runnerjp Posted May 21, 2007 Author Share Posted May 21, 2007 <?php function sendNewPass($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "runnerselite - registration"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to runnerselite.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n" $key = randomkeys(16); <--- error ."http://runnerselite.com/login/activate.php?id=". $key ."\n\n" return mail($email,$subject,$body,$from);?> still does not seem to work still getting same error/// if you're generating the $key in the query, you'll need to pass this to the sendNewPass() function as well; otherwise, you'll just be creating a new random key in sendNewPass() which doesn't correspond to the one for that user. what do you mean?? Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258064 Share on other sites More sharing options...
akitchin Posted May 21, 2007 Share Posted May 21, 2007 ignore me - i'm reading too far into what you're using $key for. try this: <?php function sendNewPass($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "runnerselite - registration"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to runnerselite.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n"; $key = randomkeys(16); <--- error $body .= "http://runnerselite.com/login/activate.php?id=". $key ."\n\n"; return mail($email,$subject,$body,$from);?> assuming that achieves what you want. you have to interrupt the string assignment in order to create the $key. Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258068 Share on other sites More sharing options...
Wuhtzu Posted May 21, 2007 Share Posted May 21, 2007 I was almost about to say it in a previous reply, but I didn't so I'll do it now. Assign the value to $key somewhere else... it's an important stage in generating the mail so place it as the first line or something like that... function sendNewPass() { $key = randomkeys(16); $from = .... } ... because it causes you to make syntax errors when you have it squeezed in between the body text. After ."New Password: ".$pass."\n\n" do not join another string by the . and therefore you need to end it with a ; ."New Password: ".$pass."\n\n"; $key = randomkeys(16); //End with ; $body .= "http://runnerselite.com/login/activate.php?id=". $key ."\n\n"; //End with ; Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258072 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 I think i said the same thing in the last thread Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258075 Share on other sites More sharing options...
runnerjp Posted May 21, 2007 Author Share Posted May 21, 2007 oh i seem to have anouther error Parse error: syntax error, unexpected ';', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <?php class Mailer { /** * sendWelcome - Sends a welcome message to the newly * registered user, also supplying the username and * password. */ function sendNewPass($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "runnerselite - registration"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to runnerselite.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n"; $key = randomkeys(16); $body .= "http://runnerselite.com/login/activate.php?id=". $key ."\n\n"; return mail($email,$subject,$body,$from); /** * sendNewPass - Sends the newly generated password * to the user's email address that was specified at * sign-up. */ function sendNewPass($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "Jpmaster77's Site - Your new password"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to Jpmaster77's Site.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n" ."It is recommended that you change your password " ."to something that is easier to remember, which " ."can be done by going to the My Account page " ."after signing in.\n\n" ."- Jpmaster77's Site"; return mail($email,$subject,$body,$from); } }; <--- this is line 52!!! /* Initialize mailer object */ $mailer = new Mailer; ?> ahh i get it so i would add it like so <?php function sendNewPass($user, $email, $pass){ $key = randomkeys(16); $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "runnerselite - registration"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to runnerselite.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n"; $body .= "http://runnerselite.com/login/activate.php?id=". $key ."\n\n"; return mail($email,$subject,$body,$from);?> Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258078 Share on other sites More sharing options...
akitchin Posted May 21, 2007 Share Posted May 21, 2007 the parse error tells you exactly what's wrong - there shouldn't be a semicolon there. why did you put one there? Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258081 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 also close the sendNewPass function with a } Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258084 Share on other sites More sharing options...
runnerjp Posted May 21, 2007 Author Share Posted May 21, 2007 becuase when i remove }; i get unexpected $end so i thought i need to add ; to solve this also by closeing the sendNewPass function with a } Cannot redeclare sendnewpass() <?php class Mailer { /** * sendWelcome - Sends a welcome message to the newly * registered user, also supplying the username and * password. */ function sendNewPass($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "runnerselite - registration"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to runnerselite.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n"; $key = randomkeys(16); $body .= "http://runnerselite.com/login/activate.php?id=". $key ."\n\n"; return mail($email,$subject,$body,$from); } /** * sendNewPass - Sends the newly generated password * to the user's email address that was specified at * sign-up. */ function sendNewPass($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "Jpmaster77's Site - Your new password"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to Jpmaster77's Site.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n" ."It is recommended that you change your password " ."to something that is easier to remember, which " ."can be done by going to the My Account page " ."after signing in.\n\n" ."- Jpmaster77's Site"; return mail($email,$subject,$body,$from); } } /* Initialize mailer object */ $mailer = new Mailer; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258086 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 becuase when i remove }; i get unexpected $end so i thought i need to add ; to solve this NO, add the last } <?php /* Initialize mailer object */ $mailer = new Mailer; } //<---HERE ?> also by closeing the sendNewPass function with a } Cannot redeclare sendnewpass() because you have that function twice... Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258087 Share on other sites More sharing options...
runnerjp Posted May 21, 2007 Author Share Posted May 21, 2007 ok that does not work <?php class Mailer { /** * sendWelcome - Sends a welcome message to the newly * registered user, also supplying the username and * password. */ function sendNewPass($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "runnerselite - registration"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to runnerselite.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n"; $key = randomkeys(16); $body .= "http://runnerselite.com/login/activate.php?id=". $key ."\n\n"; return mail($email,$subject,$body,$from); /** * sendNewPass - Sends the newly generated password * to the user's email address that was specified at * sign-up. */ function sendNewPass($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "Jpmaster77's Site - Your new password"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to Jpmaster77's Site.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n" ."It is recommended that you change your password " ."to something that is easier to remember, which " ."can be done by going to the My Account page " ."after signing in.\n\n" ."- Jpmaster77's Site"; return mail($email,$subject,$body,$from); } } /* Initialize mailer object */ $mailer = new Mailer; } ?> see i just get Parse error: syntax error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/runnerse/public_html/website/login/include/mailer.php on line 54 .... i have tried removing it so its just return mail($email,$subject,$body,$from); } /* Initialize mailer object */ $mailer = new Mailer; } and that does not work... Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258095 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 remove one of the functions <?php class Mailer { function sendNewPass($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "Jpmaster77's Site - Your new password"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to Jpmaster77's Site.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n" ."It is recommended that you change your password " ."to something that is easier to remember, which " ."can be done by going to the My Account page " ."after signing in.\n\n" ."- Jpmaster77's Site"; return mail($email,$subject,$body,$from); } } /* Initialize mailer object */ $mailer = new Mailer; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258098 Share on other sites More sharing options...
runnerjp Posted May 21, 2007 Author Share Posted May 21, 2007 ah yes i changed it to <?php class Mailer { function sendWelcome($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "runnerselite - registration"; $body = $user.",\n\n" ."We've generated a new password for you at your " ."request, you can use this new password with your " ."username to log in to runnerselite.\n\n" ."Username: ".$user."\n" ."New Password: ".$pass."\n\n"; $key = randomkeys(16); $body .= "http://runnerselite.com/login/activate.php?id=". $key ."\n\n"; return mail($email,$subject,$body,$from); } } /* Initialize mailer object */ $mailer = new Mailer; ?> but i get Call to undefined function: randomkeys() but why because the function was set while regestering with <?php function randomkeys($length){ $pattern="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; for($i=0; $i<$length; $i++) $key.=$pattern{rand(0,61)}; return $key; } function addNewUser($username, $password, $email){ $time=time(); if(strcasecmp($username, ADMIN_NAME) == 0) $ulevel=ADMIN_LEVEL; else $ulevel=USER_LEVEL; $key=$this->randomkeys(16); $status = 0; $q="INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', $time, $status,'$key')"; $result = mysql_query($q, $this->connection) or die(mysql_error()); return $result; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258108 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 OK.. get a book and read up on classes php, Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258110 Share on other sites More sharing options...
runnerjp Posted May 21, 2007 Author Share Posted May 21, 2007 i have tried to look this up as u saw i made most of the script but follow errors on the way as every 1 else does as the LEARN Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258116 Share on other sites More sharing options...
runnerjp Posted May 21, 2007 Author Share Posted May 21, 2007 btw the mailerclass if called AFTER the data is added to database Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258120 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 you copied most of the script random code HERE Add User HERE Infact ALL of your code has be chopped from others scripts and when you paste it in one it fails then you post it an ask why... Gezzz Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258121 Share on other sites More sharing options...
runnerjp Posted May 21, 2007 Author Share Posted May 21, 2007 bad call as i have not taken them from there i was using i different method of enabling users by the password...i got told not to use the password as its bad security so i got given a use of random keys...obviously i adapted it to suit my needs... also the insert into script is by my own use... please do not accuse as its not nice Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258133 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 the fact is you miss even the basic's.... i am not going to continue this.. good luck Quote Link to comment https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258136 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.