SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot robcub's Avatar
    Join Date
    May 2008
    Location
    London, England
    Posts
    135
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Using uniqid() - I'm a noob

    The website I'm doing at the moment they want a URL generated with two unique numbers in it. Like this:

    https://website.com/cl10/signup.php?...11&id2=8.1.1.1

    Only everytime a user clicks on this the id1 and the id2 should be different. I think you can do it with PHP using uniqid() function. Does anyone know where I can find out how to do that.

    Thanks

  2. #2
    SitePoint Addict
    Join Date
    Jul 2007
    Location
    San Jose, California
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    srand(mktime());
    $url = "http://www.website.com?id=".rand()."&id2=".rand();

  3. #3
    SitePoint Zealot robcub's Avatar
    Join Date
    May 2008
    Location
    London, England
    Posts
    135
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi baileylo,

    I added this to the HTML to try to get the link:

    HTML Code:
    <a href="<?php srand(mktime()); $url = "http://www.website.com?id=".rand()."&id2=".rand(); ?>" title="">
    I'm guessing that's not how you're supposed to do it? I'm a complete noob, I'm afraid.

  4. #4
    SitePoint Addict
    Join Date
    Jul 2007
    Location
    San Jose, California
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you're not printing anything
    <?php
    srand(mktime());
    $url = ......what we already had ...;
    ?>

    <a href="<?= $url ?>">URL</a>

    That'll only work if you got short tags on

  5. #5
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You gotta echo out the $url,

    PHP Code:
    <a href="<?php srand(mktime()); echo $url "http://www.website.com?id=".rand()."&id2=".rand(); ?>" title="">
    Don't use short tags! Removed for PHP 6 permanantly! (You aren't, but the guy above said something about them)

  6. #6
    SitePoint Zealot robcub's Avatar
    Join Date
    May 2008
    Location
    London, England
    Posts
    135
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you baileylo and JREAM. I'm using JREAM's code and it's working great. I've also started going through the tuts at W3schools to try to get some idea into my head about PHP.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •