School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store | FORUMS

Class / Forums / php101 Refresh the current page Week #8 Basic To-Do Assignment, post here
 

 (#14 2003-08-07 16:49:17) Post Reply

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Week #8 Basic TO-DO ASSIGNMENT: Write a script to randomly choose a URL and redirect the surfer when clicked. Make the URL a javascript mouseover so that it is a blind link so the person clicking will not see the result in the browser status window.

Post this assignment here so that we can offer comment/critique for you, but also post a URL to the working copy of the script and the complete source code of the script in your post.

scriptname.php <-- script name

Good luck to you!

 

 (#82 2003-08-22 15:48:49) Post Reply

Sk8rRIMuk
Need To Set


Enrolled: Aug 2003
Posts: 39
AP: 1

The working URL to my script is:
http://www.katikai.com/ee/assi...0Assignment.php

As always all my scripts can be found at:
http://www.katikai.com/ee/assignment/

Heres my code:


<?php
if($url!=""){
if(
$url=='rnd'){
//If the url is set to rand activate the array
$urls=array(
//Set the array
'http://www.n00bstories.com/',
'http://www.scriptschool.com/',
'http://www.google.co.uk/',
'http://www.katikai.com/');
srand(time());
$count=count($urls);
$result=rand(0,$count);
//Count and get the results of the array
$url=$urls[$result];}
//Pick a random url and asign it to the url variable
header("Location:$url");
//Call up the url into the header() function
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Week #8 Advanced To-Do Assignment</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<center>
<a href="http://www.katikai.com/ee/assignment/Week%20%238%20Basic%20To-Do%20Assignment.php?url=rnd"
onMouseOver="window.status='View a random URL via this nifty script'; return true;"
onMouseOut="window.status='';">Random URL Viewer</a>
</center>
</body>
</html>


 

 (#186 2003-09-11 05:14:09) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

me again :)


<?
if($to == "ok") {
$urls = array("http://www.tdscripts.com/", "http://www.scriptschool.com/", "http://www.php-scripts.com/", "http://www.casinoluckydog.com/");
mt_srand(time());
$choose = mt_rand(0, (count($urls))-1);
$to = $urls[$choose];
header("Location: $to"); }
?>

<a href="http://quicksaver.coolfreepage.com/assignement8basic.php?to=ok"
onMouseOver="window.status='Well? Click it.'; return true;"
onMouseOut="window.status='';">link</a>


<?
$count
= count($urls);
$result = rand(0,$count); ?>



<?
$count
= count($urls)-1; //the -1 :)
$result = rand(0,$count); ?>



tsc tsc tsc... TDavid TDavid... i would never imagine... :D

 

 (#187 2003-09-11 05:16:25) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

ah cmon why cant i add text between codes??? you really gotta correct that, gonna split tat then

my code:


<?
if($to == "ok") {
$urls = array("http://www.tdscripts.com/", "http://www.scriptschool.com/", "http://www.php-scripts.com/", "http://www.casinoluckydog.com/");
mt_srand(time());
$choose = mt_rand(0, (count($urls))-1);
$to = $urls[$choose];
header("Location: $to"); }
?>

<a href="http://quicksaver.coolfreepage.com/assignement8basic.php?to=ok"
onMouseOver="window.status='Well? Click it.'; return true;"
onMouseOut="window.status='';">link</a>


working url

 

 (#188 2003-09-11 05:18:08) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

then i said i found this error under "Simple JavaScript Mouseover with PHP" on the course:


<?
if($in != "") {
if (
$in == "rnd") {
$urls = array("http://www.tdscripts.com/",
"http://www.scriptschool.com/",
"http://www.php-scripts.com/",
"http://www.casinoluckydog.com/");
srand(time());
$count = count($urls);
$result = rand(0,$count);
$in = $urls[$result];
}
header("Location: $in");
}
?>



you put that example in and that example is bugged, you got 2 seconds to find the bug for yourself untill you read the next post :)

 

 (#189 2003-09-11 05:19:44) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

the bug is that arrays start at 0 and the count() funtion starts counting at 1 so you gotta put the -1 after it like so:


<?
if($in != "") {
if (
$in == "rnd") {
$urls = array("http://www.tdscripts.com/",
"http://www.scriptschool.com/",
"http://www.php-scripts.com/",
"http://www.casinoluckydog.com/");
srand(time());
$count = count($urls)-1;
$result = rand(0,$count);
$in = $urls[$result];
}
header("Location: $in");
}
?>



then i said "tsc tsc tsc blahblahblah", that part is stilll visible on the first post

 

 (#242 2003-09-18 05:25:03) Post Reply

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

My Week #8 Assignment
http://members.lycos.co.uk/jef...wan/class08.php



<?
$in
=$_REQUEST['in'];
//if($in != "") { header("Location: $in"); }

if($in != "") {
if (
$in == "rnd") {
$urls = array("http://www.tdscripts.com/",
"http://www.scriptschool.com/",
"http://www.php-scripts.com/",
"http://www.casinoluckydog.com/");
srand(time());
$count = count($urls);
$result = rand(0,$count);
$in = $urls[$result];
}
header("Location: $in");
}
?>

<HTML>
<TITLE>Class 8 Basic Assignment</title>
Welcome to suprise Dyanmic Link.</br>
Click <a href=<? $_SERVER['PHP_SELF']; ?>?in=rnd
onMouseOver="window.status='Click This!!!'; return true;"
onMouseOut="window.status='';"> Here </a><br>

</HTML>


 

 (#445 2003-12-31 16:02:05) Post Reply

PureGrain
Need To Set


Enrolled: Nov 2003
Posts: 14
AP: 1

Here is week 8 :)


<?
if($header != "")
{
if(
$header == "random")
{
$url =array ("http://www.completronics.com/",
"http://www.msn.com/",
"http://www.google.com",
"http://www.scriptschool.com"
);
mt_srand(time());
$count = count($url);
$result = count(0,$count);
$header =($url[$result]);
}
header("Location: $header");
}

?>

<HTML>
<BODY>
<a href="http://members.lycos.co.uk/xkoremaster/lesson8/lesson8.php?header=random"
onMouseOver="window.status='Yes, please click the link above!!!'; return true";
onMouseover="window.status=''";>Please click this link to be redirected to the site!</a>
</BODY>
</HTML>


http://members.lycos.co.uk/xko...on8/lesson8.php

 

 (#446 2003-12-31 16:45:20) Post Reply

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Bug here on this line PureGrain:

[CODE]
$result = count(0,$count);
[/CODE]

mt_rand() I think is what you are looking for as the function here.

 

 (#448 2003-12-31 18:34:22) Post Reply

PureGrain
Need To Set


Enrolled: Nov 2003
Posts: 14
AP: 1

Thanks TDavid. I got ahead of myself. I actually had the code right the first time, then i saved over the file by accident and re-wrote it too fast i guess. :D
BTW, I was wondering why the url kept popping up MSN everytime. :)
here is the fixed code and url.



<?
if($header != "")
{
if(
$header == "random")
{
$url =array ("http://www.completronics.com/",
"http://www.msn.com/",
"http://www.google.com",
"http://www.scriptschool.com"
);
mt_srand(time());
$count = count($url);
$result = rand(0,$count);
$header =($url[$result]);
}
header("Location: $header");
}

?>

<HTML>
<BODY>
<a href="http://members.lycos.co.uk/xkoremaster/lesson8/lesson8.php?header=random"
onMouseOver="window.status='Yes, please click the link above!!!'; return true";
onMouseover="window.status=''";>Please click this link to be redirected to the site!</a>
</BODY>
</HTML>



Thanks again TD
http://members.lycos.co.uk/xko...on8/lesson8.php

 

 (#474 2004-01-16 05:28:04) Post Reply

fpu112
Need To Set


Enrolled: Jan 2004
Posts: 1
AP: 1

hey SK8

Heres my code:


<?php
if($url!=""){
if(
$url=='rnd'){
//If the url is set to rand activate the array
$urls=array(
//Set the array
'http://www.n00bstories.com/',
'http://www.scriptschool.com/',
'http://www.google.co.uk/',
'http://www.katikai.com/');
srand(time());
$count=count($urls);
$result=rand(0,$count);
//Count and get the results of the array
$url=$urls[$result];}
//Pick a random url and asign it to the url variable
header("Location:$url");
//Call up the url into the header() function
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Week #8 Advanced To-Do Assignment</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<center>
<a href="http://www.katikai.com/ee/assignment/Week%20%238%20Basic%20To-Do%20Assignment.php?url=rnd"
onMouseOver="window.status='View a random URL via this nifty script'; return true;"
onMouseOut="window.status='';">Random URL Viewer</a>
</center>
</body>
</html>



there is an error there (well at least there was for me, when i tried it the same away at first. on this line
$count=count($urls); i made mine $count=(count($urls)-1) becasue my rand link would always throw in my directory wich i had all my php files in, and i didnt want that, just thought i would point that out...nerd, and get better grades :P

 

 (#629 2004-06-09 09:26:21) Post Reply

Ahkorahil
Need To Set


Enrolled: Oct 2003
Posts: 20
AP: 1

<?php
if ($to != "") {
if ($to = "lam") {
$url = array("http://www.zone.ee",
"http://www.jippii.ee",
"http://www.tdscripts.com",
"http://www.hot.ee");
mt_srand(time());
$answer = (mt_rand(1, (count($url)))-1);
$to = $url[$answer];
}
header("Location: $to");
}
?>
Click here<br>
<a href="http://members.lycos.co.uk/rain086/php/8.php?to=lam"
onMouseOver="window.status='Click on this link'; return true;"
onMouseOut="window.status='';">Hello, click on ME plz</a>

 

 (#736 2004-11-12 15:02:49) Post Reply

lestat
Need To Set


Enrolled: Jan 2004
Posts: 44
AP: 1

Working URL - http://www.timslan.com/scripts...k8/wk8basic.php

Suggestions? Coments?

<?
/* randomly choose a URL and redirect the surfer when clicked.
Make the URL a javascript mouseover so that it is a blind
link so the person clicking will not see the result in the
browser status window */

// Process code to redirect
if($in != ""){

// Assigning urls to variable to link
if ($in == "rnd"){
$randomurls = array("http://www.google.com/",
"http://www.scriptschool.com/",
"http://www.xerorip.com/",
"http://www.tigerdirect.com/");

mt_srand(time()); // Setting Random Seed
$count = count($randomurls); // Count the urls
$number = mt_rand(0,$count); // Getting the random number
$in = $randomurls[$number]; // Picking URL from the random number
}
header("Location: $in"); // If no redirect variable is set (1st page open)
}
?>

<html>
<head>
<title>Week #8 BASIC ~ Lestat</title>
<link rel="stylesheet" type="text/css" href="/css/scriptskewl.css">
</head>
<body>
Click <a href="http://timslan.com/scriptskewl/week8/wk8basic.php?in=rnd"
onMouseOver="window.status='link'; return true;"
onMouseOut="window.status='';">here</a> for a random page Link
</body>
</html>

 

 (#737 2004-11-12 15:06:32) Post Reply

lestat
Need To Set


Enrolled: Jan 2004
Posts: 44
AP: 1

Forgot to add the code tags ... sorry :)

 

 (#785 2005-03-06 11:04:22) Post Reply

zman
Need To Set


Enrolled: Feb 2005
Posts: 15
AP: 1

My basic assignment #8:



<?php

/* ScriptSchool.com Assignment 8 (basic)
// Description of Assignment: Write a script to randomly
// choose a URL and redirect the surfer when clicked. Make the
// URL a javascript mouseover so that it is a blind link so the
// person clicking will not see the result in the browser status
// window.*/

if($in != "")
{
if (
$in == "rnd") {
$urls = array("http://garagechoppers.com/learning_php/assignment7_advanced.php",
"http://garagechoppers.com/learning_php/assignment6_advanced.php",
"http://garagechoppers.com/learning_php/assignment5_advanced.php",
"http://garagechoppers.com/learning_php/assignment4_advanced.php");
srand(time());
$count = count($urls);
$result = rand(0,$count);
$in = $urls[$result];
}
header("Location: $in");
}

?>
<HTML>
<HEAD>
<TITLE>ScriptSchool.Com Assignment #8 (basic)</TITLE>
<HEAD>
<BODY bgcolor="666666">

<center><p><b>ScriptSchool.com Assignment 8 (basic)</b><br />
Description of Assignment: Write a script to randomly <br />
choose a URL and redirect the surfer when clicked. Make the <br />
URL a javascript mouseover so that it is a blind link so the <br />
person clicking will not see the result in the browser status <br />
window.</p></center>

<center><a href="http://garagechoppers.com/learning_php/assignment8_basic.phtml?in=rnd"
onMouseOver="window.status='Yes, you really do need to click this'; return true;"
onMouseOut="window.status='';">You really need to click here</a></center>

</body>
</html>


 

 (#836 2005-06-15 07:37:29) Post Reply

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

MY assignment(i don't know what's happening,it gives me the error"expected ';'" )
<script language="javascript"
<a href="http://www.vegyta.3x.ro\dropdown.php?in=http://www.manga-anime.ro
onMouseOver="window.status='Yes, you really do need to click this'; return true;"
onMouseOut="window.status='';">You really need to click here</a>
</script>
<?
if($in != "") {
if ($in == "rnd") {
$url=array("htttp://www.vegyta.3x.ro","http://www.manga-anime.ro","http://www.programare-me.as.ro","http://www.vegyta.ropage.com","http://www.animes.3xforum.ro");
mt_srand(time());
$count = count($urls);
$result = rand(0,$count);
$in = $urls[$result];
}
header("Location: $in");
}


Help Please!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

 (#837 2005-06-15 15:09:44) Post Reply

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

hello,is me again,i've solved my understanding problem.
My basic assignment:
<?
$url=array("http://www.manga-anime.ro","http://www.programare-me.as.ro","http://www.vegyta.ropage.com","http://www.animes.3xforum.ro");
$counts = count($url);
mt_srand(time());
$result =mt_rand(0,$counts-1);
$var=$url[$result];
print("<a href=\"$var\"
onMouseOver=\"window.status='click it now,go go';return true;\"
onMouseOut=\"window.status='';\">link</a>");

?>



 

 (#918 2005-12-31 14:23:44) Post Reply

Dylan
Need To Set


Enrolled: Dec 2005
Posts: 14
AP: 1

Okay, got it, with the exception that the javascript code doesn't seem to work (on mine or anyone else's). I don't know if it's my browsers or a change in some standard... but since I'm focused on PHP at the moment, I'm ignoring it. I had to add this code to the beginning:


<?php

// Write a script to randomly choose a URL and redirect
// the surfer when clicked. Make the URL a javascript
// mouseover so that it is a blind link so the person clicking
// will not see the result in the browser status window.

$newurl = $_GET['in'];
if(
$newurl != "") {
if (
$newurl == 'rnd') {
$urls = array("http://www.babyian.com/",
"http://www.algore.org/",
"http://www.apple.com/",
"http://www.bettersafercare.org/");
mt_srand(time());
$count = count($urls);
$result = mt_rand(0,$count);
$newurl = $urls[$result];
}

header("Location: $newurl");
}
?>
<HTML>
<BODY>
<p>
Click here and
<a href="http://www.algore.org/~admin/redirect.php?in=rnd"
onMouseOver="window.status='Click this link for some uncertainty'; return true;"
onMouseOut="window.status='';">Live a little.</a>
</p>
</BODY>
</HTML>


 

 (#974 2006-03-21 00:34:49) Post Reply

Russell
Need To Set


Enrolled: Mar 2006
Posts: 19
AP: 1

i actually had some trouble with this one. i finally figured out that i really didnt understand what exactly i was trying to do :P i think i got it figured out...


<?
// if $send is empty pick a url to put in the link
if($send == ""){
$urls=array('http://www.cool.com','http://www.sweet.com','http://www.awesome.com');
$num=count($urls)-1;
mt_srand(time());
$rand_num=mt_rand(0,$num);
$send=$urls[$rand_num];
// if $send is not email redirect to the $send url
}else{
header("Location: $send");
}
?>
<a href="http://www.mydomain.com/testing/lesson8.php?send=<? print($send); ?>" onMouseOver="window.status='http://www.fluffydomain.com'; return true;" onMouseOut="window.status='';">Fluffy Stuff</a>


 

 

View Previous Thread
Print this page Print This Page

View Next Thread

School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store

Advertising | Link To Us | Privacy 
Copyright 2000-2002 Script School Productions / KMR Enterprises 
No part of this website may be reproduced, copied and/or distributed in any medium 
without express written permission