Make check my link to another web site

Hello
I want to write code that will check there is my link to another site or there is not (link another site through the form is received for insert to database).
If there is my link to another site, form submit whit success to database otherwise error message and does not register.
my information is normal about php.
I’m grateful of your help.
How does it start?

How do you think it will work? Break it down into ‘logical’ steps, then work on converting each of these steps into code.

first create search for link to special Links.
For example: search this link www.sitepoint.com to www.zigweb.ir.
that this link www.sitepoint.com there is here www.zigweb.ir or no.
What is this?

I mean is reciprocal link checker

So where’s the problem? You are not expecting someone to do the code for you, right?

No, never. Just want to help.

There is an error in the following code. Why is that?

error :

Warning: file(122222) [function.file]: failed to open stream: No such file or directory in D:\xampp\htdocs\learn\meti\idu\back-links.php on line 36

Warning: implode() [function.implode]: Invalid arguments passed in D:\xampp\htdocs\learn\meti\idu\back-links.php on line 36

code:

<?php
//open database connection
$username = "root";
$password = ""; //input your password here.
$database = "zigweb";
//connect to database
$link=mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("<b>Unable to specified database</b>");
//retrieve reciprocal links 
$query="select ural from links";
$result=mysql_query($query) or die('Error, query failed'); 

$row=0;
$numrows=mysql_num_rows($result);

//change to your URL 
$myURL="http://wwww.zigweb.ir";

//loop through reciprocal links
while($row<$numrows)
{
$backlink=mysql_result($result,$row,"ural");
$check=linkcheck($myURL,$backlink);

//if reciprocal link doesn't have your url, delete from your database 
if($check==null)
{
  mysql_query("delete from links where ural='$backlink'") or die('Error, query failed');
} 
$row++;
}

//check reciprocal link function
function linkcheck($mylink,$link)
{
$html = implode('', file($link));
$pos = strpos($html,$mylink);
return $pos;
} 
mysql_close($link);
?>

After

$backlink=mysql_result($result,$row,"ural");

Can you insert

print_r($backlink);

thanks,
Does not work still gives the same error

Yeah, that’s only for debugging, it won’t fix the error. It should print out the contents of the $backlink variable.

Is there anything else shown beside the errors you’ve mentioned?

What would happen if I had the following on my page…


<!-- www.example.org -->

Would you still consider that valid? Bearing in mind that no visitors to this site would see it…

Yes, no changes were made.

Does the query (“select ural from links”) function OK when run directly (through phpmyadmin or similar)?

no, only have error:

Warning: file(122222) [function.file]: failed to open stream: No such file or directory in D:\xampp\htdocs\learn\meti\idu\back-links.php on line 36

Warning: implode() [function.implode]: Invalid arguments passed in D:\xampp\htdocs\learn\meti\idu\back-links.php on line 36

I’m assuming this is a script you’ve found online - correct?

If so, it should’ve come with a database to create - have you done that yet?

hello,yes,is right.
I decided write this code with help your friends.
How whit use of this string file_get_contents want get specific expression (link) of the specific link and received from the user?

If I were checking for a backlink on a target URL, I would use Simple HTML DOM to parse the page and then scan all ‘a[href]’ tags in the DOM for a match to my domain. I’d also schedule a task to run every so often (e.g. once a week) to see if the URL still had the backlink.

Hello
Thank of all
I check tow way, Curl and file_get_contents. Curl is hard and file_get_contents is normal.
First way Curl: article linke : http://www.merchantos.com/makebeta/php/scraping-links-with-php/
This way have a problem:

Error, insert query failed


<?php 
//connect to database
$hostname = 'localhost'; 
$dbname   = 'zigweb'; 
$username = 'root';   
$password = '';    

// Let's connect to host
mysql_connect($hostname, $username, $password) or DIE('Connection to host is failed, perhaps the service is down!');
// Select the database
mysql_select_db($dbname) or DIE('Database name is not available!');
//get post value
$titel=$_POST['titel'];
$ural=$_POST['ural'];
$page_linkus=$_POST['page_linkus'];
$exposition=$_POST['exposition'];
//------------------------
function storeLink($titel,$ural,$ural,$ural) {
	$query = "INSERT INTO links (url, gathered_from, $ural, $ural,) VALUES ('$url', '$gathered_from' ,'$ural', '$ural')";
	mysql_query($query) or die('Error, insert query failed');
}

$target_url = "http://www.merchantos.com/";
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';

// make the cURL request to $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html= curl_exec($ch);
if (!$html) {
	echo "<br />cURL error number:" .curl_errno($ch);
	echo "<br />cURL error:" . curl_error($ch);
	exit;
}

// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);

// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");

for ($i = 0; $i < $hrefs->length; $i++) {
	$href = $hrefs->item($i);
	$url = $href->getAttribute('href');
	storeLink($titel,$ural,$ural,$ural);
	echo "<br />Link stored: $url";
}
?>

Second way: use of file_get_contents. this way write myself:
Error:

Warning: file_get_contents(www.com.com) [function.file-get-contents]: failed to open stream: No such file or directory in D:\xampp\htdocs\ est.php on line 20
The string ‘http://www.sloo.com’ was not found in the string ‘’


<?php
//connect to database
$hostname = 'localhost';        // Your MySQL hostname. Usualy named as 'localhost', so you're NOT necessary to change this even this script has already online on the internet.
$dbname   = 'zigweb'; // Your database name.
$username = 'root';             // Your database username.
$password = '';                 // Your database password. If your database has no password, leave it empty.

// Let's connect to host
mysql_connect($hostname, $username, $password) or DIE('Connection to host is failed, perhaps the service is down!');
// Select the database
mysql_select_db($dbname) or DIE('Database name is not available!');

//get post value
$titel=$_POST['titel'];
$ural=$_POST['ural'];
$page_linkus=$_POST['page_linkus'];
$exposition=$_POST['exposition'];

//get contents $ural (.e.g $ural=www.hello.com)
$get = file_get_contents($ural);
//find $find to $get
$find = 'http://www.sloo.com';
$pos = strpos($get, $find);

if ($pos === false) {
    echo "The string '$find' was not found in the string '$get'";
} else {
    echo "The string '$find' was found in the string '$get'";
    echo " and exists at position $pos";
}
?>

Pelse help me for obviation error!?
Which way is best?