Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1383 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Need some help, not sure...

Thread title: Need some help, not sure...
Reply    
    Thread tools Search this thread Display Modes  
07-30-2012, 10:58 PM
#1
dlopez916 is offline dlopez916
dlopez916's Avatar
Status: Member
Join date: Oct 2009
Location: Russellville, AR
Expertise: CSS, HTML, Flash, Photoshop
Software: Photoshop, Dreamweaver, Frefox
 
Posts: 108
iTrader: 0 / 0%
 

dlopez916 is on a distinguished road

  Old  Need some help, not sure...

Ok, so I have an idea for a membership based site. What I am wanting to accomplish is for visitors to register, and they choose a username. Then, using that username, once a month, generate a special code that is unique to each user, and includes part of their username. How is this able to be done? I assumed PHP would be needed, thus my post in this forum. Thanks!

08-11-2012, 09:30 PM
#2
fde is offline fde
Status: I'm new around here
Join date: Aug 2012
Location: netherlands
Expertise: php
Software: xampp, cream for vim
 
Posts: 3
iTrader: 0 / 0%
 

fde is on a distinguished road

  Old

Imo you should use a cronjob which runs a php shell script.



This script set to run monthy in cron, connects to database, grabs the usernames and email adresses from db into array or object.

Then you do something like:
PHP Code:


$seperator
=" __ " 
$subject 'special code';
$headers 'From: webmaster@example.com' "\r\n" .
    
'Reply-To: webmaster@example.com' "\r\n" .
    
'X-Mailer: PHP/' phpversion();


foreach (
$users as $user){
 
$uniqspecode=md5($user['name']).$seperator.md5(time());
$to      =$user['email'];
$message 'Hi here is your special code: '.$uniqspecode;

mail($to$subject$message$headers);


When using object, its $user->name and $user->email
http://php.net/manual/en/language.oop5.php
http://php.net/mail
Make sure this script cannot be accessed directly from the internet, you don't want someone to visit http://yourdomain.com/script.php and send out a new batch of codes at every page refresh. One way to prevent this is instead of using <?php and ?>,
PHP Code:
#!/usr/bin/php 
in top of the script. Note you need the PHP CLI properly installed. Another way then cron is to just run the script manually every month via a protected login environment.

The seperator is provided to allow parsing of the specialcode and compare to md5 encrypted usernames, to determine which user it was.

Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed