Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

This is for the coders of PHP - makes you think...


JamesS

Recommended Posts

Posted

Hello,

 

I am pretty familiar with html and asp and java,(or at least I know enough to get myself in trouble) but until 3 weeks ago I had never even looked at PHP. On some of my other web sites I have a script, used as an SSI include, that I use for testimonials or just for photos to randomly show up on the index page whenever the refresh button is clicked. I have adapted this code so that I can add a advertisements to my index page and I want it to randomly change the ad each time they refresh or come back to the main page or come back another time. The code I use goes something like this:

 

<% Randomize

random = int(RND()*2)

 

ad0 = """http://my site .com/ 1st page"

ad1 = """http://my site .com/ 2nd page"

 

%>

 

<table align="right" width="227">

<tr>

<td align='right'><a href=<%=eval("ad"& random)%>"><img src='ads/adsmall<%=random%>.jpg'></a></td>

</tr>

</table>

 

On my other sites I just call this in using this code: <!-- #include file="ad.asp"--> but that did not work when I added it to index.php.

 

How would I call this code into the index page on a .php page? and will the server execute this properly in osC?

 

Any suggestions? Or should I, instead of making this an include, just write this code into the index.php page?

Posted

Here is a php script (I use) that will show random images

(could be altered to call text files and output to the screen)

 

 

<?php 
#This script has been developped by Nenad Motika [[email protected]]
#Please feel free to use it and to contact me for any reason

/*
A php script that will pick and show a number of random images

Create a folder called random

Put in any number of images you want - the script will find them

Copy, name script "rid.php" and install into the same folder as the images

Sample calls (edit style tags as needed, set to wrap text around it):

<img src="images/random/rid.php?pic=random1" border=0 alt=""style="float:right;padding-left:5px;padding-right:5px;padding-bottom:5px;padding-top:5px;background:white;border:1px solid white;">

to add more than one image just call it as pic=random2, pic=random3, pic=random4, etc....

*/


//read folder
$folder=opendir("."); 
while ($file = readdir($folder)) 
$names[count($names)] = $file; 
closedir($folder);
//sort file names in array
sort($names);
//remove any non-images from array
$tempvar=0;
for ($i=0;$names[$i];$i++){
$ext=strtolower(substr($names[$i],-4));
if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png"){$names1[$tempvar]=$names[$i];$tempvar++;}
}
//random
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($names1, 2);
//random image from array
$slika=$names1[$rand_keys[0]]; 
//image dimensions
$dimensions = GetImageSize($slika); 
if (isset($HTTP_GET_VARS["pic"])){header ("Location: $slika");}
else {echo "<img src=\"$slika\" $dimensions[3]>";}
?>

Posted

Great! I just added this and it works perfectly, but there is a catch. (As I mentioned before I had never seen PHP prior to osC.) I would also like this code to allow me to add hrefs to the ads so that a user can click the image and be take straight to the buy it page. So how do you intergrate href into this so that it will add the proper link to the right ad?

 

Can anyone provide the code to allow this option???

 

Here is a php script (I use) that will show random images

(could be altered to call text files and output to the screen)

<?php 
#This script has been developped by Nenad Motika [[email protected]]
#Please feel free to use it and to contact me for any reason

/*
A php script that will pick and show a number of random images

Create a folder called random

Put in any number of images you want - the script will find them

Copy, name script "rid.php" and install into the same folder as the images

Sample calls (edit style tags as needed, set to wrap text around it):

<img src="images/random/rid.php?pic=random1" border=0 alt=""style="float:right;padding-left:5px;padding-right:5px;padding-bottom:5px;padding-top:5px;background:white;border:1px solid white;">

to add more than one image just call it as pic=random2, pic=random3, pic=random4, etc....

*/
//read folder
$folder=opendir("."); 
while ($file = readdir($folder)) 
$names[count($names)] = $file; 
closedir($folder);
//sort file names in array
sort($names);
//remove any non-images from array
$tempvar=0;
for ($i=0;$names[$i];$i++){
$ext=strtolower(substr($names[$i],-4));
if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png"){$names1[$tempvar]=$names[$i];$tempvar++;}
}
//random
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($names1, 2);
//random image from array
$slika=$names1[$rand_keys[0]]; 
//image dimensions
$dimensions = GetImageSize($slika); 
if (isset($HTTP_GET_VARS["pic"])){header ("Location: $slika");}
else {echo "<img src=\"$slika\" $dimensions[3]>";}
?>

Posted
Great! I just added this and it works perfectly, but there is a catch. (As I mentioned before I had never seen PHP prior to osC.) I would also like this code to allow me to add hrefs to the ads so that a user can click the image and be take straight to the buy it page. So how do you intergrate href into this so that it will add the proper link to the right ad?

 

Can anyone provide the code to allow this option???

 

That is a totally different animal...you will need to install the featured products mod. I use this also. After it is set up you just add products to the featured list, set it to show up on the front page - works great.

 

http://www.oscommerce.com/community/contri...search,featured

Posted
That is a totally different animal...you will need to install the featured products mod. I use this also. After it is set up you just add products to the featured list, set it to show up on the front page - works great.

 

http://www.oscommerce.com/community/contri...search,featured

 

That mod is not exactly what i am looking for. I like to new products for [month] mod, and I really am looking for a way to basically have a rotating banner/ or advertisement in the main text. thanks though.

(That makes me think if I just adjust the banner coding it may work, but I do not even know where to locate it.)

 

I like this addition you gave me, I imagine it would not be that hard add the HREF to the random code. The code in ASP i put at the top works excellently for this use on HTML pages. ( I also just thought that I could add text at the bottom of the ad and make that the link... )

  • 3 months later...
Posted
Here is a php script (I use) that will show random images

(could be altered to call text files and output to the screen)

<?php 
#This script has been developped by Nenad Motika [[email protected]]
#Please feel free to use it and to contact me for any reason

/*
A php script that will pick and show a number of random images

Create a folder called random

Put in any number of images you want - the script will find them

Copy, name script "rid.php" and install into the same folder as the images

Sample calls (edit style tags as needed, set to wrap text around it):

<img src="images/random/rid.php?pic=random1" border=0 alt=""style="float:right;padding-left:5px;padding-right:5px;padding-bottom:5px;padding-top:5px;background:white;border:1px solid white;">

to add more than one image just call it as pic=random2, pic=random3, pic=random4, etc....

*/
//read folder
$folder=opendir("."); 
while ($file = readdir($folder)) 
$names[count($names)] = $file; 
closedir($folder);
//sort file names in array
sort($names);
//remove any non-images from array
$tempvar=0;
for ($i=0;$names[$i];$i++){
$ext=strtolower(substr($names[$i],-4));
if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png"){$names1[$tempvar]=$names[$i];$tempvar++;}
}
//random
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($names1, 2);
//random image from array
$slika=$names1[$rand_keys[0]]; 
//image dimensions
$dimensions = GetImageSize($slika); 
if (isset($HTTP_GET_VARS["pic"])){header ("Location: $slika");}
else {echo "<img src=\"$slika\" $dimensions[3]>";}
?>

 

 

Does anyone know how I could manipulate this code to pull a *.txt, *.htm, *.html file rather than images - as it states at the top of the quote? My PHP skills are not the greatest and I have been trying to manipulate this code for some time now by myself. (just 'guessing' and 'stare and compare' methodology) Currently I am using this code to pull random images, but I thought it would be better utilized if I pulled a *.txt file with an image coded within it and wording rather than just blindly pulling an image only and having static text around it.

 

I also would need to know what code to enter in order to ('require') this new code since I will not be using: <img src="images/random/rid.php?pic=random1" border=0 alt=""style="float:right;padding-left:5px;padding-right:5px;padding-bottom:5px;padding-top:5px;background:white;border:1px solid white;"> to pull the *.txt files. Would I use:

require('DIR_WS_FOLDERNAME . 'filename.php'); or

require('images/FOLDERNAME/FILENAME.php');

"if I was hosting the folder in /images/" OR am I way off base with these two require elements?

 

Thanks in advance for any support you can offer.

Posted
What exactly - specifically do you want to do?

 

 

Well - I would like to break the index.php page into half or maybe thirds. Then use this code in 3 different folders with multiple pages in each. Utilizing this code to pull *.txt files that would include a photo or two of my products with my desired text around it. An example of a page it would call is:

<tr><td>my text and a photo</td></tr>

Each time the index.php page is reloaded a new topic/category/product would be opened in that 1/3 of the page highlighting variuos products with text as well. (an attempt to interest the visitor more).

 

The site I got the idea from was Amazon.com when you go to the homepage the top category shows an image with text, the second 1/3rd shows another category, and then it repeats this another time below that. Every time you hit "refresh" it brings up a new category or image with text.

 

Would this bog the server down too much or is there a better way to handle this?

 

When you first gave this to me the intent was to pull random images into the homepage, which I currently do, using them as banners. Instead - I am utilizing the banner module to do this and would like to alter this code to randomize content rather than pics.

Posted

OK, so if I got it right, you want to show (in 3 locations) a picture with custom text

 

I suggest that you start with the feature items mod found at

http://www.oscommerce.com/community/contributions,651/

 

Make 3 of them (3 different names - feature1.php, feature2.php and feature3.php), add 3 extra text columns to the products_description table (call them extra_text1, extra_text2 & extra_text3), add these new tables to the admin/categories.php script, so you can edit them.

 

You will need to repeat the feature mod 3 times in both the catalog and admin area

Posted
OK, so if I got it right, you want to show (in 3 locations) a picture with custom text

 

I suggest that you start with the feature items mod found at

http://www.oscommerce.com/community/contributions,651/

 

Make 3 of them (3 different names - feature1.php, feature2.php and feature3.php), add 3 extra text columns to the products_description table (call them extra_text1, extra_text2 & extra_text3), add these new tables to the admin/categories.php script, so you can edit them.

 

You will need to repeat the feature mod 3 times in both the catalog and admin area

 

which version are you recommending?

Posted
which version are you recommending?

 

 

Thanks for your help on this.

 

Do you think you could still share the script with me for how to pull files rather than images, so that I can have it in my files?

Posted
Thanks for your help on this.

 

Do you think you could still share the script with me for how to pull files rather than images, so that I can have it in my files?

 

Version -> Featured Products 1.5.8 Complete Pack

 

I can give you a helping hand to get the Featured Products mod going how you want...no promises

 

If you want to create text files and manually set everything try this code (already to go) from Javier Valderrama

 

<?php
/* ***************************************************************
Jaxolotl Design

Simple Random Frase includer
PHP programming: Javier Valderrama

Developed for Jaxolotl Design - www.jaxolotl-design.com

Files extensions supported txt|html|htm|php| and adding extra hand made code you can include files link images or somenthing else....LOL

Enjoy :)

Please don't remove this lines, I think it's a very low price and a way to say TNX if it's usefull for you;)
*************************************************************** */


$txt_array = Array();
$my_dir = "myDir/";   //Replace it with your frase's directory (dont'n delete the slash)
if ($dir = @opendir("$my_dir")) {

	  while (($file = readdir($dir)) !== false) { 
		   if ($file != "." && $file != ".."  && !is_dir($my_dir.$file)) 
				   {
				   /* echo $my_dir.$file."<br>";  DEBUG show file list */
				   $txt_array[] = $file;

				   } 
	  }  
  closedir($dir);
}

$random_number=rand(0, count($txt_array)-1); 
$random_txt=$txt_array[$random_number];

//This code includes the text file file
include($my_dir.$random_txt);

//This code show a random image
// echo "<img src=\"".$my_dir.$random_txt."\" border=\"0\" alt=\"\">";
?>

Posted
Version -> Featured Products 1.5.8 Complete Pack

 

I can give you a helping hand to get the Featured Products mod going how you want...no promises

 

If you want to create text files and manually set everything try this code (already to go) from Javier Valderrama

 

Thanks for all your help. I am going to give the Featured Products Mod a go and see if I can install it. I appreciate everything.

 

Have a great day.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...