Have you ever wondered how can you verify if a user in your application owns an internet domain? This is not something that most of us have not seen before, most of the tools we use such as Google Search Console and many SaaS platforms such as email delivery services have the process of verifying domain ownership.
a while back working on a project I had to implement the same logic, the user verifies that they own a domain and this would grant them to allow any email address under their domain name to join their organization in our application. I have extracted this logic into an open-source PHP package.
Verify Domain is a simple PHP package with zero dependencies that makes it easy to implement verification of domain ownership in any PHP application.
You can simply include PHP Verify Domain in your project by downloading it as a composer dependency.
composer require hazaveh/verify-domain
Once the package is installed you can instantiate the verification class like the below:
use Hazaveh\VerifyDomain\VerifyDomain; $domainVerifier = new VerifyDomain();
Once you have the client instantiated you can use two available methods of
Verification by file means the user should upload a file on the root of their domain address, the script would expect 3 arguments of domain, file name, and content which will then be used for verification. In a real case scenario, you should provide the content that you’ll be using to verify the domain ownership of a user, for example, this could be an organization ID or some other unique identifier.
Verification by DNS means that the user should create a TXT DNS record in their domain control panel and paste the content that you provide in your application as the value for this record. The script will check the domain DNS records to see whether the provided value is in the domain DNS records.
Verification by Meta Tags will search the HTML body of the domain and look for the meta tag with the name and content provided by you.
The Verification Class does not have any dependency, which means you’re probably able to use it with Dependency Injection in your PHP Framework of choice such as Laravel, without any additional configuration.
The Verify Domain package makes it easy to add domain verification ability to your application or SaaS project in a simple way, all you have to do is to focus on the business logic.