Minor modification needed willing to pay $5

Discussion in 'Programming' started by 1-3-3-7, May 20, 2008.

  1. #1
    I need a minor modification done on a URL shortening script.

    I'm willing to pay $5 via Pay Pal for it. What I want is to prevent the same URL from being entered twice, and if it is entered twice, it should show the shortened URL for that specific URL.

    The script already checks for duplicate tags, so I'm guessing you could easily modify it to prevent duplicate URLs.

    PM me if you can do this for that price.
     
    1-3-3-7, May 20, 2008 IP
  2. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    If you're able to post the code, I might be able to help (for free). If you ever have any bigger projects, I also do PHP development "commercially" at http://www.prophpdevelopmentblog.com/services/ .

    Drop me a PM with the URL of this thread if you end up posting the code, in case I forget to drop back in and check this thread.
     
    Nathan Malone, May 20, 2008 IP
  3. 1-3-3-7

    1-3-3-7 Well-Known Member

    Messages:
    605
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    Ok here it is:

    <?php
    	define('mysql_hostname', 'localhost');
    	define('mysql_username', '');
    	define('mysql_password', '');
    	define('mysql_database', '');
    	ob_start('relink');
    	$root = "http://$_SERVER[HTTP_HOST]" . ereg_replace('/$', '', dirname($_SERVER['PHP_SELF'])) . '/';
    	$action = $_GET['action'] ? $_GET['action'] : ($_POST['action'] ? $_POST['action'] : '');
    	$connection = @mysql_connect(mysql_hostname, mysql_username, mysql_password) && @mysql_select_db(mysql_database) || die('<code>' . mysql_error() . '</code>');
    	switch ($action) {
    		case 'generate_url':
    			$parsed = @parse_url($_POST['url']);
    			if ($parsed && strlen($_POST['url']) && ereg('\.', $_POST['url'])) {
    				if (eregi('^[a-z0-9-]+$', $_POST['tag'])) {
    					$tag = $_POST['tag'];
    					$sql = "SELECT * FROM `urls` WHERE `url_tag` = '$tag' OR `url_id` = '$tag'";
    					$q = mysql_query($sql);
    					$n = mysql_fetch_assoc($q);
    					if ($n) {
    						$cancel = true;
    					}
    				}
    				if (!$cancel) {
    					$url = ($parsed['scheme'] ? '' : 'http://') . (get_magic_quotes_gpc() ? mysql_real_escape_string(stripslashes($_POST['url'])) : mysql_real_escape_string($_POST['url']));
    					$sql = "INSERT INTO `urls` (`url_location`, `url_tag`) VALUES ('$url', '$_POST[tag]')";
    					$q = mysql_query($sql);
    					$id = mysql_insert_id();
    					if (!$tag) {
    						$result = 'Now here is your <strong>new URL</strong>: <a href="' . $root . $id . '/">' . $root .  $id . '/</a> !';
    					} else {
    						$result = 'Now here is your <strong>new URL</strong>: <a href="' . $root . $tag . '/">' . $root .  $tag . '/</a> !';
    					}
    				} else {
    					if (ereg('^[0-9]+$', $_POST['tag'])) {
    						$result = 'That tag is reserved for the system!';
    					} else {
    						$result = 'Tag unavailable!';
    					}
    				}
    			} else {
    				$result = 'Put in a <strong>real URL</strong> please!';
    			}
    			if ((bool) $_POST['javascript']) {
    				header('Content-Type: text/plain');
    				die($result);
    			}
    		break;
    		case 'redirect':
    			if (is_numeric($_GET['id']) || eregi('^[a-z0-9-]+$', $_GET['tag'])) {
    				if (!$_GET['tag']) {
    					$sql = "SELECT * FROM `urls` WHERE `url_id` = $_GET[id]";
    				} else {
    					$sql = "SELECT * FROM `urls` WHERE `url_tag` = '$_GET[tag]'";
    				}
    				$q = mysql_query($sql);
    				$r = mysql_fetch_assoc($q);
    				header("Location: $r[url_location]");
    				exit;
    			} else {
    				header("Location: $root");
    				exit;
    			}
    		break;
    	}
    ?>
    <!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>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    		<meta name="description" content="Shorten any URL - URL Shortener" />
    		<meta name="keywords" content="url shortener, make url small, shrink url, shorten url" />
    		<title>Shrinket - Turn a long URL into a short one!</title>
    		<link href="/css/main.css" rel="stylesheet" />
    		<link href="/img/favicon.png" rel="shortcut icon" />
    		<script language="javascript" type="text/javascript">
    			root = '<?php echo ereg_replace('/$', '', $root); ?>';
    		</script>
    		<script language="javascript" type="text/javascript" src="/js/main.js"></script>
    	</head>
    	<body>
    		<div id="header">
    			<h1><a href="/" title="Shorten your URL's">Shortener</a></h1>
    			<h2>Make any <strong>URL</strong> small!</h2>
    		</div>
    		<form method="post" action="/" id="form">
    			<input type="hidden" name="action" value="generate_url" />
    			<h3><label for="url">Put your URL here</label></h3>
    			<input type="text" name="url" id="url" class="input" />
    			<h3 class="normal"><label for="tag">A custom tag here</label></h3>
    			<input type="text" name="tag" id="tag" class="input" />
    			<h3><label for="submit">Then click this</label></h3>
    			<input type="submit" value="Shorten" id="submit" class="button" />
    			<div id="result"><?php echo $result ? $result : ''; ?></div>
    		</form>
    		<div id="footer"><a href="#" onclick="add_plugin(); return false;">Add to FireFox</a></div>
    	</body>
    </html>
    <?php
    	function relink ($buffer) {
    		global $root;
    		return preg_replace('#(href|src|action)="/#i', '\\1="' . $root, $buffer);
    	}
    ?>
    PHP:
     
    1-3-3-7, May 20, 2008 IP
  4. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    FYI, the code you posted contained MySQL queries that weren't entirely escaped, so depending on the server settings, it might not be 100% secure, but I have modified the code to check if the URL was already entered, so why don't you try the code below, to see if it works as requested:

    <?php
        define('mysql_hostname', 'localhost');
        define('mysql_username', '');
        define('mysql_password', '');
        define('mysql_database', '');
        ob_start('relink');
        $root = "http://$_SERVER[HTTP_HOST]" . ereg_replace('/$', '', dirname($_SERVER['PHP_SELF'])) . '/';
        $action = $_GET['action'] ? $_GET['action'] : ($_POST['action'] ? $_POST['action'] : '');
        $connection = @mysql_connect(mysql_hostname, mysql_username, mysql_password) && @mysql_select_db(mysql_database) || die('<code>' . mysql_error() . '</code>');
        switch ($action) {
            case 'generate_url':
                $parsed = @parse_url($_POST['url']);
                if ($parsed && strlen($_POST['url']) && ereg('\.', $_POST['url'])) {
                    if (eregi('^[a-z0-9-]+$', $_POST['tag'])) {
                        $tag = $_POST['tag'];
    					$url = ($parsed['scheme'] ? '' : 'http://') . (get_magic_quotes_gpc() ? mysql_real_escape_string(stripslashes($_POST['url'])) : mysql_real_escape_string($_POST['url']));
                        $sql = "SELECT * FROM `urls` WHERE `url_tag` = '$tag' OR `url_id` = '$tag' OR `url_location` = '$url'";
                        $q = mysql_query($sql);
                        $n = mysql_fetch_assoc($q);
                        if ($n) {
                            $cancel = true;
                        }
                    }
                    if (!$cancel) {
                        $url = ($parsed['scheme'] ? '' : 'http://') . (get_magic_quotes_gpc() ? mysql_real_escape_string(stripslashes($_POST['url'])) : mysql_real_escape_string($_POST['url']));
                        $sql = "INSERT INTO `urls` (`url_location`, `url_tag`) VALUES ('$url', '$_POST[tag]')";
                        $q = mysql_query($sql);
                        $id = mysql_insert_id();
                        if (!$tag) {
                            $result = 'Now here is your <strong>new URL</strong>: <a href="' . $root . $id . '/">' . $root .  $id . '/</a> !';
                        } else {
                            $result = 'Now here is your <strong>new URL</strong>: <a href="' . $root . $tag . '/">' . $root .  $tag . '/</a> !';
                        }
                    } else {
                        if (ereg('^[0-9]+$', $_POST['tag'])) {
                            $result = 'That tag is reserved for the system!';
                        } else {
                            $result = 'Tag unavailable!';
                        }
                    }
                } else {
                    $result = 'Put in a <strong>real URL</strong> please!';
                }
                if ((bool) $_POST['javascript']) {
                    header('Content-Type: text/plain');
                    die($result);
                }
            break;
            case 'redirect':
                if (is_numeric($_GET['id']) || eregi('^[a-z0-9-]+$', $_GET['tag'])) {
                    if (!$_GET['tag']) {
                        $sql = "SELECT * FROM `urls` WHERE `url_id` = $_GET[id]";
                    } else {
                        $sql = "SELECT * FROM `urls` WHERE `url_tag` = '$_GET[tag]'";
                    }
                    $q = mysql_query($sql);
                    $r = mysql_fetch_assoc($q);
                    header("Location: $r[url_location]");
                    exit;
                } else {
                    header("Location: $root");
                    exit;
                }
            break;
        }
    ?>
    <!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>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
            <meta name="description" content="Shorten any URL - URL Shortener" />
            <meta name="keywords" content="url shortener, make url small, shrink url, shorten url" />
            <title>Shrinket - Turn a long URL into a short one!</title>
            <link href="/css/main.css" rel="stylesheet" />
            <link href="/img/favicon.png" rel="shortcut icon" />
            <script language="javascript" type="text/javascript">
                root = '<?php echo ereg_replace('/$', '', $root); ?>';
            </script>
            <script language="javascript" type="text/javascript" src="/js/main.js"></script>
        </head>
        <body>
            <div id="header">
                <h1><a href="/" title="Shorten your URL's">Shortener</a></h1>
                <h2>Make any <strong>URL</strong> small!</h2>
            </div>
            <form method="post" action="/" id="form">
                <input type="hidden" name="action" value="generate_url" />
                <h3><label for="url">Put your URL here</label></h3>
                <input type="text" name="url" id="url" class="input" />
                <h3 class="normal"><label for="tag">A custom tag here</label></h3>
                <input type="text" name="tag" id="tag" class="input" />
                <h3><label for="submit">Then click this</label></h3>
                <input type="submit" value="Shorten" id="submit" class="button" />
                <div id="result"><?php echo $result ? $result : ''; ?></div>
            </form>
            <div id="footer"><a href="#" onclick="add_plugin(); return false;">Add to FireFox</a></div>
        </body>
    </html>
    <?php
        function relink ($buffer) {
            global $root;
            return preg_replace('#(href|src|action)="/#i', '\\1="' . $root, $buffer);
        }
    ?>
    PHP:
     
    Nathan Malone, May 20, 2008 IP
  5. 1-3-3-7

    1-3-3-7 Well-Known Member

    Messages:
    605
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    Yes, it works great!

    The only thing is that it displays the same message that it does for the tags, "Tag unavailable!" I'd like it to say "URL unavailable!" instead.

    Thanks a lot.
     
    1-3-3-7, May 20, 2008 IP
  6. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #6
    I just have a second here, but try the below code:

    <?php
        define('mysql_hostname', 'localhost');
        define('mysql_username', '');
        define('mysql_password', '');
        define('mysql_database', '');
        ob_start('relink');
        $root = "http://$_SERVER[HTTP_HOST]" . ereg_replace('/$', '', dirname($_SERVER['PHP_SELF'])) . '/';
        $action = $_GET['action'] ? $_GET['action'] : ($_POST['action'] ? $_POST['action'] : '');
        $connection = @mysql_connect(mysql_hostname, mysql_username, mysql_password) && @mysql_select_db(mysql_database) || die('<code>' . mysql_error() . '</code>');
        switch ($action) {
            case 'generate_url':
                $parsed = @parse_url($_POST['url']);
                if ($parsed && strlen($_POST['url']) && ereg('\.', $_POST['url'])) {
                    if (eregi('^[a-z0-9-]+$', $_POST['tag'])) {
                        $tag = $_POST['tag'];
    					$url = ($parsed['scheme'] ? '' : 'http://') . (get_magic_quotes_gpc() ? mysql_real_escape_string(stripslashes($_POST['url'])) : mysql_real_escape_string($_POST['url']));
                        $sql = "SELECT * FROM `urls` WHERE `url_tag` = '$tag' OR `url_id` = '$tag' OR `url_location` = '$url'";
                        $q = mysql_query($sql);
                        $n = mysql_fetch_assoc($q);
                        if ($n) {
                            $cancel = true;
                        }
                    }
                    if (!$cancel) {
                        $url = ($parsed['scheme'] ? '' : 'http://') . (get_magic_quotes_gpc() ? mysql_real_escape_string(stripslashes($_POST['url'])) : mysql_real_escape_string($_POST['url']));
                        $sql = "INSERT INTO `urls` (`url_location`, `url_tag`) VALUES ('$url', '$_POST[tag]')";
                        $q = mysql_query($sql);
                        $id = mysql_insert_id();
                        if (!$tag) {
                            $result = 'Now here is your <strong>new URL</strong>: <a href="' . $root . $id . '/">' . $root .  $id . '/</a> !';
                        } else {
                            $result = 'Now here is your <strong>new URL</strong>: <a href="' . $root . $tag . '/">' . $root .  $tag . '/</a> !';
                        }
                    } else {
                        if (ereg('^[0-9]+$', $_POST['tag'])) {
                            $result = 'That tag is reserved for the system!';
    					} else if ($_POST['url'] == $n['url_location']) {
    						$result = 'URL unavailable!';
                        } else {
                            $result = 'Tag unavailable!';
                        }
                    }
                } else {
                    $result = 'Put in a <strong>real URL</strong> please!';
                }
                if ((bool) $_POST['javascript']) {
                    header('Content-Type: text/plain');
                    die($result);
                }
            break;
            case 'redirect':
                if (is_numeric($_GET['id']) || eregi('^[a-z0-9-]+$', $_GET['tag'])) {
                    if (!$_GET['tag']) {
                        $sql = "SELECT * FROM `urls` WHERE `url_id` = $_GET[id]";
                    } else {
                        $sql = "SELECT * FROM `urls` WHERE `url_tag` = '$_GET[tag]'";
                    }
                    $q = mysql_query($sql);
                    $r = mysql_fetch_assoc($q);
                    header("Location: $r[url_location]");
                    exit;
                } else {
                    header("Location: $root");
                    exit;
                }
            break;
        }
    ?>
    <!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>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
            <meta name="description" content="Shorten any URL - URL Shortener" />
            <meta name="keywords" content="url shortener, make url small, shrink url, shorten url" />
            <title>Shrinket - Turn a long URL into a short one!</title>
            <link href="/css/main.css" rel="stylesheet" />
            <link href="/img/favicon.png" rel="shortcut icon" />
            <script language="javascript" type="text/javascript">
                root = '<?php echo ereg_replace('/$', '', $root); ?>';
            </script>
            <script language="javascript" type="text/javascript" src="/js/main.js"></script>
        </head>
        <body>
            <div id="header">
                <h1><a href="/" title="Shorten your URL's">Shortener</a></h1>
                <h2>Make any <strong>URL</strong> small!</h2>
            </div>
            <form method="post" action="/" id="form">
                <input type="hidden" name="action" value="generate_url" />
                <h3><label for="url">Put your URL here</label></h3>
                <input type="text" name="url" id="url" class="input" />
                <h3 class="normal"><label for="tag">A custom tag here</label></h3>
                <input type="text" name="tag" id="tag" class="input" />
                <h3><label for="submit">Then click this</label></h3>
                <input type="submit" value="Shorten" id="submit" class="button" />
                <div id="result"><?php echo $result ? $result : ''; ?></div>
            </form>
            <div id="footer"><a href="#" onclick="add_plugin(); return false;">Add to FireFox</a></div>
        </body>
    </html>
    <?php
        function relink ($buffer) {
            global $root;
            return preg_replace('#(href|src|action)="/#i', '\\1="' . $root, $buffer);
        }
    ?>
    PHP:
     
    Nathan Malone, May 20, 2008 IP
    1-3-3-7 likes this.
  7. 1-3-3-7

    1-3-3-7 Well-Known Member

    Messages:
    605
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #7
    I tried with the new code and it still displays the same message as before.

    Thanks though.
     
    1-3-3-7, May 20, 2008 IP
  8. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #8
    Hmm, oh well. I'm in the middle of a project, so I can't jump into the code right now, but I might be able to do it later on, or perhaps someone else can help you out with the last little bit here.
     
    Nathan Malone, May 20, 2008 IP
  9. 1-3-3-7

    1-3-3-7 Well-Known Member

    Messages:
    605
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #9
    Alright.

    Thanks for your help, I'll see if maybe I can resolve it myself.
     
    1-3-3-7, May 20, 2008 IP
  10. gyp

    gyp Banned

    Messages:
    44
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #10
    if ( $job == "done" ) {
    echo "Please message me next time you have something";
    } else {
    echo "I am interested in this job, Please Message me.";
    }
     
    gyp, May 21, 2008 IP