如何在PHP中共享动态链接


How to share a dynamic link in PHP?

我在PHP中生成了一个链接,该链接获取用户的ID,并将其放置在推荐链接的末尾,以跟踪谁使用推荐系统推荐谁。通过php:链接的示例

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

我正试图为facebook、twitter、电子邮件创建一个共享按钮,甚至使用bitly api添加一个shortener,但我一直遇到同样的问题。。。它不会更新用户ID,而是按原样发送URL。

我显然在做一些非常愚蠢的事情。非常感谢您的帮助。

如何共享链接:

<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>

链接按原样工作。如果我只想创建一个简单的链接,它会给我这样的东西,例如(当然取决于用户):

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

为什么当我使用facebook、twitter或bitlyapi共享链接时,它拒绝在url的末尾填充用户id?

非常感谢您的帮助!!!

EDIT(不起作用的完整php代码)

<?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 -->
";
?>

这个php是一个小盒子,它正确地生成了一个复制代码(使用引导程序框架),然后生成了当前未运行的共享链接。(忽略电子邮件链接,因为这是一个正常工作的模式)

您需要使用echo显示id,现在您只需将其显示为静态html,无需其他操作,将其修改为

<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>

您想要echo该值:

<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>

更新:

尽管它应该在您的更新中正常工作,但请尝试:

<?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 -->
";
?>

通过将值与字符串连接。