Jump to content

Recommended Posts

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";

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/
Share on other sites

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";

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258034
Share on other sites

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;

?>

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258040
Share on other sites

<?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??

 

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258064
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258068
Share on other sites

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 ;

 

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258072
Share on other sites

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);?> 

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258078
Share on other sites

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;

?>


Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258086
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258087
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258095
Share on other sites

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;

?>

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258098
Share on other sites

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; ?>

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258108
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/52305-creating-a-function/#findComment-258133
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.