2

I have a simple share button for facebook, twitter and Pinterest

<a href="<?php echo "$base_url/share.php"; ?>" class="btn btn-default btn-facebook btn-icon btn-block" target="popup" 
onclick="window.open('<?php echo "$base_url/share.php?id=$id&share=fb&type=article"; ?>','popup','width=600,height=600'); return false;"><i class="fab fa-facebook"></i> <span class="post-sharing__label d-none d-sm-inline-block">Share on Facebook</span></a>

<a href="<?php echo "$base_url/share.php"; ?>" class="btn btn-default btn-twitter btn-icon btn-block" target="popup" 
onclick="window.open('<?php echo "$base_url/share.php?id=$id&share=tw&type=article"; ?>','popup','width=600,height=600'); return false;"><i class="fab fa-twitter"></i> <span class="post-sharing__label d-none d-sm-inline-block">Share on Twitter</span></a>

<a href="<?php echo "$base_url/share.php"; ?>" class="btn btn-default btn-twitter btn-icon btn-block" target="popup" 
onclick="window.open('<?php echo "$base_url/share.php?id=$id&share=tw&type=article"; ?>','popup','width=600,height=600'); return false;"><i class="fab fa-twitter"></i> <span class="post-sharing__label d-none d-sm-inline-block">Share on Twitter</span></a>

When a user clicks to share it goes to a php file named share.php; this file gets information regarding the page that's going to get shared.

if ($share =="tw"){     

header("Location: http://twitter.com/share?text=$seo_description&url=$share_url");
die();
}

On desktop, it works without an issue but on mobile, I get the following error

The terms you entered did not bring any results, please try again later.

Facebook and Pinterest works on mobile, i am strugling with any reason why im getting this.

I am logged into the same twitter account on my mobile as my pc.

i got the information for my url from this question

Nashie
  • 311
  • 1
  • 10
  • 1
    I'd suggest you apply proper URL encoding to these values you are putting into a URL context there first of all. – CBroe Feb 14 '23 at 08:03
  • ok thats a good point but why does it work on pc? and the issue only happens on mobile? – Nashie Feb 14 '23 at 08:05
  • 1
    Probably because the mobile browsers behave differently, when it comes to handling "missing" URL encoding on their own. – CBroe Feb 14 '23 at 08:12

1 Answers1

1

I got this working on mobile by changing the link

if ($share =="tw"){     

header("Location: http://twitter.com/share?text=$seo_description&url=$share_url");
die();
}

to this

if ($share =="tw"){     

header("Location: https://twitter.com/intent/tweet?text=$seo_description&url=$share_url");
die();
}
Nashie
  • 311
  • 1
  • 10