karabey
karabey

Reputation: 57

URL Shortning Code to short actually Page

I am trying to use for my own Website this Script https://github.com/briancray/PHP-URL-Shortener. On the Readme it tells this here

To programmatically shorten URLs with PHP use the following code:

$shortenedurl = file_get_contents('http://yourdomain.com/shorten.php?longurl=' . urlencode('http://' . $_SERVER['HTTP_HOST']  . '/' . $_SERVER['REQUEST_URI']));

If i add this Code to any Page of my Website it should shorten the actually Sites Link. But it will not show me the Link and Shorten it.

Upvotes: 1

Views: 138

Answers (1)

Aamir
Aamir

Reputation: 5440

Doing

$shortenedurl = file_get_contents('http://yourdomain.com/shorten.php?longurl=' . urlencode('http://' . $_SERVER['HTTP_HOST']  . '/' . $_SERVER['REQUEST_URI']));

would only shorten it and save it as a variable. To display it, you will need to display the contents of the variable using echo. Try this:

$shortenedurl = file_get_contents('http://yourdomain.com/shorten.php?longurl=' . urlencode('http://' . $_SERVER['HTTP_HOST']  . '/' . $_SERVER['REQUEST_URI']));
echo $shortenedurl;

Upvotes: 1

Related Questions