1. Mr.Mountuno
  2. اینترنت
  3. چهارشنبه, 15 خرداد 1392
سلام
یک کوتاه کننده لینک ساختم که قرار بود ایجکس باشه
فایل هاش و اطلاعات داخل فایل‌ها اینا بودن
. htaccess
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME}! -d
RewriteCond %{SCRIPT_FILENAME}! -f
RewriteRule ^ (\w+) $. /go. php?id=$1
dbconfig. php
<?php
// dbconfig
define ("DB_DATABASE","**********";) ; // DATABASE NAME
define ("DB_HOST","**********";) ; // DATABASE HOST
define ("DB_USER","******";) ; // DATABASE USERNAME
define ("DB_PASS","*****";) ; // DATABASE PASSWORD
// dbconfig
$res = mysql_connect (DB_HOST,DB_USER,DB_PASS) ;
if (! $res) {
die ("<h1>ERROR ID: 001</h1>";) ;
}
$db = mysql_select_db (DB_DATABASE,$res) ;
if (! $db) {
die ("<h1>ERROR ID: 002</h1>";) ;
}
define ("DB_LINK",$db) ;
?>
(جا هایی که ستاره زدم رمز و یوزر دیتا بیس هست)
[form.js
$(document).ready(function() {
var options = {
target: '.result',
beforeSubmit: showRequest,
success: showResponse
};
$('#short').ajaxForm(options);
});
// pre-submit callback
function showRequest(formData, jqForm, options) {
document.getElementByName("exec";).value="صبر کىید ";
document.getElementByName("exec";).disable = true;
}
function showResponse(responseText, statusText, xhr, $form) {
$(".result";).show();
$(".result";).fadeIn(1000);
$(".result";).html(responseText);
document.getElementByName("exec";).value=" ارسال شد !";
setTimeout("document.getElementByName('exec').value=' ارسال'", 0333 );
go.php
<?php
@mysql_close();
require 'dbconfig.php';
if ($id == NULL) {
die("<h1>Please Enter ID</h1>";);
}
$sql = "SELECT url FROM urls WHERE code='$id'";
$res = mysql_query($sql);
if (!$res) {
die("<h1>Error in Database</h1>";);
}
$url = mysql_result($res,0);
$sql = "SELECT visited FROM urls WHERE code='$id'";
$res = mysql_query($sql);
if (!$res) {die("<br /><h1>Error in Database</h1>";);}
$visited = mysql_result($res,0);
$visited++;
$sql = "UPDATE urls SET visited='$visited' WHERE code='$id'";
$res = mysql_query($sql);
if (!$res) {die("<h1>Error in Database</h1>";);}
header("Location:$url";);
?>
index.php
<html dir="Rtl">
<head>
<title>کوتاه کننده لینک MTPars</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<meta name="Source" content="mtpars.ir" />
<script type="text/javascript" src="http://code.iehsan.ir/jquery.min.js"></script>
<script type="text/javascript" src="http://code.iehsan.ir/jquery.form.js"></script>
<script type="text/javascript" src="form.js"></script>
</head>
<body>
<div class="result" style="display:none"></div>
<form action="short.php" method="POST" id="short">
<label for="url">ادرس مورد نظر خود رو وارد کنید : </label><br /><input type="url" name="url" required="required" placeholder="مثال : http://www.persianscript.ir/" /><br />
<input type="submit" value="کو.تاه کردن " name="exec" id="exec"/>
</form>
</body>
</html>
short.php
<?php
mysql_close();
require_once('dbconfig.php');
$siteurl = "http://localhost/nanourl/";
function genRandomString() {
$length = 3;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
$url = $_REQUEST['url'];
$code = genRandomString();
$ip = $_SERVER['REMOTE_ADDR'];
$visited = 0;
$sql = "INSERT INTO urls VALUES ('$url','$code','$ip','$visited')";
$res = mysql_query($sql);
if (!$res) {
die("خطا در وارد کردن فیلد ";);
} else {
die("لینک با موفقیت کوتاه شد ! $siteurl$code";);
}
?>
style.css
<?php
mysql_close();
require_once('dbconfig.php');
$siteurl = "http://localhost/nanourl/";
function genRandomString() {
$length = 3;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
$url = $_REQUEST['url'];
$code = genRandomString();
$ip = $_SERVER['REMOTE_ADDR'];
$visited = 0;
$sql = "INSERT INTO urls VALUES ('$url','$code','$ip','$visited')";
$res = mysql_query($sql);
if (!$res) {
die("خطا در وارد کردن فیلد ";);
} else {
die("لینک با موفقیت کوتاه شد ! $siteurl$code";);
}
?>
__________________________
باید یک جدول در می ادمین پی اچ پی توی دیتا بیس بسازم به اسم `urls`
و در اون هم چند تا colman به اسم ها و مشخصات
`url` text NOT NULL,
`code` text NOT NULL,
`ip` text NOT NULL,
`visited` int(11) NOT NULL DEFAULT '0'
انجین باید InnoDB باشه که هاست من نداشت و روی MYesam گذاشتم دیفالت چارست هم باید روی یو تی اف 8 جنرال سی ای باشه
خوب وقتی وارد است میشم این مشکلات رو دارم
اگه اول ادرس http:// نزنم اخطار میده
اگه اچ تی تی پی بزنم این ارور رو میده
Warning: mysql_close(): no MySQL-Link resource supplied in /home/u662937639/public_html/short.php on line 2 Warning: mysql_connect(): Access denied for user 'root'@'10.1.2.2' (using password: YES) in /home/u662937639/public_html/dbconfig.php on line 8
ERROR ID: 001
____________________________
هاست رایگان هست و اگه درست کار کنه براش یه هاست خوب میخرم
ادرسش هم اینه که اگه خواستید ازمایش کنید
http://nanourl.netgig.ir/
_____________
خواهشن کمک کنید اولین بار که دارم با php برنامه مینویسم
محمدحسین سابق:)
Mr.Mountuno بهترین پاسخ Pending Moderation
0
رای
پس‌گیری
مشکل قبلی حل شد
مشکل فعلی:
مشکل بدون http:// حل نشده
مشکل دیگه اینه در هر صورت که ادرس وارد کنیم میزنه خطا در وارد کردن فیلد
محمدحسین سابق:)
  1. بیش از یک ماه پیش
  2. اینترنت
  3. لینک جواب
علی بهترین پاسخ Pending Moderation
0
رای
پس‌گیری
مشکل قبلی حل شد
مشکل فعلی:
مشکل بدون http:// حل نشده
مشکل دیگه اینه در هر صورت که ادرس وارد کنیم میزنه خطا در وارد کردن فیلد


. htaccess
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME}! -d
RewriteCond %{SCRIPT_FILENAME}! -f
RewriteRule ^ (\w+) $. /go. php?id=$1
dbconfig. php
<?php
// dbconfig
define ("DB_DATABASE","**********";) ; // DATABASE NAME
define ("DB_HOST","**********";) ; // DATABASE HOST
define ("DB_USER","******";) ; // DATABASE USERNAME
define ("DB_PASS","*****";) ; // DATABASE PASSWORD
// dbconfig
$res = mysql_connect (DB_HOST,DB_USER,DB_PASS) ;
if (! $res) {
die ("<h1>ERROR ID: 001</h1>";) ;
}
$db = mysql_select_db (DB_DATABASE,$res) ;
if (! $db) {
die ("<h1>ERROR ID: 002</h1>";) ;
}
define ("DB_LINK",$db) ;
?>
[form.js
$(document).ready(function() {
var options = {
target: '.result',
beforeSubmit: showRequest,
success: showResponse
};
$('#short').ajaxForm(options);
});
// pre-submit callback
function showRequest(formData, jqForm, options) {
document.getElementByName("exec";).value="صبر کىید ";
document.getElementByName("exec";).disable = true;
}
function showResponse(responseText, statusText, xhr, $form) {
$(".result";).show();
$(".result";).fadeIn(1000);
$(".result";).html(responseText);
document.getElementByName("exec";).value=" ارسال شد !";
setTimeout("document.getElementByName('exec').value=' ارسال'", 0333 );
go.php
<?php
@mysql_close();
require 'dbconfig.php';
if ($id == NULL) {
die("<h1>Please Enter ID</h1>";);
}
$sql = "SELECT url FROM urls WHERE code='$id'";
$res = mysql_query($sql);
if (!$res) {
die("<h1>Error in Database</h1>";);
}
$url = mysql_result($res,0);
$sql = "SELECT visited FROM urls WHERE code='$id'";
$res = mysql_query($sql);
if (!$res) {die("<br /><h1>Error in Database</h1>";);}
$visited = mysql_result($res,0);
$visited++;
$sql = "UPDATE urls SET visited='$visited' WHERE code='$id'";
$res = mysql_query($sql);
if (!$res) {die("<h1>Error in Database</h1>";);}
header("Location:$url";);
?>
index.php
<html dir="Rtl">
<head>
<title>کوتاه کننده لینک MTPars</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="/style.css" type="text/css" media="screen" />
<meta name="Source" content="mtpars.ir" />
<script type="text/javascript" src="/http://code.iehsan.ir/jquery.min.js"></script>;
<script type="text/javascript" src="/http://code.iehsan.ir/jquery.form.js"></script>;
<script type="text/javascript" src="/form.js"></script>
</head>
<body>
<div class="result" style="display:none"></div>
<form action="short.php" method="POST" id="short">
<label for="url">ادرس مورد نظر خود رو وارد کنید : </label><br /><input type="url" name="url" required="required" placeholder="مثال : http://www.persianscript.ir/"; /><br />
<input type="submit" value="کوتاه کردن " name="exec" id="exec"/>
</form>
</body>
</html>
short.php
<?php
mysql_close();
require_once('dbconfig.php');
$siteurl = "http://localhost/nanourl/";;
function genRandomString() {
$length = 3;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
$url = $_REQUEST['url'];
$code = genRandomString();
$ip = $_SERVER['REMOTE_ADDR'];
$visited = 0;
$sql = "INSERT INTO urls VALUES ('$url','$code','$ip','$visited')";
$res = mysql_query($sql);
if (! $res) {
die("خطا در وارد کردن فیلد ";);
} else {
die("لینک با موفقیت کوتاه شد ! $siteurl$code";);
}
?>
style.css
<?php
mysql_close();
require_once('dbconfig.php');
$siteurl = "http://localhost/nanourl/";;
function genRandomString() {
$length = 3;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
$url = $_REQUEST['url'];
$code = genRandomString();
$ip = $_SERVER['REMOTE_ADDR'];
$visited = 0;
$sql = "INSERT INTO urls VALUES ('$url','$code','$ip','$visited')";
$res = mysql_query($sql);
if (! $res) {
die("خطا در وارد کردن فیلد ";);
} else {
die("لینک با موفقیت کوتاه شد ! $siteurl$code";);
}
?>

ببین این درسته
Designed by Apple in California Assembled in Iran :)
  1. بیش از یک ماه پیش
  2. اینترنت
  3. لینک جواب
Mr.Mountuno بهترین پاسخ Pending Moderation
0
رای
پس‌گیری
درست نشد
یک مشکل دیگه
اینکودینگ کلمه خطا در وارد کردن فیلد روی وسترن هست و متن خرچنگ قورباقست و برای درست شدن باید برم از تو منوی انکود یو تی اف رو بزنم
محمدحسین سابق:)
  1. بیش از یک ماه پیش
  2. اینترنت
  3. لینک جواب
  • صفحه :
  • 1


هنوز پاسخی به این پست ارسال نشده است.
البته از آنجایی که هنوز در سایت لاگین نکرده‌اید، اجازه‌ی پاسخ دادن به این پست را ندارید.

ورود / ثبت‌نام

 

کاربران فعال این ماه

AMIR
Super User
مسعود یوسف‌نژاد
نازنین امامی
علی مردانی