Jump to content

Recommended Posts

I want to random show a banner on my site. I know there are a lot of scripts out there but i wanted to tweak one for my own use. the thing is I have both flash banners and animated gifs. I need help writing an if statement that checks the file that is randomly picked and echo's the correct tag (image or object) here is what I have so far.

 

<?php

$banners = array(
"http://www.website.com,images/banner1.gif",
"http://www.example.com,flash/banner2.swf",
);


$randnum = rand(0, count($banners) - 1); 
$exploded = explode(",", $banners[$randnum]); 

$url = $exploded[0]; // Grab the URL for the banner
$img = $exploded[1]; // Grab the image for the banner

if ($img  has ".gif")   //this is were I am not sure of the syntax
{
echo "<a href=\"$url\">";
echo "<img src=\"$img\" border=\"0\" />";
echo "</a>";
} else
{
echo "flash movie tag "
}

?>

Link to comment
https://forums.phpfreaks.com/topic/114667-random-banner/
Share on other sites

in the first if statement i want to check if the file name has .gif in it. if so echo the <img> tag with the random chosen banner ad.

 

if it does not have a .gif in the file name that means it is a .swf so I thought I could just use an else statement and then echo the flash object and embed tag with the random file name.

 

 

Link to comment
https://forums.phpfreaks.com/topic/114667-random-banner/#findComment-589693
Share on other sites

this is what i have so far.

 

<?php

$banners = array(
"http://www.website.com,images/Banner4.gif",
"http://www.example.com,images/BANNER6.swf",
);



$randnum = rand(0, count($banners) - 1); // Choose a random banner
$exploded = explode(",", $banners[$randnum]); // Separate chosen banner by ,

$url = $exploded[0]; // Grab the URL for the banner
$img = $exploded[1]; // Grab the image for the banner

if(stristr($img, '.gif') === FALSE) {
echo "<object id=\"OGBanner\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"468\" height=\"60\">";
echo "<param name=\"movie\" value=\"$img\" />";
echo       "<!--[if !IE]>-->";

echo        "<object type=\"application/x-shockwave-flash\" data=\"images/BANNER6.swf\" width=\"468\" height=\"60\">";
echo        "<!--<![endif]-->";
echo          "<p><a href=\"http://www.stratacahce.com/!0_OGWP.php\">Click for Organic Growth White Paper</a></p>";
echo        "<!--[if !IE]>-->";
echo        "</object>";
echo       "<!--<![endif]-->";
echo      "</object>";
}else {
echo "<a href=\"$url\">";
echo "<img src=\"$img\" border=\"0\" />";
echo "</a>";
?>

 

 

I am saving this file as banners.php and including it in my html with

<?php include("banners.php"); ?>

 

the only thing showing in the banner spot is "; echo "  ???

Link to comment
https://forums.phpfreaks.com/topic/114667-random-banner/#findComment-589794
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.