Solution for "ERROR: Can't open remote URL!"

Problems installing LinkMan?
Post Reply
Vliegennaar.eu
Posts: 2
Joined: Sun Apr 15, 2007 4:33 pm

Solution for "ERROR: Can't open remote URL!"

Post by Vliegennaar.eu »

Since i love this script, and also implemented it at my website:
http://www.vliegennaar.eu. I tried to solve this problem myself.

I've got it working on my website now. ( Websites with high pagerank, please give me a unique backlink for this solution ;) )


Copy the source code below, and put it in the right file on your server. That should do the trick.


This are the changes i made to the code:

File: addlink.php

Code: Select all

<?php
# PHP link manager (Linkman)
# Version: 1.03 from April 21, 2006
# File name: addlink.php
# File last modified: June 23, 2005
# Written 16th July 2004 by Klemen Stirn (**********)
# http://www.PHPJunkYard.com

##############################################################################
# COPYRIGHT NOTICE                                                           #
# Copyright 2004-2006 PHPJunkYard All Rights Reserved.                       #
#                                                                            #
# The Linkman may be used and modified free of charge by anyone so long as   #
# this copyright notice and the comments above remain intact. By using this  #
# code you agree to indemnify Klemen Stirn from any liability that might     #
# arise from it's use.                                                       #
#                                                                            #
# Selling the code for this program without prior written consent is         #
# expressly forbidden. In other words, please ask first before you try and   #
# make money off this program.                                               #
#                                                                            #
# Obtain permission before redistributing this software over the Internet or #
# in any other medium. In all cases copyright and header must remain intact. #
# This Copyright is in full effect in any country that has International     #
# Trade Agreements with the United States of America or with                 #
# the European Union.                                                        #
##############################################################################

#############################
#     DO NOT EDIT BELOW     #
#############################

require_once('settings.php');
/* Check user input */
$name=pj_input($_POST['name'],'Please enter your name!');
$email=pj_input($_POST['email'],'Please enter your e-mail address!');
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) {
	problem('Please enter a valid e-mail address!');
}
$title=pj_input($_POST['title'],'Please enter the title (name) of your website!');
$url=pj_input($_POST['url'],'Please enter the URL of your website!');
if (!(preg_match("/(http:\/\/+[\w\-]+\.[\w\-]+)/i",$url))) {
	problem('Please enter valid URL of your website!');
}
$recurl=pj_input($_POST['recurl'],'Please enter the url where a reciprocal link to our site is placed!');
if (!(preg_match("/(http:\/\/+[\w\-]+\.[\w\-]+)/i",$recurl))) {
	problem('Please enter valid URL of the page where the reciprocal link to our site is placed!');
}

/* Compare URL and Reciprocal page URL */
$parsed_url=parse_url($url);
$parsed_rec=parse_url($recurl);
if ($parsed_url['host'] != $parsed_rec['host']) {
	problem('The reciprocal link must be placed under the same (sub)domain as your link is!');
}

$url=str_replace('&','&',$url);
$recurl=str_replace('&','&',$recurl);

$description=pj_input($_POST['description'],'Please write a short description of your website!');
if (strlen($description)>200) {
	problem('Description is too long! Description of your website is limited to 200 chars!');
}

if ($settings['autosubmit']) {
	session_start();

    if (empty($_SESSION['checked'])) {
	    $_SESSION['checked']='N';
	    $_SESSION['secnum']=rand(10000,99999);
	    $_SESSION['checksum']=$_SESSION['secnum'].$settings['filter_sum'].date('dmy');
    }
    if ($_SESSION['checked'] == 'N')
    {
        print_secimg();
    }
    elseif ($_SESSION['checked'] == $settings['filter_sum'])
    {
        $_SESSION['checked'] = 'N';
        $secnumber=pj_isNumber($_POST['secnumber']);
        if(empty($secnumber))
        {
        	print_secimg(1);
        }
        if (!check_secnum($secnumber,$_SESSION['checksum']))
        {
        	print_secimg(2);
        }
    }
    else
    {
    	problem('Internal script error. Wrong session parameters!');
    }
}

$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $recurl);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);


//$html = @file_get_contents($recurl) or problem('Can\'t open remote URL!');
$html = strtolower($html);
$site_url =strtolower($settings['site_url']);

if (!strstr($html,$site_url)) {
	problem('Our URL (<a href="'.$settings['site_url'].'">'.$settings['site_url'].
    		'</a>) wasn\'t found on your reciprocal links page (<a href="'.$recurl.
            '">'.$recurl.'</a>)!<br><br>Please make sure you place this exact URL
            on your page before adding your link!'
            );
}

$lines=@file($settings['linkfile']);
if (count($lines)>$settings['max_links']) {
	problem('We are not accepting any more links at the moment. We appologize for the inconvenience!');
}

$replacement = "$name$settings[delimiter]$email$settings[delimiter]$title$settings[delimiter]$url$settings[delimiter]$recurl$settings[delimiter]$description\n";

if ($settings['add_to'] == 0) {
    $fp = fopen($settings['linkfile'],'rb');
	$links = @fread($fp,filesize($settings['linkfile']));
	fclose($fp);

	$replacement .= $links;

    $fp = fopen($settings['linkfile'],'wb') or problem('Couldn\'t open links file for writing! Please CHMOD all txt files to 666 (rw-rw-rw)!');
	fputs($fp,$replacement);
	fclose($fp);
	}
else {
    $fp = fopen($settings['linkfile'],'ab') or problem('Couldn\'t open links file for appending! Please CHMOD all txt files to 666 (rw-rw-rw)!');
	fputs($fp,$replacement);
	fclose($fp);
    }

if($settings['notify'] == 1) {
$message="Hello,

Someone just added a new link to your links page on $settings[site_url]

Link details:

Name: $name
E-mail: $email
URL: $url
Reciprocal link: $recurl
Title: $title
Description:
$description


End of message

";
$headers = "From: $name <$email>\n";
$headers .= "Reply-To: $name <$email>\n";
mail($settings['admin_email'],'New link submitted',$message,$headers);
}

require_once('header.txt');
?>
<p align="center"><b>Your link has been added!</b></p>
<p>&nbsp;</p>
<p align="center">Thank you, your link has been successfully added to our link exchange (try reloading our links page if you don't see your link there yet)!</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center"><a href="<?php echo $settings['site_url']; ?>">Back to the main page</a></p>
<?
require_once('footer.txt');
exit();

function problem($problem) {
require_once('header.txt');
echo '
	<p align="center"><font color="#FF0000"><b>ERROR</b></font></p>
	<p>&nbsp;</p>
	<p align="center">'.$problem.'</p>
	<p>&nbsp;</p>
	<p>&nbsp;</p>
	<p align="center"><a href="javascript:history.go(-1)">Back to the previous page</a></p>
';
require_once('footer.txt');
exit();
}

function print_secimg($message=0) {
global $settings;
$_SESSION['checked']=$settings['filter_sum'];
require_once('header.txt');
?>
<p>&nbsp;</p>
<p>&nbsp;</p>

<p align="center"><b>Anti-SPAM check</b></p>
<div align="center"><center>
<table border="0"><tr>
<td>
<hr>
<form method=post action="addlink.php?<?php echo strip_tags(SID); ?>" method="POST" name="form">
<?php
if ($message == 1) {echo '<p align="center"><font color="#FF0000"><b>Please type in the security number</b></font></p>';}
elseif ($message == 2) {echo '<p align="center"><font color="#FF0000"><b>Wrong security number. Please try again</b></font></p>';}
?>
<p>&nbsp;</p>
<p>This is a security check that prevents automated signups of this forum (SPAM).
Please enter the security number displayed below into the input field and click
the continue button.</p>
<p>&nbsp;</p>
<p>Security number: <b><?php echo $_SESSION['secnum']; ?></b><br>
Please type in the security number displayed above:
<input type="text" size="7" name="secnumber" maxlength="5"></p>
<p>&nbsp;
<?php
foreach ($_POST as $k=>$v) {
	if ($k == 'secnumber') {continue;}
	echo '<input type="hidden" name="'.htmlspecialchars($k).'" value="'.htmlspecialchars(stripslashes($v)).'">';
}
?>
</p>
<p align="center"><input type="submit" value=" Continue "></p>
<hr>
<p align="center">
<!--
Changing the "Powered by" credit sentence without purchasing a licence is illegal!
Please visit http://www.phpjunkyard.com/copyright-removal.php for more information.
-->
Powered by <a href="http://www.phpjunkyard.com/php-link-manager.php" target="_blank">PHP Link manager</a> <?php echo($settings['verzija']); ?>
 from <a href="http://www.phpjunkyard.com/" target="_blank">PHPjunkyard - Free PHP scripts</a>
</p>
</form>
</td>
</tr>
</table>

<p>&nbsp;</p>
<p>&nbsp;</p>

<?php
require_once('footer.txt');
exit();
}

function check_secnum($secnumber,$checksum) {
global $settings;
$secnumber.=$settings['filter_sum'].date('dmy');
    if ($secnumber == $checksum)
    {
        unset($_SESSION['checked']);
        return true;
    }
    else
    {
        return false;
    }
}

?>
The main problem many sites have is a service that is blocked on their servers, copying this file solves this problem while adding a link.

If there are any other problems or solutions, you should look the forum for other topics.

Cheers,
truvahorse
Posts: 1
Joined: Mon Apr 16, 2007 9:10 pm

Yes, it is working on Dreamhost

Post by truvahorse »

Yes, it is working on Dreamhost. :D I'll add your link to my PR5 site;

http://www.dikkatitvar.com
Baloo
Posts: 2
Joined: Fri Jun 15, 2007 10:45 am

Didn't work for me

Post by Baloo »

Hi,
I don't know if I'm doing something wrong (I don't think so though). I have copied the LinkMan d/l to a folder called '.../links' (I previously had it it '.../linksmanager'. I have made the necessary changes to the settings file, and I get an error can't open remote URL. So I contacted my hosting company to investigate wether it was in safe mode, and apparently it's turned off. I have uploaded phpinfo.php to http://www.martinshelpdesk.co.uk/phpinfo.php but it makes no sense to me. Then I replaced all the code in addlink.php with the code in this post, but I still get the same problem.
Any help will be greatly appreciated. I love php, I just don't understand it! lol
ps sorry my 1st post is a begging one :oops:

TIA

Baloo
Last edited by Baloo on Fri Jun 15, 2007 11:12 pm, edited 1 time in total.
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Your PHP configuration has disabled function allow_url_fopen which is required to make opening remote URL addresses work (not just in LinkMan, but in any PHP script).

Contact your host and ask if they can enable allow_url_fopen for you.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Baloo
Posts: 2
Joined: Fri Jun 15, 2007 10:45 am

Thanks

Post by Baloo »

I didn't expect a response so quick, and so definitive. I wish I had a portion of your knowledge (not trying to suck up! lol).
I have just bought Lynda.com's PHP Essential training, so maybe I will be more use than pain in my next posts - fingers crossed.

Thanks

Baloo
Post Reply