473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Activating users using email in php

Please help me to get a php code that activates users upon registration by sending the activation codes to their specified emails.

@Rabbit

Expand|Select|Wrap|Line Numbers
  1. $host  = $_SERVER['HTTP_HOST'];
  2. $host_upper = strtoupper($host);
  3. $login_path = @ereg_replace('admin','',dirname($_SERVER['PHP_SELF']));
  4. $path   = rtrim($login_path, '/\\');
  5.  
  6. $message = 
  7. "Thank you for registering with us. Your account has been activated...
  8.  
  9. *****LOGIN LINK*****\n
  10. http://$host$path/login.php
  11.  
  12. Thank You
  13.  
  14. Administrator
  15. $host_upper
  16. ______________________________________________________
  17. THIS IS AN AUTOMATED RESPONSE. 
  18. ***DO NOT RESPOND TO THIS EMAIL****
  19. ";
  20.  
  21.     @mail($to_email, "User Activation", $message,
  22.     "From: \"Member Registration\" <auto-reply@$host>\r\n" .
  23.      "X-Mailer: PHP/" . phpversion());
  24.  
  25.  
  26.  echo "Active";
  27.  
  28.  
  29. }
Mar 21 '12 #1
2 1823
What exactly are you trying to accomplish? Are you sending an activation code after they fill out a registration form? What I would do is this:
  1. Generate a random number for each user and store it in a database.
  2. Send them a hash of this random number in your email (retrieve it from the database, then sha1() or md5() it).
  3. When they click on the link/enter the activation code, retrieve the number from the database, hash it, and compare it to the hash they have. If they match, your user is legitimate.

Example:
Expand|Select|Wrap|Line Numbers
  1. function registerUser() {
    //... whatever code you already have here
    $activationCode = rand();
    //... insert $activationCode into the database alongside other user info
    }
  2.  
  3. //... meanwhile, the user clicks on a link in the email with the hash in a GET variable
  4.  
  5. $submittedHash = $_GET['ac'];
  6.  
  7. $storedCode = /* Put whatever code here to retrieve the number you stored in the database earlier */;
  8.  
  9. if ($submittedHash == md5($storedCode)) 
    loginSuccessful($submittedHash); // or whatever
Mar 26 '12 #2
You can also check out this tutorial for even more comprehensive help.
Mar 26 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Maria Bitsku | last post by:
How do I deactivate a window using Javascript. For example if I have a window that opens up another window, how do I prevent the user from clicking (doing anything) in the original window until...
5
by: Michael Hill | last post by:
I have a general question about how people generally tend to deal with users data that they enter. As an example users enter double quotes in a text field surrounding a specific piece of text...
16
by: Wayne Aprato | last post by:
I have several Access 97 databases which are split into front end and back end running off a server. The front end mde is shared by 2 or 3 - absolute maximum of 6 concurrent users. This scenario...
4
by: Michael | last post by:
Hi, I have an Access database set up on a network drive that several users can access. The database has many queries but just one main form. I have designed a startup form where a user can...
7
by: Sync Walantaji | last post by:
Hi, I would like to write a asp.net winform program to authenticate users on Active Directory. Can I do this with asp.net if the IIS server is not part of the Active directory domain? Is...
1
by: Sivaraman.S | last post by:
I am unable to create new users using directory services in Windows 2003 server. But it is possible to create users with ASP.NET applications in windows 2000. I am getting "Permission Denied"...
1
by: babar | last post by:
plz tell me how can i(admin) block and unblock users using checkbox?
0
by: Reshmi Jacob | last post by:
Hi , How cal I SELECT all users using a particular tablespace. For eg : if UserA and UserB uses TS-X and UserC and UserD uses TS-Y.....I want the result like this Table space ...
20
by: Ramdas | last post by:
How do I add users using Python scripts on a Linux machine? Someone has a script?
6
by: fjm | last post by:
Hi all.. Didn't expect to be back so soon but I have an other dilema going on where I can sure use some expert advice. I have a php system that will be used in a multi-user environment. There...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.