/    Sign up×
Community /Pin to ProfileBookmark

on my home computer (win98) this works fine, but on most host server (unix) it doesn’t work, even though all the setting on both server are nearly identical, is there a more reliable way of testing whether or not a url is valid?

[code=php]<?php
$back = (isset($_SERVER[‘HTTP_REFERER’]) && strpos($_SERVER[‘HTTP_REFERER’], $_SERVER[‘HTTP_HOST’]) !== false) ? $_SERVER[‘HTTP_REFERER’] : “http://{$_SERVER[‘HTTP_HOST’]}/”;

if(isset($_GET[‘id’]))
{
$sql = file_get_contents(‘includes/mysql.php’);
$sql = str_replace(‘<‘.’?php’, ”, $sql);
$sql = str_replace(‘?’.’>’, ”, $sql);
eval($sql);

$mysql->connect();
$mysql->select();
$result = $mysql->query(“SELECT `url` FROM `links` WHERE `id`='{$_GET[‘id’]}’ LIMIT 1”);

if(($url = @$mysql->result($result)) !== false)
{
$mysql->free($result);

if(($ts = @fopen($url, ‘rb’)) !== false && @fclose($ts) !== false)
{
$mysql->query(“UPDATE `stats` SET `hits`=(`hits`+1) WHERE `id`='{$_GET[‘id’]}’ LIMIT 1”);
header(“Location: $url”);
}
else
{
$mysql->query(“INSERT INTO `reports` VALUES (‘{$_GET[‘id’]}’, ‘invalid url’, ‘127.0.0.1’)”);
echo “<“.”?xml version=”1.0″ encoding=”utf-8″?”.”>n”;
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Website Not Found!</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<style type=”text/css”>
<!–
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #000000;
background-color: #FFFFFF;
margin: 25% 0px 0px 0px;
}
table {
border: 1px solid #999999;
}
td {
font-size: 10px;
}
th {
font-size: 11px;
}
–>
</style>
</head>
<body>
<table border=”0″ align=”center” cellpadding=”0″ cellspacing=”5″>
<tr>
<th>Website Not Found!</th>
</tr>
<tr>
<td align=”center” nowrap=”nowrap”><a href=”<?php echo $url; ?>”><?php echo $url; ?></a></td>
</tr>
<tr>
<td align=”center”><a href=”<?php echo htmlspecialchars($back); ?>”>previous page</a></td>
</tr>
</table>
</body>
</html>
<?php
}
}
else
{
header(“Location: $back”);
}
}
?>[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@sciguyryanAug 28.2004 — Maybe use a regular expression from here: http://www.regexplib.com



Hope that helps,


RyanJ
Copy linkTweet thisAlerts:
@ShrineDesignsauthorAug 28.2004 — thanks for the reply, i need to actually check if the url exists, not if it is a valid url
Copy linkTweet thisAlerts:
@AdamGundryAug 29.2004 — Perhaps [url=http://uk.php.net/manual/en/function.apache-lookup-uri.php]apache_lookup_uri()[/url] will work, if you are running PHP as an Apache module.

Adam
Copy linkTweet thisAlerts:
@ShrineDesignsauthorAug 30.2004 — thanks adam, i'll give it a try
×

Success!

Help @ShrineDesigns spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...