Results 1 to 18 of 18
  1. #1
    Join Date
    Nov 2004
    Posts
    673

    Question Can anyone see what is wrong with this code?

    Can anyone see what is wrong with this code?


    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>";
    }
    ?>
    Just imagine, if the world was like an online community. Where people help each other, just because they can.

  2. #2
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    What is it not doing?
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  3. #3
    Join Date
    Nov 2004
    Posts
    673
    It should display a image file or flash file at random, but it does not do anything.
    Just imagine, if the world was like an online community. Where people help each other, just because they can.

  4. #4
    Join Date
    Oct 2004
    Location
    Shimonoseki
    Posts
    2,101
    You are using commas to add strings, you must use dot instead

    PHP 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>";
    }
    ?>
    Closed for winter...

  5. #5
    Join Date
    Nov 2004
    Posts
    673
    @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
    Just imagine, if the world was like an online community. Where people help each other, just because they can.

  6. #6
    Join Date
    Mar 2004
    Location
    New Jersey
    Posts
    793
    this line
    Code:
    echo "<img src=\"http://www.domain.com/image", $random_integer, ".jpg\"></img>";
    should look like this line
    Code:
    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?

  7. #7
    Join Date
    Nov 2004
    Posts
    673
    Thank you, I changed that. Yet the script is not working

    I have PHP version 4.4.1, maybe that is the problem
    Just imagine, if the world was like an online community. Where people help each other, just because they can.

  8. #8
    Join Date
    Mar 2005
    Location
    Derby, UK
    Posts
    219
    You are naming your flash files and images as;

    image0.jpg, image1.jpg, etc

    and

    flash0.swf, flash1.swf, etc

    Right?

  9. #9
    Join Date
    Oct 2004
    Location
    Shimonoseki
    Posts
    2,101
    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" ?
    Closed for winter...

  10. #10
    Join Date
    Nov 2004
    Posts
    673
    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)
    Just imagine, if the world was like an online community. Where people help each other, just because they can.

  11. #11
    Join Date
    Nov 2004
    Posts
    673
    I also tried the following code, but get the following in my error log


    Code:
    "File does not exist: /home/website/public_html/test/<"

    PHP Code:
    <?php 
    $r_swf
    []="flash0.swf" 
    $r_swf[]="flash1.swf" 
    $r_swf[]="flash2.swf" 
    $swf $r_swfrand(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>
    Just imagine, if the world was like an online community. Where people help each other, just because they can.

  12. #12
    Join Date
    Mar 2005
    Location
    Derby, UK
    Posts
    219
    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 Code:
    <?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.

  13. #13
    Join Date
    Nov 2004
    Posts
    673
    @Neoboffin

    Thank you. I will test this

    How can I add the php file into my html page?
    Just imagine, if the world was like an online community. Where people help each other, just because they can.

  14. #14
    Join Date
    Oct 2004
    Location
    Shimonoseki
    Posts
    2,101
    $swf = $r_swf[ rand(0,2) ]; // get rid of the spaces:
    $swf = $r_swf[rand(0,2)];
    Closed for winter...

  15. #15
    Join Date
    Mar 2005
    Location
    Derby, UK
    Posts
    219
    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.

  16. #16
    Join Date
    Nov 2004
    Posts
    673
    @Neoboffin
    This is working

    Thank you
    Just imagine, if the world was like an online community. Where people help each other, just because they can.

  17. #17
    Join Date
    Mar 2005
    Location
    Derby, UK
    Posts
    219
    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.

  18. #18
    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.
    "The only difference between a poor person and a rich person is what they do in their spare time."
    "If youth is wasted on the young, then retirement is wasted on the old"

Posting Permissions

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