I am trying to create a registration system that allows users to submit their website URLs. Now when a user enters a URL, it checks against the database to see if it already exists, and rejects it if it does.
However, my problem is because of this :
If http://www.example.com
is in the database and I enter http://example.com
, this counts as a different URL as far as the check is concerned, and it allows the submission.
Is there a proper way to handle this, apart from retrieving all records, removing the www
if present, and then comparing? (Which is a terribly inefficient way to do so!)
Note : Adding Laravel tag in case it has any helper functions for this (I am using a laravel-4 installation).
EDIT : This is my current logic for the check :
$exists_url = DB::table("user_urls")
->where('site_url', 'like', $siteurl)
->get();
if($exists_url)
{
return Redirect::to('submiturl')->withErrors('Site already exists!');
}
EDIT 2 : One way is to take the given URL http://www.example.com
, and then search the database for http://www.example.com
, www.example.com
, http://example.com
and example.com
. However I'm trying to find a more efficient way to do this!