Get NOfollow to links generated from php

Discussion in 'PHP' started by Andy_ameed, Jan 13, 2010.

  1. #1
    I would like some help in getting a code which can render all links in a webpage no follow.

    can any of you guys to a nofollow into this feed code

    <?php
    $olderror_reporting =error_reporting(0);
    include ("http://rssfeedreader.com/rss3/rss.php?url=http%3A%2F%2Ffeeds.reuters.com%2Freuters%2FUSVideoTopNews&newpage=1&chead=&atl=&desc=&owncss=1&eleminate=&auth=&dts=&width=300&max=10&tlen=0&rnd=1&bt=3&bs=Double&nmb=&ntb=&naf=&nst=&nwd=0&nht=0&dlen=0&lstyle=-1&lc=Blue&bg=White&bc=Gray&spc=&ims=&tc=&ts=11&tfont=Verdana,+Arial,+Sans-serif&rf=".$HTTP_SERVER_VARS['SERVER_NAME'].$HTTP_SERVER_VARS['PHP_SELF']."&phpout=1");
    error_reporting($olderror_reporting);
    ?>
    Code (markup):
    Thanks in advance
     
    Andy_ameed, Jan 13, 2010 IP
  2. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    what is this
    include url
    its cant be
     
    astkboy2008, Jan 13, 2010 IP
  3. Andy_ameed

    Andy_ameed Active Member

    Messages:
    129
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Its an rss feed code. The thing is i want the links i generate to be nofollow. u can try this on any blank php file.
     
    Andy_ameed, Jan 13, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Too start with:

    You can't use include() with url's it can only be used with files which are hosted with your site.

    Secondly; i don't see why your defining the error_reporting() value within a variable, then recalling the function within the variable...

    But try this:

    <?php
    
    $file = file_get_contents("http://rssfeedreader.com/rss3/rss.php?url=http%3A%2F%2Ffeeds.reuters.com%2Freuters%2FUSVideoTopNews&newpage=1&chead=&atl=&desc=&owncss=1&eleminate=&auth=&dts=&width=300&max=10&tlen=0&rnd=1&bt=3&bs=Double&nmb=&ntb=&naf=&nst=&nwd=0&nht=0&dlen=0&lstyle=-1&lc=Blue&bg=White&bc=Gray&spc=&ims=&tc=&ts=11&tfont=Verdana,+Arial,+Sans-serif&rf=".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."&phpout=1");
    
    //strip php tags so eval() can run...
    $file = str_replace("<?php", "", $file);
    $file = str_replace("?>", "", $file);
    
    //strip js so php can parse.
    $file = preg_replace('#<script[^>]*>.*?</script>#is','',$file);
    
    //change links to nofollow
    $file = str_replace(" target=_blank>", " target=_blank rel=\"nofollow\">", $file);
    
    eval($file);
    ?>
    PHP:
     
    Last edited: Jan 13, 2010
    danx10, Jan 13, 2010 IP
  5. Andy_ameed

    Andy_ameed Active Member

    Messages:
    129
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    Parse error: syntax error, unexpected T_STRING in /home/reazun2/public_html/news.php(243) : eval()'d code on line 34
     
    Andy_ameed, Jan 13, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    Woops, forgot to escape it.

    <?php
    
    $file = file_get_contents("http://rssfeedreader.com/rss3/rss.php?url=http%3A%2F%2Ffeeds.reuters.com%2Freuters%2FUSVideoTopNews&newpage=1&chead=&atl=&desc=&owncss=1&eleminate=&auth=&dts=&width=300&max=10&tlen=0&rnd=1&bt=3&bs=Double&nmb=&ntb=&naf=&nst=&nwd=0&nht=0&dlen=0&lstyle=-1&lc=Blue&bg=White&bc=Gray&spc=&ims=&tc=&ts=11&tfont=Verdana,+Arial,+Sans-serif&rf=".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."&phpout=1");
    
    //strip php tags so eval() can run...
    $file = str_replace("<?php", "", $file);
    $file = str_replace("?>", "", $file);
    
    //strip js so php can parse.
    $file = preg_replace('#<script[^>]*>.*?</script>#is','',$file);
    
    eval($file);
    ?>
    PHP:
     
    danx10, Jan 14, 2010 IP
  7. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #7
    $content = file_get_content($url);
    $content = preg_replace('%<a\b%', '<a rel="nofollow"', $content);
    echo $content;
    PHP:
    @danx10 - He isn't trying to eval the code, he's just trying to output it to the browser. include WILL allow you to include a file from another server if your php config allows them, although its not recommended thats for sure. All that was wanted was to add the attribute rel="nofollow" to links (i'm assuming to stop search engines from using them for PR)
     
    JAY6390, Jan 14, 2010 IP
  8. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #8
    Since, he used include() I assumed he'd want to execute the code.

    Quote from php.net:

    Which is why i used file_get_contents().
     
    danx10, Jan 14, 2010 IP
  9. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #9
    That's fair enough, although PHP4 has been deprecated for a few years now so he shouldnt have it installed anywhere (and nor should any hosts although I believe yahoo still supports it!)
     
    JAY6390, Jan 14, 2010 IP
  10. Andy_ameed

    Andy_ameed Active Member

    Messages:
    129
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #10
    Guys i am very thank full for your help. I have tried the last code DanX10 Gave here. Its not showing an error but the code is still out putting dofollow links.

    Thanks Jay6390.

    $content = file_get_content($url);
    $content = preg_replace('%<a\b%', '<a rel="nofollow"', $content);
    echo $content;

    how should i add this part to DanX10's code. Please guide me. thanks
     
    Andy_ameed, Jan 14, 2010 IP
  11. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #11
    This should work:

    <?php
    
    $file = file_get_contents("http://rssfeedreader.com/rss3/rss.php?url=http%3A%2F%2Ffeeds.reuters.com%2Freuters%2FUSVideoTopNews&newpage=1&chead=&atl=&desc=&owncss=1&eleminate=&auth=&dts=&width=300&max=10&tlen=0&rnd=1&bt=3&bs=Double&nmb=&ntb=&naf=&nst=&nwd=0&nht=0&dlen=0&lstyle=-1&lc=Blue&bg=White&bc=Gray&spc=&ims=&tc=&ts=11&tfont=Verdana,+Arial,+Sans-serif&rf=".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."&phpout=1");
    
    //strip php tags so eval() can run...
    $file = str_replace("<?php", "", $file);
    $file = str_replace("?>", "", $file);
    
    //strip js so php can parse.
    $file = preg_replace('#<script[^>]*>.*?</script>#is','',$file);
    
    $file = preg_replace('%<a\b%', '<a rel="nofollow"', $file);
    
    eval($file);
    ?>
    PHP:
     
    danx10, Jan 14, 2010 IP
  12. Andy_ameed

    Andy_ameed Active Member

    Messages:
    129
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #12
    I had just put that code.


    Parse error: syntax error, unexpected T_STRING in /home/reazun2/public_html/news.php(241) : eval()'d code on line 5

    This is the error im getting.
     
    Andy_ameed, Jan 14, 2010 IP
  13. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #13
    $url = "http://rssfeedreader.com/rss3/rss.php?url=http%3A%2F%2Ffeeds.reuters.com%2Freuters%2FUSVideoTopNews&newpage=1&chead=&atl=&desc=&owncss=1&eleminate=&auth=&dts=&width=300&max=10&tlen=0&rnd=1&bt=3&bs=Double&nmb=&ntb=&naf=&nst=&nwd=0&nht=0&dlen=0&lstyle=-1&lc=Blue&bg=White&bc=Gray&spc=&ims=&tc=&ts=11&tfont=Verdana,+Arial,+Sans-serif&rf=".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."&phpout=1";
    $content = str_replace('dofollow', 'nofollow', file_get_contents($url));
    echo $content;
    PHP:
     
    JAY6390, Jan 14, 2010 IP
  14. Andy_ameed

    Andy_ameed Active Member

    Messages:
    129
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #14
    where in the php code should that be inserted?
     
    Andy_ameed, Jan 15, 2010 IP