Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    have vbs script and javascript but need php

    created and used the VBS script a long time ago; recently switched servers so VBS script doesn't work. javascript also appears not to work though. sigh. There are a lot of .php files here so I'm thinking now that is what's needed.

    Can the following script run in PHP? What it does is only list a single link on a webpage but clicking that one link then randomly redirects to any one of a prespecified set of possible links.

    I've never done PHP before so apologize if this sounds doesn't make sense.


    VBS script/html page (works, have used many time):
    [CODE]
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <html>
    <head>
    <title>CoursePerceptionSurvey</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <%
    randomize
    dim index1, index2, index3, link1(10), link2(10), link3(10), link4(10)
    link1(0) = "http://www.google.com"
    link1(1) = "http://www.yahoo.com"
    link1(2) = ""
    link1(3) = ""
    link1(4) = ""
    link1(5) = ""
    link2(0) = ""
    link2(1) = ""
    link3(0) = ""
    link3(1) = ""
    link4(0) = ""
    link4(1) = ""
    index1=cint(rnd*1)

    index2=cint(rnd*2)
    ' if you have 3 links, add the link to the links array. for example, links(2) = "the survey link here"
    ' change the function ahead to be index=cint(rnd*2)
    index3=cint(rnd*1)

    index4=cint(rnd*1)
    %>

    </head>

    <body>

    Thank you for your interest in participating in this study.&nbsp; Please click the link below to begin...</p>
    <a href="<%=link1(index1)%>" target="_blank"><font color="#0000FF">Survey</font></a>
    </font><br>
    <a href="<%=link2(index2)%>" target="_blank"><font color="#0000FF"> </font></a>
    <a href="<%=link3(index3)%>" target="_blank"><font color="#0000FF"> </font></a></p>
    <hr>
    </body>
    </html>
    [CODE]


    Javascript (this is untested since I just found out my server doesn't run this):

    [CODE]
    <%@LANGUAGE="JSCRIPT" CODEPAGE="1252"%>
    <html>
    <head>
    <title>CoursePerceptionSurvey</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <%
    var index1, index2, index3, link1=[], link2=[], link3=[], link4=[];
    var cint=parseInt, rnd=Math.random;
    link1[0] = "http://www.google.com"
    link1[1] = "http://www.yahoo.com"
    link1[2] = ""
    link1[3] = ""
    link1[4] = ""
    link1[5] = ""
    link2[0] = ""
    link2[1] = ""
    link3[0] = ""
    link3[1] = ""
    link4[0] = ""
    link4[1] = ""

    index1=cint(rnd*1)

    index2=cint(rnd*2)
    ' if you have 3 links, add the link to the links array. for example, links(2) = "the survey link here"
    ' change the function ahead to be index=cint(rnd*2)
    index3=cint(rnd*1)

    index4=cint(rnd*1)
    %>
    [CODE]
    Last edited by opirnia; 01-25-2010 at 05:31 PM. Reason: added [CODE]

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,387
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    PHP Code:
    <?php
    $list
    =array("http://www.google.com","http://www.yahoo.com","http://www.aol.com");
    shuffle($list);
    ?>
    <html>
    <body>
    <a href="<?=$list[0]?>" target="_blank"> click me </a>
    </body>
    </html>

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you. Is shuffle truly random? I only ask as I have googled and recently found a function called "rand"; they want to use this small script to assign people to surveys so it needs to be truly random.

    I will test this though to see what happens. Thank you so much.

    Quote Originally Posted by mlseim View Post
    PHP Code:
    <?php
    $list
    =array("http://www.google.com","http://www.yahoo.com","http://www.aol.com");
    shuffle($list);
    ?>
    <html>
    <body>
    <a href="<?=$list[0]?>" target="_blank"> click me </a>
    </body>
    </html>

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    There is no truely random algorithm for a programming language.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,387
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    Read more about it here:
    http://www.random.org/

    If you want, you can get a random number from them any time you need one.

  • Users who have thanked mlseim for this post:

    opirnia (01-25-2010)


  •  

    Posting Permissions

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