Forums / Templates, Stylesheets, Page Layout / Randomizing the header_bg image

Randomizing the header_bg image

Locked

Views: 2,325

Results 1 to 13 of 13
This thread is locked. New replies are disabled.
30 Aug 2007, 8:17 PM
#1
atomickarma avatar

atomickarma

New Zenner

Join Date:
Aug 2007
Posts:
9
Plugin Contributions:
0

Randomizing the header_bg image

hi

I'm having issues setting the header_bg image to randomize.

I've tried both the css method and the src= method, with three different php random scripts, and non of them works.

Alt text shows, so I know I have the file paths correct. There's no instruction with any of the scripts regarding permissions (I have the php files in the templates/CUSTOM/images folder and the css files in the templates/CUSTOM/css file) so I wonder if this is the issue?

I wonder if anyone has any suggestions?

Thanks
Christian

30 Aug 2007, 9:23 PM
#2
brandtim avatar

brandtim

Zen Follower

Join Date:
Apr 2006
Posts:
250
Plugin Contributions:
0

Re: Randomizing the header_bg image

If the alt text is showing, most likely the file paths are NOT correct.

Do you have a link?

BrandTim

30 Aug 2007, 9:50 PM
#3
atomickarma avatar

atomickarma

New Zenner

Join Date:
Aug 2007
Posts:
9
Plugin Contributions:
0

Re: Randomizing the header_bg image

brandtim:

If the alt text is showing, most likely the file paths are NOT correct.

Do you have a link?

BrandTim

indeed:

http://www.fairytalemail.co.uk/index.php

31 Aug 2007, 2:00 AM
#5
brandtim avatar

brandtim

Zen Follower

Join Date:
Apr 2006
Posts:
250
Plugin Contributions:
0

Re: Randomizing the header_bg image

Taking a brief look at your code, the img src is this:
http://www.fairytalemail.co.uk/includes/templates/santa/css/templates/santa/images/header/rotate.php

but you want it to be this:
http://www.fairytalemail.co.uk/includes/templates/santa/images/header/header_bg.jpg

Not sure exactly why you're trying to use a php file as the src for an image (although it can be done). It would be much better if you called the php file which then either returned or echoed the src URL.

Regardless, your file path is definitely not what you want it to be.

BrandTim

31 Aug 2007, 7:22 PM
#6
atomickarma avatar

atomickarma

New Zenner

Join Date:
Aug 2007
Posts:
9
Plugin Contributions:
0

Re: Randomizing the header_bg image

I'm not sure where you're getting the

http://www.fairytalemail.co.uk/includes/templates/santa/css/templates/santa/images/header/rotate.php

from, as I can't find that anywhere.

Not sure why I was rambling about the alt text, however, what I meant to say was that attempting to open

http://www.fairytalemail.co.uk/includes/templates/santa/images/header/image.php

gives me a 403 error - I expect that this is right, and the filepath is right. It's the same file in the src: includes/templates/santa/images/header/image.php - and the same location as http://www.fairytalemail.co.uk/includes/templates/santa/images/header/header_bg.jpg which of course opens.

That's why I suspected a permissions issue in the firstplace, as there seems to be no fauilt with the filepaths

31 Aug 2007, 8:00 PM
#7
atomickarma avatar

atomickarma

New Zenner

Join Date:
Aug 2007
Posts:
9
Plugin Contributions:
0

Re: Randomizing the header_bg image

I should also add that I've now tried this method:

<?php $random_imgs = array('header_bg.jpg', 'header_bg2.jpg'); $random_img = $random_imgs[rand(0, 1)]; ?>

<img src="includes/templates/santa/images/<?php echo $random_img; ?>" width="369" height="176" alt="Welcome to FairytaleMail's Christmas Pages!" /></div>

</div>

if I change the <?php echo $random_img; ?> and replace it with header_bg.jpg, I see the image; the filepath works.

It seems that whenever I attempt to use any kind of script to randomise the images, zencart stops me. I've determined that it is a permissions issue, but I don't have much experience with these, and don't know where to start

31 Aug 2007, 8:04 PM
#8
atomickarma avatar

atomickarma

New Zenner

Join Date:
Aug 2007
Posts:
9
Plugin Contributions:
0

Re: Randomizing the header_bg image

In fact I seem to have solved it - I've changed the permissions on define_main_page.php (where the script in the last post was housed) to 755, and this seems to have scratched it

Cheers for the suggestion regarding how I was handling the php, brandtim!

1 Sep 2007, 3:19 PM
#9
brandtim avatar

brandtim

Zen Follower

Join Date:
Apr 2006
Posts:
250
Plugin Contributions:
0

Re: Randomizing the header_bg image

Do not leave your html_includes files at 755! See here.

ZenCart does not have the power to stop you from using a randomizer on your images. No CMS does. That was not what was going on.

I was getting the link:
http://www.fairytalemail.co.uk/includes/templates/santa/css/templates/santa/images/header/rotate.php
from HTML source code of your site. That was literally where the src of the image was pointed.

The 403 error when trying to access this file:
http://www.fairytalemail.co.uk/includes/templates/santa/images/header/image.php
via HTTP is correct. No remote user should be able to execute PHP scripts from within the includes directory. If that worked it would pose a serious security risk.

This is not a permissions issue - this is an execution issue. You were trying to have the src of your image point to a PHP file which would then respond with an image (NOT an image URL). While this is possible in certain scenarios, this is a bad idea when working with CMSs.

I suspect (but am not 100% certain) that the problem you were having with the randomizer PHP code in define_main_page.php is that it never got to the server. If your permissions were set to 444 or perhaps 644, depending on how you were trying to put the file on the server, the server was rejecting the file and it was remaining unchanged. Changing the permissions to 755 allowed you to over-write the file with your changes and that is what allowed it to work.

Be sure to change the permissions back to 644! In fact, I'd highly and strongly recommend going through all of the security recommendations on the page linked to above ASAP.

BrandTim

1 Sep 2007, 5:37 PM
#10
atomickarma avatar

atomickarma

New Zenner

Join Date:
Aug 2007
Posts:
9
Plugin Contributions:
0

Re: Randomizing the header_bg image

Cheers sport - I do have one problem though - locking down the images folder effectively rewrites my layout, is there any way around this?

1 Sep 2007, 8:47 PM
#11
brandtim avatar

brandtim

Zen Follower

Join Date:
Apr 2006
Posts:
250
Plugin Contributions:
0

Re: Randomizing the header_bg image

If your server is correctly configured, changing the permissions on the images/ directory from 777 to 644 will have no impact on the layout of your site. Can you post screencaps showing the two layouts? That way maybe we can get a sense of what's happening.

BrandTim

6 Jun 2008, 10:09 AM
#12
mreateg avatar

mreateg

New Zenner

Join Date:
May 2008
Posts:
6
Plugin Contributions:
0

Re: Randomizing the header_bg image

This worked out pretty sweet for me:

<?php $random_imgs = array('images/ban1.jpg', 'images/ban1b.jpg', 'images/ban1c.jpg'); $random_img = $random_imgs[rand(0, 2)];?> <?=zen_image(DIR_WS_TEMPLATE.$random_img)?>
6 Jun 2008, 10:33 AM
#13
kitcorsa avatar

kitcorsa

Totally Zenned

Join Date:
Feb 2007
Posts:
1,724
Plugin Contributions:
0

Re: Randomizing the header_bg image

you could also set a advert banner as your header image then add them from admin, then you can also get them to link to a special or an item etc then you can also see if they been clicked from you admin!!!

this is what im doing!!! :D