
|
View Full Version : Can anyone see what is wrong with this code?
Johnburk 11-04-2005, 12:07 PM Can anyone see what is wrong with this code?
<?php
$random_integer = rand(1,2);
if (is_int($random_integer / 2)) {
$random_integer = rand(0,10); // Assumes you have images from image0 to image10
echo "<img src=\"http://www.domain.com/image", $random_integer, ".jpg\"></img>"; //point to the correct domain/folder, this assumes .jpg but can be easily changed
}
else {
$random_integer = rand(0,10); // Assumes you have flashs from flash0 to flash10
echo "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"";
echo "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0\"";
echo "id=\"Main\" width=\"269\" height=\"367\">";
echo "<param name=\"movie\" value=\"flash", $random_integer, ".swf\">";
echo "<param name=\"bgcolor\" value=\"#FFFFFF\">";
echo "<param name=\"quality\" value=\"high\">";
echo "<param name=\"allowscriptaccess\" value=\"samedomain\">";
echo "<embed type=\"application/x-shockwave-flash\"";
echo "pluginspage=\"http://www.macromedia.com/go/getflashplayer\"";
echo "width=\"269\" height=\"367\"";
echo "name=\"Main\" src=\"flash", $random_integer, ".swf\"";
echo "bgcolor=\"#FFFFFF\" quality=\"high\"";
echo "swLiveConnect=\"true\" allowScriptAccess=\"samedomain\"";
echo "></embed>";
echo "</object>";
}
?>
Burhan 11-04-2005, 12:12 PM What is it not doing?
Johnburk 11-04-2005, 12:45 PM It should display a image file or flash file at random, but it does not do anything.
BurakUeda 11-04-2005, 12:50 PM You are using commas to add strings, you must use dot instead ;)
<?php
$random_integer = rand(1,2);
if (is_int($random_integer / 2)) {
$random_integer = rand(0,10); // Assumes you have images from image0 to image10
echo "<img src=\"http://www.domain.com/image". $random_integer.".jpg\"></img>"; //point to the correct domain/folder, this assumes .jpg but can be easily changed
}
else {
$random_integer = rand(0,10); // Assumes you have flashs from flash0 to flash10
echo "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"";
echo "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0\"";
echo "id=\"Main\" width=\"269\" height=\"367\">";
echo "<param name=\"movie\" value=\"flash".$random_integer.".swf\">";
echo "<param name=\"bgcolor\" value=\"#FFFFFF\">";
echo "<param name=\"quality\" value=\"high\">";
echo "<param name=\"allowscriptaccess\" value=\"samedomain\">";
echo "<embed type=\"application/x-shockwave-flash\"";
echo "pluginspage=\"http://www.macromedia.com/go/getflashplayer\"";
echo "width=\"269\" height=\"367\"";
echo "name=\"Main\" src=\"flash".$random_integer.".swf\"";
echo "bgcolor=\"#FFFFFF\" quality=\"high\"";
echo "swLiveConnect=\"true\" allowScriptAccess=\"samedomain\"";
echo "></embed>";
echo "</object>";
}
?>
Johnburk 11-04-2005, 01:13 PM @BurakUeda
Thank you
I don't really understand what you mean. It is not my code and I don't know much about php, someone else made it, but it is not working.
I tried your quoute, but still it is not working :(
serversphere 11-04-2005, 01:20 PM this line
echo "<img src=\"http://www.domain.com/image", $random_integer, ".jpg\"></img>";
should look like this line
echo "<img src=\"http://www.domain.com/image". $random_integer. ".jpg\"></img>";
The periods within the echo are right.
:)
If it's still not working then something else is wrong. Is the script being run within the same directory as the flash files?
Johnburk 11-04-2005, 01:21 PM Thank you, I changed that. Yet the script is not working :(
I have PHP version 4.4.1, maybe that is the problem
Neoboffin 11-04-2005, 01:27 PM You are naming your flash files and images as;
image0.jpg, image1.jpg, etc
and
flash0.swf, flash1.swf, etc
Right?
BurakUeda 11-04-2005, 01:29 PM Hmmm..
Some questions:
Where is your images and flash files, I mean folder names.
And did you actually put your own url instead of "domain.com" ?
Johnburk 11-04-2005, 02:39 PM Yes I put my own url,
Flash files are names flash01.swf flash1.swf etc.
They are both in root directory and /image directory (just to be sure)
Johnburk 11-04-2005, 02:46 PM I also tried the following code, but get the following in my error log
"File does not exist: /home/website/public_html/test/<"
<?php
$r_swf[]="flash0.swf"
$r_swf[]="flash1.swf"
$r_swf[]="flash2.swf"
$swf = $r_swf[ rand(0,2) ];
?>
<embed name="Movie1" src="<? echo $swf; ?>" quality="high" bgcolor="#FFFFFF"
width="269" height="367"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</embed>
Neoboffin 11-04-2005, 03:09 PM Do this.
Get all your '.swf' files and place them in a new directory. Now copy and paste the below codeand save the file as a .php, now upload this to the same directory as the .swf files are in.
<?php
$random_number = rand(1,9);
echo '<object width="550" height="400">
<param name="movie" value="flash' . $random_number . '.swf">
<embed src="flash' . $random_number . '.swf" width="550" height="400">
</embed>
</object>';
?>
For this to work, there SHOULD be 9 .swf's in the directory called "flash1.swf" and "flash2.swf" etc. You can rename flash to whichever you want. Just make sure you change it in the PHP code. If this does not work (which is should) I'm a little stumped.
Johnburk 11-04-2005, 03:11 PM @Neoboffin
Thank you. I will test this
How can I add the php file into my html page?
BurakUeda 11-04-2005, 03:12 PM $swf = $r_swf[ rand(0,2) ]; // get rid of the spaces:
$swf = $r_swf[rand(0,2)];
Neoboffin 11-04-2005, 03:16 PM Well you can either;
Create an IFrame:
<iframe src="myflash.php" width="550" height="400" scrolling="no" frameborder="0">Sorry, your browser does not support IFrames!</iframe>
Or add the following code into your .htaccess file:
AddType x-httpd-php .html .htm
The above code will allow your .htm and .html pages to be executed as .PHP pages.
Johnburk 11-04-2005, 03:28 PM @Neoboffin
This is working :D :D :D
Thank you
Neoboffin 11-04-2005, 03:33 PM No problem.
However, just so you know, using as little code as possible for the flash file is not really recommended, but still works. You may wish to add your own param names to it.
innova 11-07-2005, 11:58 AM Also,
Dont echo out blocks of static html.. its a lot cleaner to jump in and out of php mode when convenient inside the HTML document.
|