Jump to content

Recommended Posts

Hi,

 

What i want to do is check to make sure that if someone is using my script that the the domain name that site is on is valid.

 

I have a table on my script site which will store the users urls what i was thinking of is if i connect to that database and check to make sure the the current url matches a url in that table.

 

From what i have read i think the best method would be to use curl to check. What i need to do now though is build something which can handle a curl query on the other side. I know how to handle the results when i get them but how would i go about setting this up so i can get the results i need.

 

Cheers,

Adam

Link to comment
https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/
Share on other sites

function url_exists($url)

{

$result  = parse_url($url);

if(isset($result['host'])) {

$cmdResult = gethostbynamel($result['host']);

 

if($cmdResult) {

return true;

} else {

  return false;

}

} else {

return false;

}

}

 

echo url_exists("http://www.google.com");

 

Here's another solution. Int he client file have it call pull the contents of a dynamically generated page on your site using the domain name as a paramter. Then that page only needs to determine if the domain is valid or not and output a true false. This is just a maock up and would need some error handling:

 

In the client code:

 

<?php

$validationURL = "http://www.yourdomain.net/validateDomain.php?domain=".$_SERVER['HTTP_HOST'];

$validation = trim(implode('', file(validationURL))); 

if ($validation == 'valid') {
  echo "This is a valid domain";
} else {
  echo "This is Not valid domain";
}

?>

 

On the validateDomain.php file that will be on your servers you would put this:

<?php

//Insert db connection info here

$domain  = stripslashes($_GET['domain'])
$query = "SELECT * FROM tablename WHERE domain = '$domain'";
$results = mysql_query($query);

if (mysql_num_rows($result)==1) {
  echo 'valid'
}

?>

What i have done now seems to work but don't know how check the results..

 


                $ch = curl_init("http://www.mysite.com/results.xml");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

	$value = curl_exec($ch);

	preg_match_all('/<(website)>([^<]+)<\/\\1>/', $value, $matches);

	while (list(, $value) = each($matches[0])) {
                }
            if ($value = 'http://www.agoodsite.com') {
	 	echo "true";
	}else{
		echo "false";
		}

 

This does not seem to work though and just brings back false. Any ideas?

I tested it and it worked for me. There was a missing semicolon at the end of the first line though. Try running the validateDomain.php page directly and add some echo statements for debuggin purposes. Add different values for the domain name on the query string and see what the results are:

 

<?php

$debug = true; //set this to false to run live

//Insert db connection info here

$domain  = stripslashes($_GET['domain']);
if ($debug) { echo "Domain: $domain<br>"; }

$query = "SELECT * FROM tablename WHERE domain = '$domain'";
if ($debug) { echo "Query: $query<br>"; }

$results = mysql_query($query) or DIE (mysql_error);
if ($debug) { echo "Num Rows: " . mysql_num_rows($result) . "<br>Result: "; }

if (mysql_num_rows($result)==1) {
  echo 'valid';
} else {
  echo 'not valid';
}

?>[/code[

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.