Link shortener in PHPBB?

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
DockPro
Registered User
Posts: 6
Joined: Sun Mar 25, 2018 10:59 pm

Link shortener in PHPBB?

Post by DockPro »

Hello, I'm implementing a shortening of links to my forum, I've already installed it, but I want the links to be automatically shortened, for this the creator has provided a code, but I do not know exactly where to place it, they could help me. 8-)

- To programmatically shorten URLs with PHP use the following code:

Code: Select all

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

Souce: https://github.com/briancray/PHP-URL-Shortener
User avatar
AmigoJack
Registered User
Posts: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Link shortener in PHPBB?

Post by AmigoJack »

Don't do that - you hand over every URI to a third party, which can easily log everything everyone links. And on top of that when the service dies you're sitting there with dead links.

As for your question: you'd have to modify multiple files and adapt that example - different things (posts, forum descriptions, signatures, PMs...) are saved at different places.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5871
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Link shortener in PHPBB?

Post by thecoalman »

AmigoJack wrote: Mon Jun 11, 2018 7:33 am Don't do that - you hand over every URI to a third party, which can easily log everything everyone links. And on top of that when the service dies you're sitting there with dead links.
This is a local script and the redirection is performed locally, see the link.

@OP Similar to AmigoJacks's warning one thing to keep in mind is you need to maintain this forever.

If I was going to implement something like this I'd just put it at the bottom of viewtopic.php, viewforum.php and perhaps downloads/file.php

Use validated phpBB variables, if in viewtopic.php this should work.

Code: Select all

$shortenedurl = file_get_contents('http://yourdomain.com/shorten.php?longurl=' . urlencode('http://yourdomian.com/viewtopic.php?f=' . $forum_id . '&t=' . $topic_id . ($start ? '&start=' . $start : '')));
As far as the security of the third party script I'm no expert but I see it will block based on IP and I would be sure to use that.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
Lumpy Burgertushie
Registered User
Posts: 69223
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Link shortener in PHPBB?

Post by Lumpy Burgertushie »

if it was me, just based on those two responses, I would not do it.

besides, why are you wanting to do this? nobody cares how long a link is, they just click on it.
by the way, phpbb already shortens local links in a post.


robert
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5871
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Link shortener in PHPBB?

Post by thecoalman »

Lumpy Burgertushie wrote: Mon Jun 11, 2018 1:55 pm
besides, why are you wanting to do this? nobody cares how long a link is, they just click on it.
by the way, phpbb already shortens local links in a post.
phpBB only shortens the displayed link text, this shortens the url itself.

Code: Select all

https://www.phpbb.com/community/viewtopic.php?f=641&t=2474926
Becomes:

Code: Select all

https://www.phpbb.com/xyz123
xyz123 is just a random string and the script will redirect to the correct URL. It's cleaner especially if there is very long URL but overall never found it very useful.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28619
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Link shortener in PHPBB?

Post by Paul »

It is also a potential security risk as you have no idea where you are going to. And as such it is a favourite function for phishing.
User avatar
Toxyy
Registered User
Posts: 942
Joined: Mon Oct 24, 2016 3:22 pm
Location: Namek
Contact:

Re: Link shortener in PHPBB?

Post by Toxyy »

thecoalman wrote: Tue Jun 12, 2018 2:43 pm
Lumpy Burgertushie wrote: Mon Jun 11, 2018 1:55 pm
besides, why are you wanting to do this? nobody cares how long a link is, they just click on it.
by the way, phpbb already shortens local links in a post.
phpBB only shortens the displayed link text, this shortens the url itself.

Code: Select all

https://www.phpbb.com/community/viewtopic.php?f=641&t=2474926
Becomes:

Code: Select all

https://www.phpbb.com/xyz123
xyz123 is just a random string and the script will redirect to the correct URL. It's cleaner especially if there is very long URL but overall never found it very useful.
There are a couple of extensions that do something pretty similar to that, unless hes wanting a local url shortener like goo.gl or something for his boards sake.
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

Some of my extensions:
[3.3][BETA] Post Form Templates || [3.3][BETA] Anonymous Posts || [3.2][3.3][BETA] ACP Merge Child Forums || [3.2][BETA] Sticky Ad || [3.2][DEV] User Delete Topics || [3.3][DEV] Moderate While Searching || [3.3][RC] Short Number Twig Extension
Post Reply

Return to “phpBB Custom Coding”