Chris S
Chris S

Reputation: 3

How to share a dynamic link in PHP?

I have a generated link in PHP that takes the user's ID and places it at the end of a referral link to track who refers who using a referral system. Example of the link via php:

http://example.com/index.php?page=act/reg&inv=$arrusr[0]

I'm trying to create a share button for facebook, twitter, email, and even add a shortener using bitly api - but I keep running into the same problem... it will not update the user ID, and instead literally send the URL as is.

I'm obviously doing something very stupid. Any help is greatly appreciated.

How the link is shared:

<a class='btn btn-tw' href='https://twitter.com/home?status=http://example.com/test/index.php?page=act/reg&inv=$arrusr[0]'><i class='fa fa-2x fa-twitter twcolor'></i></a>

The link works as is. If I want to just create a simple link, it will give me something like this for example (depending on the user of course):

http://example.com/index.php?page=act/reg&inv=43

How come, when I use a facebook, twitter, or bitly api share link it refuses to populate the user id on the end of the url?

Any help is greatly appreciated!!!

EDIT (full php code that isn't working)

<?php

echo "
        <div class='row'><!-- start of row text -->
            <div class='col-md-4'>
                <center><img src='image/logo.png' alt='Logo' class='img-circle img-responsive logo-size' style='max-height:275px;'></center>
                <div id='DateCountdown' class='img-responsive' data-date='2014-11-01 04:05:00'></div><br />
           </div>
           <div class='col-md-8 welcome-bar'>
                <img src='image/thankyoubanner.png' alt='Thank you for signing up' class='img-responsive'>
                <h2>Invite friends and<br />win more prizes!</h2>
                            <p align='center'>Share this unique link via email, facebook or twitter and win more prizes as each friend signs up.</p>
                            <center><form role='form'>
                            <input class='form-control' id='focusedInput' type='text' value='http://example.com/index.php?page=act/reg&inv=$arrusr[0]' style='max-width:375px;text-align:center;'>
                            </form></center>
                            <a class='btn btn-fb' href=http://www.facebook.com/sharer/sharer.php?u=http://example.com/index.php?page=act/reg&inv=$arrusr[0]'><i class='fa fa-2x fa-facebook fbcolor'></i></a>
                            <a class='btn btn-em' data-toggle='modal' data-target='#subscribe'><i class='fa fa-2x fa-envelope-o emcolor'></i></a>
                            <a class='btn btn-tw' href='https://twitter.com/home?status=http://example.com/index.php?page=act/reg&inv=$arrusr[0]'><i class='fa fa-2x fa-twitter twcolor'></i></a>

           </div>
        </div><!-- end of row countdown -->

";
?>

This php is a little box that is correctly generating a copy code (using bootstrap framework), and then the share links that are currently not operating. (ignore the email link as that's a modal correctly working)

Upvotes: 0

Views: 4014

Answers (2)

Kypros
Kypros

Reputation: 2986

You would want to echo that value:

<a class='btn btn-tw' href='https://twitter.com/home?status=http://example.com/test/index.php?page=act/reg&inv=<?php echo $arrusr[0]; ?>'><i class='fa fa-2x fa-twitter twcolor'></i></a>

UPDATE:

Although it should work as is in your update, please try:

<?php

echo "
        <div class='row'><!-- start of row text -->
            <div class='col-md-4'>
                <center><img src='image/logo.png' alt='Logo' class='img-circle img-responsive logo-size' style='max-height:275px;'></center>
                <div id='DateCountdown' class='img-responsive' data-date='2014-11-01 04:05:00'></div><br />
           </div>
           <div class='col-md-8 welcome-bar'>
                <img src='image/thankyoubanner.png' alt='Thank you for signing up' class='img-responsive'>
                <h2>Invite friends and<br />win more prizes!</h2>
                            <p align='center'>Share this unique link via email, facebook or twitter and win more prizes as each friend signs up.</p>
                            <center><form role='form'>
                            <input class='form-control' id='focusedInput' type='text' value='http://example.com/index.php?page=act/reg&inv=".$arrusr[0]."' style='max-width:375px;text-align:center;'>
                            </form></center>
                            <a class='btn btn-fb' href=http://www.facebook.com/sharer/sharer.php?u=http://example.com/index.php?page=act/reg&inv=".$arrusr[0]."'><i class='fa fa-2x fa-facebook fbcolor'></i></a>
                            <a class='btn btn-em' data-toggle='modal' data-target='#subscribe'><i class='fa fa-2x fa-envelope-o emcolor'></i></a>
                            <a class='btn btn-tw' href='https://twitter.com/home?status=http://example.com/index.php?page=act/reg&inv=".$arrusr[0]."'><i class='fa fa-2x fa-twitter twcolor'></i></a>

           </div>
        </div><!-- end of row countdown -->

";
?>

by concatenating the value with the string.

Upvotes: 2

Ali
Ali

Reputation: 3461

You need to display the id using echo, now you're simply displaying it as static html, nothing else, modify it to

<a class='btn btn-tw' href='https://twitter.com/home?status=http://example.com/test/index.php?page=act/reg&inv=<?php echo $arrusr[0]; ?>'><i class='fa fa-2x fa-twitter twcolor'></i></a>

Upvotes: 2

Related Questions