Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-25-2010, 05:23 PM   PM User | #1
opirnia
New to the CF scene

 
Join Date: Jan 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
opirnia is an unknown quantity at this point
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]
opirnia is offline   Reply With Quote
Old 01-25-2010, 06:30 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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>
mlseim is offline   Reply With Quote
Old 01-25-2010, 08:01 PM   PM User | #3
opirnia
New to the CF scene

 
Join Date: Jan 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
opirnia is an unknown quantity at this point
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>
opirnia is offline   Reply With Quote
Old 01-25-2010, 08:13 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
There is no truely random algorithm for a programming language.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 01-25-2010, 10:42 PM   PM User | #5
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
opirnia (01-25-2010)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:36 PM.


Advertisement
Log in to turn off these ads.