adamjblakey Posted August 13, 2007 Share Posted August 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/ Share on other sites More sharing options...
jitesh Posted August 13, 2007 Share Posted August 13, 2007 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"); Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-322307 Share on other sites More sharing options...
adamjblakey Posted August 13, 2007 Author Share Posted August 13, 2007 Thanks for that.. How do i go about creating something so i access the table with all the urls in so that i can run this check on it. Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-322312 Share on other sites More sharing options...
jitesh Posted August 13, 2007 Share Posted August 13, 2007 Retrive URLs From database and check each using function. Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-322316 Share on other sites More sharing options...
adamjblakey Posted August 13, 2007 Author Share Posted August 13, 2007 If the site script is running on e.g. www.thebigsite.com and the database is on www.myscripts.com how would i go about doing this as i can't do normal connect as people would see my login details to that db. Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-322329 Share on other sites More sharing options...
adamjblakey Posted August 14, 2007 Author Share Posted August 14, 2007 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-323544 Share on other sites More sharing options...
kyleldi Posted August 14, 2007 Share Posted August 14, 2007 store the login information in a file and require_once it. This keeps all the pertinent information out of your pagecode. Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-323551 Share on other sites More sharing options...
Psycho Posted August 14, 2007 Share Posted August 14, 2007 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' } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-323643 Share on other sites More sharing options...
adamjblakey Posted August 14, 2007 Author Share Posted August 14, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-323644 Share on other sites More sharing options...
adamjblakey Posted August 14, 2007 Author Share Posted August 14, 2007 You way seems better mjdamato so i will run with that. I have tried doing this but i get this error: Unable to access validationURL in Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-323652 Share on other sites More sharing options...
adamjblakey Posted August 14, 2007 Author Share Posted August 14, 2007 Solved that it was a missing $ but what is happening now is it comes back with This is Not valid domain every time even though there is that domain in the table. Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-323672 Share on other sites More sharing options...
Psycho Posted August 14, 2007 Share Posted August 14, 2007 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[ Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-323699 Share on other sites More sharing options...
adamjblakey Posted August 15, 2007 Author Share Posted August 15, 2007 Cheers for that mjdamato Quote Link to comment https://forums.phpfreaks.com/topic/64650-best-way-to-do-a-domain-check/#findComment-324438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.