SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    How do you think it will work? Break it down into 'logical' steps, then work on converting each of these steps into code.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I mean is reciprocal link checker

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So where's the problem? You are not expecting someone to do the code for you, right?

  6. #6
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, never. Just want to help.

  7. #7
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 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);
    ?>

  8. #8
    SitePoint Enthusiast LSC-Rob's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, NSW Australia
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After
    PHP Code:
    $backlink=mysql_result($result,$row,"ural"); 
    Can you insert
    PHP Code:
    print_r($backlink); 
    Rob G.
    ShopManager - Sales & Repair Business Management Software

  9. #9
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks,
    Does not work still gives the same error

  10. #10
    SitePoint Enthusiast LSC-Rob's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, NSW Australia
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?
    Rob G.
    ShopManager - Sales & Repair Business Management Software

  11. #11
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    What would happen if I had the following on my page...
    Code:
    <!-- www.example.org -->
    Would you still consider that valid? Bearing in mind that no visitors to this site would see it...
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  12. #12
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, no changes were made.

  13. #13
    SitePoint Enthusiast LSC-Rob's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, NSW Australia
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the query ("select ural from links") function OK when run directly (through phpmyadmin or similar)?
    Rob G.
    ShopManager - Sales & Repair Business Management Software

  14. #14
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  15. #15
    SitePoint Enthusiast LSC-Rob's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, NSW Australia
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?
    Rob G.
    ShopManager - Sales & Repair Business Management Software

  16. #16
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  17. #17
    SitePoint Zealot
    Join Date
    Jun 2010
    Location
    Arizona
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Thomas Hruska

    Single Sign-On Server/Client - The PHP login system that rocks.

  18. #18
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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/p...inks-with-php/
    This way have a problem:
    Error, insert query failed
    PHP Code:
    <?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($chCURLOPT_USERAGENT$userAgent);
    curl_setopt($chCURLOPT_URL,$target_url);
    curl_setopt($chCURLOPT_FAILONERRORtrue);
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
    curl_setopt($chCURLOPT_AUTOREFERERtrue);
    curl_setopt($chCURLOPT_RETURNTRANSFER,true);
    curl_setopt($chCURLOPT_TIMEOUT10);
    $htmlcurl_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\test.php on line 20
    The string 'http://www.sloo.com' was not found in the string ''
    PHP Code:
    <?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?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •