Page 1 of 2
Rotate Different Copyrighted Content
Posted: Wed Aug 31, 2005 2:25 am
by nparekh
Hi guys
I added some php include statements into my main site pages and the include statements call a file called article.inc.
What I would like to do is rotate different articles on my site - I have written over 50 articles and would like to rotate them so its fresh content everytime someone visits.
At present I have <!--#include virtual="article.inc" --> on my main page.
Any ideas how I would get it to call for example article1.inc, article2.inc up to say article50.inc - all are which my own articles?
Thanks in advance
Nikhil
Posted: Wed Aug 31, 2005 2:34 am
by William
Code: Select all
<?php
$art = mt_rand(0, 50);
if($art == "0") {
echo "<!--#include virtual=\"article.inc\" -->";
} else {
echo "<!--#include virtual=\"article" . $art . ".inc\" -->";
}
?>
Would that help?
Posted: Wed Aug 31, 2005 2:40 am
by nparekh
Hi there
I am new to php so I will give that a try:)
I did notice one thing though - it checks if $art==0 but how does it know to go to article1.inc etc up to article50.inc?
I don't see a counter - or maybe thats the way the code is supposed to be?
Thanks again
Nikhil
Posted: Wed Aug 31, 2005 2:59 am
by n00b Saibot
This piece of code returns a random number between 0 and 50 and assigns it to $art variable.
Code: Select all
if($art == "0") {
echo "<!--#include virtual=\"article.inc\" -->";
} else {
echo "<!--#include virtual=\"article" . $art . ".inc\" -->";
}
This piece checks if $art equals 0 then includes article.inc else includes article(num).inc...
Posted: Wed Aug 31, 2005 2:59 am
by William
mt_rand() is a function to randomly pick from number 0,50. I basicly said if it is 0 then don't add the number because its not article.inc its article.inc

Posted: Wed Aug 31, 2005 3:03 am
by nparekh
Thank You!
As I said I am new to PHP but am trying to learn quickly:)
I will try out this code and post back results over the next few days.
Thanks again!!
Regards,
Nikhil
Posted: Wed Aug 31, 2005 3:05 am
by William
No problem. Also that is not a PHP include. To include using PHP you need to do the following:
Code: Select all
<?php
include("filename.ext");
?>
and if you want to do that with my code use this:
Code: Select all
<?php
$art = mt_rand(0, 50);
if($art == "0") {
include("article.inc");
} else {
include("article" . $art . ".inc");
}
?>
Posted: Wed Aug 31, 2005 3:31 am
by nparekh
Hi William
I can't use <?PHP ?> on my server as it only supports SSI coding for PHP. So thats why I use <!--#include virtual="article.inc" -->
How would I modify that code to work with the code you provided?
Thanks again
Nikhil
Posted: Wed Aug 31, 2005 3:34 am
by William
Sorry I do not know SSI very well. Sorry I can't help you any further.
Posted: Wed Aug 31, 2005 3:47 am
by n00b Saibot
nparekh wrote:How would I modify that code to work with the code you provided?
The original code will work for you just fine... use that.
Posted: Wed Aug 31, 2005 3:48 am
by William
Yes but if he can't use <?php ?> at all then he can't use anything I provided.
Posted: Wed Aug 31, 2005 4:06 am
by n00b Saibot
nparekh wrote:as it only supports SSI coding for PHP.

Posted: Wed Aug 31, 2005 4:07 am
by William
I can't use <?PHP ?> on my server as it only supports SSI coding for PHP.

Update
Posted: Fri Sep 09, 2005 12:07 am
by nparekh
Hi guys,
Thanks again for your help with this but I am having some trouble getting anything to display on my main site. I have created a file called rotate.php which contains the following:
<?php
$art = mt_rand(0, 50);
if($art == "0") {
include("test.txt");
} else {
include("test" . $art . ".txt");
}
?>
When I open up the rotate.php in a browser the articles rotate e.g test28.txt etc
However when I try the following in a file included on my main site I get a blank space i.e nothing is displayed in the area where it should be displaying the test*.txt
<!--#include virtual="/rotate.php" -->
I've even tried <!--#include virtual="rotate.php" -->- without the trailing
Any ideas please?
Thanks in advance
Regards,
Nikhil
Problem with code
Posted: Sun Sep 11, 2005 4:10 am
by nparekh
Hi guys,
I have tried varying the code as listed below but I get the following error:
Parse error: parse error, unexpected '<' on line 4
I was told to try the following code but it resulted in the error above. I can't seem to find where the problem lies. Code is as follows:
<?php
$art = mt_rand(0, 50);
if($art == "0") {
<!--#include virtual="<?="test.txt" ?>" -->
} else {
include("test" . $art . ".txt");
<!--#include virtual="<?="test" . $art . ".txt" ?>" -->
}
?>
Thanks again for your help.
Nikhil