Hello,

I would like to share a page on facebook with a dynamic url.

Here is the code to get the dynamic url.

<?php 
 $profie_url =  $this->url(array("id" => $mRow->id, "url" =>
                $this->urlify($mRow->first_name)) , "details") ."/" . $this->urlify(trim($mRow->subtitle)) . "/" . $this->urlify(trim($mRow->city_name));
 ?>

To use it I usually do:

href="<?php echo $profie_url?>"

The code below is to share on facebook. How can I change the static url by a dynamic url?

<div id="fb-root"></div> <script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/fr_CA/sdk.js#xfbml=1&version=v2.8";
  fjs.parentNode.insertBefore(js, fjs);
 }(document, 'script', 'facebook-jssdk'));</script> <div class="fb-share-button" data-href="https://www.mywebsite.com/" data-layout="button" data-size="large" data-mobile-iframe="true"><a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.mywebsite.com&src=sdkpreparse">Partager</a> </div>

Hi,
this might come in handy to achieve what you exactly need. Check the link below.
Facebook Dev

you can do it like this:

  <!-- Load Facebook SDK for JavaScript -->
  <div id="fb-root"></div>
  <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));</script>

  <!-- Your share button code -->
  <div class="fb-share-button"

  <!-- Your dynamic URL goes here -->
    data-href="<?php echo $profie_url?>"

    data-layout="button_count">
  </div>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.