Sharath
Sharath

Reputation: 2428

Not able to share the link in whatsapp which contains parameters in url

I have link which needs to be shared in whatsapp which looks like the one shown below.

<?php 
$temp = 'whatsapp://send?text=http://www.example.com/index.php?
           secid=1&url=/content/575098/ready-opposed.html';
?>

<a href="<?php echo urlencode($temp); ?>">
  <img src="img_uploads/watsapp.png" width="18" height="18"/>
</a>  

So now when I share it through mobile site, in Whatsapp I get only http://www.example.com/index.php?secid=1 but the next parameter url is not there. Just to test if I put url as 1st parameter and secid as 2nd parameter then I receive only url but not secid.

In my scenario only if those 2 parameters is present the page is rendered

Can someone please help me solve this issue.

Upvotes: 4

Views: 6254

Answers (3)

Aldoo Rayan
Aldoo Rayan

Reputation: 21

I solved a similar problem using:

$value = 2;
$message_to_send = urlencode(rawurlencode("www.domain.com/products.php?Id=".$value))

Upvotes: 1

Vikas Jangra
Vikas Jangra

Reputation: 195

Just Use The rawurlencode() instead of urlencode() For example

<?php
$value = 2;
$text = rawurlencode("www.domain.com/products.php?Id=".$value);
?>
<a href="https://api.whatsapp.com/send?text=<?php echo $text; ?>"><i class="fa fa-whatsapp"></i></a>

Upvotes: 5

Pixel88
Pixel88

Reputation: 41

I'm reviving an old/dead answer, but I had the same problem and solved URLencoding the special chars.

In this case, convert the & with %26

Some ref:

Upvotes: 4

Related Questions