Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

minor edits but one important one #1

Closed
wants to merge 5 commits into from

2 participants

@bl4h

Config.php needs PHP tags

bl4h added some commits
@bl4h bl4h Most servers will send the source code and expose mysql info if you d…
…on't specify PHP tags !
05879df
@bl4h bl4h erm 3b9695a
@bl4h bl4h 6a6b6d2
@bl4h bl4h Save a lot of bandwidth by only doing a HEAD (header only).
Curl handler in curl_close was incorrect.
Die will close curl so we don't have to worry about having curl_close before that.
79f1374
@bl4h bl4h safer and keeps people from entering invalid urls. 045c715
@briancray
Owner

Closing PHP tags is a bad idea because it may cause the PHP file to incorrectly send output to the browser

@briancray briancray closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 13, 2011
  1. @bl4h

    Most servers will send the source code and expose mysql info if you d…

    bl4h authored
    …on't specify PHP tags !
  2. @bl4h

    erm

    bl4h authored
  3. @bl4h

    No commit message

    bl4h authored
  4. @bl4h

    Save a lot of bandwidth by only doing a HEAD (header only).

    bl4h authored
    Curl handler in curl_close was incorrect.
    Die will close curl so we don't have to worry about having curl_close before that.
  5. @bl4h
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 6 deletions.
  1. +3 −2 config.php
  2. +2 −1  redirect.php
  3. +5 −3 shorten.php
View
5 config.php
@@ -1,4 +1,4 @@
-
+<?PHP
/*
* First authored by Brian Cray
* License: http://creativecommons.org/licenses/by/3.0/
@@ -35,4 +35,5 @@
define('CACHE', TRUE);
// if so, where will the cache files be stored? (include trailing slash)
-define('CACHE_DIR', dirname(__FILE__) . '/cache/');
+define('CACHE_DIR', dirname(__FILE__) . '/cache/');
+?>
View
3  redirect.php
@@ -53,4 +53,5 @@ function getIDFromShortenedURL ($string, $base = ALLOWED_CHARS)
$out += strpos($base, $char) * pow($length, $size - $i);
}
return $out;
-}
+}
+?>
View
8 shorten.php
@@ -9,7 +9,7 @@
$url_to_shorten = get_magic_quotes_gpc() ? stripslashes(trim($_REQUEST['longurl'])) : trim($_REQUEST['longurl']);
-if(!empty($url_to_shorten) && preg_match('|^https?://|', $url_to_shorten))
+if(!empty($url_to_shorten) && preg_match('|^https?://|', $url_to_shorten) && filter_var($url_to_shorten, FILTER_VALIDATE_URL) !== FALSE)
{
require('config.php');
@@ -24,13 +24,14 @@
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_to_shorten);
+ curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
- curl_close($handle);
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) == '404')
{
die('Not a valid URL');
}
+ curl_close($ch);
}
// check if the URL has already been shortened
@@ -60,4 +61,5 @@ function getShortenedURLFromID ($integer, $base = ALLOWED_CHARS)
$integer = floor( $integer / $length );
}
return $base[$integer] . $out;
-}
+}
+?>
Something went wrong with that request. Please try again.