如何在PHP中共享动态链接?

时间:2014-10-27 19:36:08

标签: php api dynamic twitter hyperlink

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

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

我试图为Facebook,Twitter,电子邮件创建一个分享按钮,甚至使用shortener添加bitly api - 但我一直遇到同样的问题...它会不更新用户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或bitly api share链接时,它拒绝在网址末尾填充用户ID?

非常感谢任何帮助!!!

编辑(完整的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是一个小盒子,正确生成一个复制代码(使用bootstrap框架),然后是当前没有运行的共享链接。 (忽略电子邮件链接,因为模式正确地工作)

2 个答案:

答案 0 :(得分:2)

你需要使用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>

答案 1 :(得分:2)

您希望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>

UPDATE:

虽然它应该在您的更新中有效,但请尝试:

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

";
?>

通过将值与字符串连接起来。