...

View Full Version : have vbs script and javascript but need php



opirnia
01-25-2010, 06:23 PM
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]

mlseim
01-25-2010, 07:30 PM
<?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>

opirnia
01-25-2010, 09:01 PM
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.




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

Fou-Lu
01-25-2010, 09:13 PM
There is no truely random algorithm for a programming language.

mlseim
01-25-2010, 11:42 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum