View Full Version : can someone please help me!
kyle246
07-05-2011, 10:45 PM
Hello everyone. I copied some code to my website (it is a form) and it is not working.
It looks like it is very simple code, but I do not know how to get it to work.
In the form, you are supposed to be able to submit a domain name and the results will show up but its not working.
It is located at thundertutorials.com/testing.html
thanks,
Kyle
I would appreciate any help
deepsand
07-05-2011, 11:23 PM
Looks like you either miscopied the code, or copied from a dynamically generated page, rather than a static one.
<form method="post" action="">
<p><b>Domain/Host Name:</b> <input type="text" name="sitehost" size='30' maxlength='50' value=" Put Your Site In Here "> <input type="submit" value="Grab Details"></p>
</form>
<ul>
Note that the code that follows the above does not use form data, but is hard coded to refer to your own Domain Name.
<li>Google indexed pages: <a href="http://www.google.com/search?q=site%3Awww.thundertutorials.com&hl=en">n/a</a></li>
<li>Yahoo indexed pages: <a href="http://siteexplorer.search.yahoo.com/search?p=www.thundertutorials.com">1</a></li>
<li>Yahoo inbound links: <a href="http://siteexplorer.search.yahoo.com/search?p=www.thundertutorials.com&bwm=i">1</a></li>
<li>Bing indexed pages: <a href="http://www.bing.com/search?q=site%3Awww.thundertutorials.com&mkt=en-US">n/a</a></li>
<li>Bing inbound links: <a href="http://www.bing.com/search?q=inbody%3Awww.thundertutorials.com&mkt=en-US">2</a></li>
</ul>
kyle246
07-06-2011, 12:39 AM
thank you very much for the reply
so, i did copy the code, but i'm not sure if it was from a a "dynamically generated page" or not. The place where the code was copied from (and I have permission) was from targetedgemarketing.com
thanks,
kyle
deepsand
07-06-2011, 02:07 AM
The Form code - that in the first Code box above - returns the input URL to them when the Submit button, named "Grab Details," is clicked on.
Their server then regenerates the page, with that URL plugged into the the display code shown in the second Code box above.
When first viewed, their page has their own URL in that 2nd block of code. You copied the page after having entered & submitted your own URL.
You are missing the server side code.
kyle246
07-06-2011, 02:24 AM
The Form code - that in the first Code box above - returns the input URL to them when the Submit button, named "Grab Details," is clicked on.
Their server then regenerates the page, with that URL plugged into the the display code shown in the second Code box above.
When first viewed, their page has their own URL in that 2nd block of code. You copied the page after having entered & submitted your own URL.
You are missing the server side code.
Thank you again for helping me out. Do you know where I could get the "server side code?" Would I be able to find it from viewing the page source, or would I have to contact the owners of the website?
thanks,
Kyle
deepsand
07-06-2011, 03:27 AM
The source code visible to us is only the client side code. For the server side, you'll need to go to the owner/operator of the site.
kyle246
07-06-2011, 08:04 PM
I got this code that they said is for that form thing. It is in PHP. How would I get this to work?
Here is what I got.
<head>
<script type="text/javascript" src="http://www.websnapr.com/js/websnapr.js"></script>
</head>
then for the form i have this code
<form method="post" action="<?$_SERVER['PHP_SELF'];?>">
<p><b>Domain/Host Name:</b> <input type="text" name="sitehost" size='30' maxlength='50' value=" Put Your Site In Here "> <input type="submit" value="Grab Details"></p>
</form>
<ul>
<li>Google indexed pages: <?=getGooglePages($sitehost);?></li>
<li>Yahoo indexed pages: <?=getYahooPages($sitehost);?></li>
<li>Yahoo inbound links: <?=getYahooLinks($sitehost);?></li>
<li>Bing indexed pages: <?=getBingPages($sitehost);?></li>
<li>Bing inbound links: <?=getBingLinks($sitehost);?></li>
<li>Domain age: <?=getDomainAge($sitedomain);?></li>
</ul>
<?php
function getGooglePages($host) {
$request = "http://www.google.com/search?q=" . urlencode("site:" . $host) . "&hl=en";
$data = getPageData($request);
preg_match('/<div id=resultStats>(About )?([\d,]+) result/si', $data, $p);
$value = ($p[2]) ? $p[2] : "n/a";
$string = "<a href=\"" . $request . "\">" . $value . "</a>";
return $string;
}
function getGoogleLinks($host) {
$request = "http://www.google.com/search?q=" . urlencode("link:" . $host) . "&hl=en";
$data = getPageData($request);
preg_match('/<div id=resultStats>(About )?([\d,]+) result/si', $data, $l);
$value = ($l[2]) ? $l[2] : "n/a";
$string = "<a href=\"" . $request . "\">" . $value . "</a>";
return $string;
}
function getYahooPages($host) {
$request = "http://siteexplorer.search.yahoo.com/search?p=" . urlencode($host);
$data = getPageData($request);
preg_match('/Pages \(([\d,]+)/si', $data, $p);
$value = ($p[1]) ? $p[1] : "n/a";
$string = "<a href=\"" . $request . "\">" . $value . "</a>";
return $string;
}
function getYahooLinks($host) {
$request = "http://siteexplorer.search.yahoo.com/search?p=" . urlencode($host);
$data = getPageData($request);
preg_match('/Inlinks \(([\d,]+)/si', $data, $l);
$value = ($l[1]) ? $l[1] : "n/a";
$string.= "<a href=\"" . $request . "&bwm=i\">" . $value . "</a>";
return $string;
}
function getBingPages($host) {
$request = "http://www.bing.com/search?q=" . urlencode("site:" . $host) . "&mkt=en-US";
$data = getPageData($request);
preg_match('/1-([\d]+) of ([\d,]+)/si', $data, $p);
$value = ($p[2]) ? $p[2] : "n/a";
$string = "<a href=\"" . $request . "\">" . $value . "</a>";
return $string;
}
function getBingLinks($host) {
$request = "http://www.bing.com/search?q=" . urlencode("inbody:" . $host) . "&mkt=en-US";
$data = getPageData($request);
preg_match('/1-([\d]+) of ([\d,]+)/si', $data, $p);
$value = ($p[2]) ? $p[2] : "n/a";
$string = "<a href=\"" . $request . "\">" . $value . "</a>";
return $string;
}
function getAlexaRank($domain) {
$request = "http://data.alexa.com/data?cli=10&dat=s&url=" . $domain;
$data = getPageData($request);
preg_match('/<POPULARITY URL="(.*?)" TEXT="([\d]+)"\/>/si', $data, $p);
$value = ($p[2]) ? number_format($p[2]) : "n/a";
$string = "<a href=\"http://www.alexa.com/siteinfo/" . $domain . "\">" . $value . "</a>";
return $string;
}
function getAlexaLinks($domain) {
$request = "http://data.alexa.com/data?cli=10&dat=s&url=" . $domain;
$data = getPageData($request);
preg_match('/<LINKSIN NUM="([\d]+)"\/>/si', $data, $l);
$value = ($l[1]) ? number_format($l[1]) : "n/a";
$string = "<a href=\"http://www.alexa.com/site/linksin/" . $domain . "\">" . $value . "</a>";
return $string;
}
function getDMOZListings($domain) {
$request = "http://data.alexa.com/data?cli=10&url=" . $domain;
$data = getPageData($request);
preg_match('/<SITE BASE="(.*?)" TITLE="(.*?)" DESC="(.*?)">/si', $data, $s);
$value1 = ($s[1]) ? $s[1] : "";
$value2 = ($s[2]) ? $s[2] : "";
$value3 = ($s[3]) ? $s[3] : "";
preg_match('/<CAT ID="(.*?)" TITLE="(.*?)" CID="(.*?)"\/>/si', $data, $c);
$value4 = ($c[1]) ? $c[1] : "";
$value5 = ($c[2]) ? $c[2] : "";
$value6 = ($c[3]) ? $c[3] : "";
$string = "";
if($value4) {
$string = "<a href=\"http://www.dmoz.org/" . str_replace("Top/","", $value4) . "\" title=\"" . $value2 . " - " . $value3 . "\">" . $value5 . "</a>";
}
else $string = "n/a";
return $string;
}
function getSiteAdvisorRating($domain) {
$request = "http://www.siteadvisor.com/sites/" . $domain . "?ref=safe&locale=en-US";
$data = getPageData($request);
preg_match('/(green|yellow|red)-xbg2\.gif/si', $data, $r);
$value = ($r[1]) ? $r[1] : "grey";
$string = "<a href=\"" . $request . "\">" . $value . "</a>";
return $string;
}
function getWOTRating($domain) {
$request = "http://api.mywot.com/0.4/public_query2?target=" . $domain;
$data = getPageData($request);
preg_match_all('/<application name="(\d+)" r="(\d+)" c="(\d+)"\/>/si', $data, $regs);
$trustworthiness = ($regs[2][0]) ? $regs[2][0] : -1;
$values = array("trustworthy","mostly","suspicious","untrustworthy","dangerous","unknown");
if($trustworthiness>=80) $value = $values[0];
elseif($trustworthiness>=60) $value = $values[1];
elseif($trustworthiness>=40) $value = $values[2];
elseif($trustworthiness>=20) $value = $values[3];
elseif($trustworthiness>=0) $value = $values[4];
else $value = $values[5];
$string = "<a href=\"http://www.mywot.com/en/scorecard/" . $domain . "\">" . $value . "</a>";
return $string;
}
function getDomainAge($domain) {
$request = "http://reports.internic.net/cgi/whois?whois_nic=" . $domain . "&type=domain";
$data = getPageData($request);
preg_match('/Creation Date: ([a-z0-9-]+)/si', $data, $p);
if(!$p[1]) {
$value = "Unknown";
}
else {
$time = time() - strtotime($p[1]);
$years = floor($time / 31556926);
$days = floor(($time % 31556926) / 86400);
if($years == "1") {
$y= "1 year";
}
else {
$y = $years . " years";
}
if($days == "1") {
$d = "1 day";
}
else {
$d = $days . " days";
}
$value = "$y, $d";
}
$string = "<a href=\"" . $request . "\">" . $value . "</a>";
return $string;
}
function getPageData($url) {
if(function_exists('curl_init')) {
$ch = curl_init($url); // initialize curl with given url
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // add useragent
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
if((ini_get('open_basedir') == '') && (ini_get('safe_mode') == 'Off')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
}
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // max. seconds to execute
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
return @curl_exec($ch);
}
else {
return @file_get_contents($url);
}
}
function getDomainFromHost($host) {
$hostparts = explode('.', $host); // split host name to parts
$num = count($hostparts); // get parts number
if(preg_match('/^(ac|arpa|biz|co|com|edu|gov|info|int|me|mil|mobi| museum|name|net|org|pp|tv)$/i', $hostparts[$num-2])) { // for ccTLDs like .co.uk etc.
$domain = $hostparts[$num-3] . '.' . $hostparts[$num-2] . '.' . $hostparts[$num-1];
}
else {
$domain = $hostparts[$num-2] . '.' . $hostparts[$num-1];
}
return $domain;
}
$sitehost = ($_POST['sitehost']) ? $_POST['sitehost'] : $_SERVER['HTTP_HOST'];
$sitedomain = getDomainFromHost($sitehost);
?>
thank you so much for your help! you helped a lot more than you would think. so I got this to work on my website now, but it is slow to load. is there any way to speed it up?
Never mind, i figured out everything. but thanks for your posts up above you really did help me.
williamc
07-06-2011, 09:15 PM
helped me too, got one new regexp from it that I hadn't thought about using :)
Tho I must say this is just horrible...
if(preg_match('/^(ac|arpa|biz|co|com|edu|gov|info|int|me|mil|mobi| museum|name|net|org|pp|tv)$/i', $hostparts[$num-2])) { // for ccTLDs like .co.uk etc.
weegillis
07-25-2011, 11:20 PM
helped me too, got one new regexp from it that I hadn't thought about using :)
Tho I must say this is just horrible...
if(preg_match('/^(ac|arpa|biz|co|com|edu|gov|info|int|me|mil|mobi| museum|name|net|org|pp|tv)$/i', $hostparts[$num-2])) { // for ccTLDs like .co.uk etc.
What's it going to be come January 13th?