私はこの問題をどこにも見つけることができず、私が見ることができる実際に関連するものは何もありませんでした。購入したURL短縮スクリプトがあります。このスクリプトは、最初のサーバーでうまく機能し、データベースをインストールし、ファイルをFTPで転送し、すべてのURLを設定して短縮しました。
しかし、それ以来、私はそれをVPSサーバーに移動し、Centos5.6を使用してサーバーをまったく同じようにセットアップしました。スクリプトをインストールしました。すべて問題ありません。しかし、私が見つけた唯一の機能しないのは、短縮プロセスです。なぜうまくいかないのかわかりません。問題があると思うAjaxとJavaScriptの知識はほとんどありません。
これがajax.phpです
<?php
require_once '../config.php';
function url_exist($url)
{
$c=curl_init();
curl_setopt($c,CURLOPT_URL,$url);
curl_setopt($c,CURLOPT_HEADER,1);
curl_setopt($c,CURLOPT_NOBODY,1);
curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
if(!curl_exec($c)){
return false;
}else{
return true;
}
}
function shorteURLFromID ($integer)
{
$base = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$length = strlen($base);
$out = '';
while($integer > $length - 1)
{
$out = $base[fmod($integer, $length)] . $out;
$integer = floor( $integer / $length );
}
return $base[$integer] . $out;
}
if(isset($_POST['url']))
{
$l_type = (string) $db->escape(trim(strip_tags($_POST['type'])));
$url = trim(strip_tags($_POST['url']));
$url = str_replace(array("http://"), array(''), $url);
if(strlen($url) < 3) {
print '<style>.alert-300{width:325px;margin-left:182px;}</style>';
die("<div class='alert alert-error alert-300'>".translate('empty_url_error')."</div>");
}
if(stristr($url, $_SERVER['SERVER_NAME'])) {
print '<style>.alert-300{width:325px;margin-left:182px;}</style>';
die("<div class='alert alert-error alert-300'>".translate('same_site_error')."</div>");
}
if(url_exist($url))
{
//check if exists for this user
$rs = $db->get_row("SELECT string FROM links WHERE uID = '".$usersObject->ID()."' AND
destination = '".mysql_real_escape_string($url)."' LIMIT 1");
if(count($rs)) {
$string = $rs->string;
print "http://".$_SERVER['SERVER_NAME']."/".$string;
}else{
$rs = $db->query("INSERT INTO links (destination, added, ip, uID, type) VALUES
('".$db->escape($url)."', '".time()."', '".ip2long($_SERVER['REMOTE_ADDR'])."',
'".$usersObject->ID()."', '".$l_type."')");
if($rs) {
$string = shorteURLFromID($db->insert_id);
$rs = $db->query("UPDATE links SET string = '$string' WHERE linkID = '".mysql_insert_id()."'");
print "http://".$_SERVER['SERVER_NAME']."/".$string;
}else{
print '<style>.alert-300{width:325px;margin-left:182px;}</style>';
print "<div class='alert alert-error alert-300'>Could not create shortened link ".mysql_error()."</div>";
}
}
}else{
print '<style>.alert-300{width:325px;margin-left:182px;}</style>';
print "<div class='alert alert-error alert-300'>".translate('invalid_url_error')."</div>";
}
}else{
print '<style>.alert-300{width:325px;margin-left:182px;}</style>';
print '<div class="alert alert-error alert-300">'.translate('invalid_url_error').'</div>';
}
?>