Forum

Thread tagged as: Question

Sharing blog posts by email or social media - Full URL?

Hi,

I've been using Perch to power a new website for the first time and I've been trying to get full URLs for the social sharing links. It's working at the moment, but still done partly manually and I was wondering if it's possible to get the full URL (query string included). Here are some examples of what I have:

<a href="mailto:?subject=<SUBJECT_TEXT_HERE>&body=https://www.domain.com<?php echo PerchUtil::html($_SERVER['REQUEST_URI']); ?> and <a href="https://www.facebook.com/sharer/sharer.php?u=https://www.domain.com<?php echo PerchUtil::html($_SERVER['REQUEST_URI']); ?>

but like I said, the domain parts are manually written. Is there any way to get the whole URL (domain/base + query string) for the social sharing links? :)

Thanks!

Tomi Tähti

Tomi Tähti 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can usually use $_SERVER['HTTP_HOST'] to get the current host, but it will depend on your hosting configuration.

Hi Drew!

Thank you for your answer. That indeed gives the "domain.com" part but will not include the protocol (https:// or https://) at the beginning. This is not so serious though, the protocol and domain shouldn't change anytime soon, but I started investigating this purely out of curiosity. :)

Kind Regards, Tomi