random value

Discussion in 'PHP' started by janjalani, Dec 26, 2005.

  1. #1
    Hi, I really know nothing about php, so maybe you guys can help me:)
    I have this form
    <form name="my_form" method="get" action="http://websitehere.com">
      <input type="hidden" name="q" value="" id="url_input" />
      <input type="hidden" name="hl" value="" />
    Code (markup):
    And I want replace the "http://websitehere.com" by 5 different random urls like "http://1websitehere.com" and "http://2websitehere.com" and "http://3websitehere.com" so on.. Even better I could put "weight" in them so 1 url will show more often.. probably this can be done by php or java? I dont know:confused:
     
    janjalani, Dec 26, 2005 IP
  2. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sorry i don't understand, you want to open 5 pages when the form is completed
     
    onlyican.com, Dec 26, 2005 IP
  3. janjalani

    janjalani Active Member

    Messages:
    238
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #3
    janjalani, Dec 26, 2005 IP
  4. tresman

    tresman Well-Known Member

    Messages:
    235
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    138
    #4
    I'm bad at php and too lazy now (I'm on holidays!) to modify it for you, but here

    http://www.alistapart.com/articles/randomizer/

    you can find a tutorial on how to make a image random via php. If you a know just a bit on programming will be really easy to modify so it fits your requirements.
     
    tresman, Dec 26, 2005 IP
  5. janjalani

    janjalani Active Member

    Messages:
    238
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Thanks but i can't modify it, looks complicated :p
     
    janjalani, Dec 26, 2005 IP
  6. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #6
    I have to make an assumption here. A php file generates that html and you can put a variable in the action element of the form tag.

    
    $urls = array(
        "http://www.example.com/1/",
        "http://www.example.com/2/",
        "http://www.example.com/3/",
        );
    $url = $urls[rand(0,count($urls)-1)];
    
    echo "<form name=\"my_form\" method=\"get\" action=\"$url\">";
    
    PHP:
    Quick idea. Not tested.
     
    noppid, Dec 26, 2005 IP
    tresman likes this.
  7. tresman

    tresman Well-Known Member

    Messages:
    235
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    138
    #7
    I was writting a reply with some code that should also work, but the one posted while I was writting looks better (I'm pretty sure it will work) so go ahead and try it.
     
    tresman, Dec 26, 2005 IP
    noppid likes this.
  8. janjalani

    janjalani Active Member

    Messages:
    238
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #8
    Thanks noppid and tresman, it worked :) So if i want to add more urls I will just add below the array?
     
    janjalani, Dec 26, 2005 IP
  9. tresman

    tresman Well-Known Member

    Messages:
    235
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    138
    #9
    Hey! why don't you just make a quick test? ;) It's quick and will help you a lot! :p
     
    tresman, Dec 26, 2005 IP
  10. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #10
    Yep, exactly. Just add URLs to the array and the math will always work.
     
    noppid, Dec 26, 2005 IP
    janjalani likes this.
  11. janjalani

    janjalani Active Member

    Messages:
    238
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #11
    Alright, Thanks :)
     
    janjalani, Dec 26, 2005 IP
    noppid likes this.
  12. mrongey

    mrongey Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Sorry to resurrect an old thread, but this is exactly the kind of script I need - except I need to add weight to the urls, and I want to be able to do it some way other than having multiple entries of the same url in the array.

    Please help the newbie!
     
    mrongey, Feb 9, 2006 IP