homepage Welcome to WebmasterWorld Guest from 54.204.64.152
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP Rotator for loading different include.php file
AlexB77




msg:4426745
 1:11 am on Mar 9, 2012 (gmt 0)

Hi,

I am trying to create a simple rotator that will randomly load iclude1.php on the first load then include2.php on the second load or if refreshed then include3.php and so on and on.

What I am actually trying to achieve is: I have few difrent adds scripts in separate php files that I would like to change every time when page is being loaded or reloaded.

Thanks for you help in advance

 

incrediBILL




msg:4426757
 2:04 am on Mar 9, 2012 (gmt 0)

Is your goal site wide or per visitor?

Per visitor is pretty easy, just track the current counter in a session variable and increment the session variable each time a page is loaded.

Site wide is equally as easily, just track the current counter in a flat file or in a MySQL database. Read it, increment it, write it back out, then display the appropriate file for the current count.

AlexB77




msg:4426886
 9:56 am on Mar 9, 2012 (gmt 0)

Thanks for you respond to my question, in theory it makes sense to me, but when it comes to coding, I am a bit slow on PHP. any chance of helping me out?

here is what I have:

/includes/file1.php ... file2.php ... file3.php

so at this stage I simply use the following line where I am including one of the files above

<?php include("/var/www/vhosts/testdomain.com/httpdocs/includes/file1.php");?>

so the question is how to accommodate all of the above files in this one line so that wen page is loaded or reloaded then above line will include file2.php or file3.php insted of file1.php?

any help is appreciated as always.

incrediBILL




msg:4426912
 10:35 am on Mar 9, 2012 (gmt 0)

The code would probably look something like this, I didn't test it...

session_start();

if (isset($_SESSION['cnt'])){
$_SESSION['cnt'] += 1;
if( $_SESSION['cnt'] > 3 ) $_SESSION['cnt'] =1;
}else {
$_SESSION['cnt'] =1;
}

include("/var/www/vhosts/testdomain.com/httpdocs/includes/file" . $_SESSION['cnt'] . ".php");

The above should display files 1 thru 3.

AlexB77




msg:4426940
 12:20 pm on Mar 9, 2012 (gmt 0)

Sweet, works as intended, thanks a million.

Security wise, how secure to use this script on the regular html output page?

incrediBILL




msg:4427032
 4:16 pm on Mar 9, 2012 (gmt 0)

thanks a million.


A bit more compensation than it's probably worth, but I'll accept it in small denomination unmarked bills.

Shouldn't have any security issues.

AlexB77




msg:4435653
 6:53 pm on Mar 31, 2012 (gmt 0)

Hi again,

All through the script works fine, but I have started to get an errors like the one below:


[Sat Mar 31 12:47:18 2012] [error] [client 000.000.000.00] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /var/www/vhosts/test_site.com/httpdocs/some_files/file.html:50) in /var/www/vhosts/test_site.com/httpdocs/some_files/file.html on line 55, referer: [test_site.com...]


[Sat Mar 31 12:47:29 2012] [error] [client 000.000.000.00] PHP Notice: A session had already been started - ignoring session_start() in /var/www/vhosts/test_site.com/httpdocs/some_files/file_1.html on line 67, referer: [test_site.com...]


any ideas as to why this has been happening?

g1smd




msg:4435739
 12:08 am on Apr 1, 2012 (gmt 0)

Maybe you have session_start() stated more than once in your file.

Indeed the code snippet above that you added has one, but maybe you already had one in your file.

enigma1




msg:4435822
 10:25 am on Apr 1, 2012 (gmt 0)

Could happen if some of your files invoked before the session_start output something. In many cases it accidentally happens by leaving blank lines outside the php tags in files (like at the start of the file).

AlexB77




msg:4435847
 2:06 pm on Apr 1, 2012 (gmt 0)

Thanks for your response, I have placed the following to the beginning of the page and it seems that this has resolved the error in logs.
<?php
if (!isset($_SESSION)) {
session_start();
}
?>


but now I am facing slightly different problem with headers that are being sent of the following character:
Set-Cookie:PHPSESSID=ac588btkl03a3t7g9tjb8dvun6; path=/
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control:no-cache, no-store, must-revalidate, post-check=0, pre-check=0
Pragma:no-cache


and in reality what I'd like to have instead is simple


Cache-Control:max-age=21600
Expires:Sun, 01 Apr 2012 20:03:21 GMT


I should probably use some other method rather then session_start() to do what I need, but have run out of ides because of my poor knowledge of php.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved