Coding random Include page

Started on the old forum in April 2011 · view the original in the archive · old links redirect here

5 replies · 529 views · started 15 years ago · 1 min read

4 participants
puge Developer · 54 posts #1

Hi bro, kindly help out with this... <?php include_once $_SERVER['DOCUMENT_ROOT'] . '/variables/variables.php'; include_once $_SERVER['DOCUMENT_ROOT'] . '/variables/random.php'; ?> ..... so how can i include a random page into this file? e.g because i got 67page to include on this page? how can i make it random.

something else Fellow · 2,296 posts #3
<?php
$filenames = array();
if ($handle = opendir('/variables')) {
    $n = 1;
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $filenames[$n] = $file;
            $n++;
        }
    }
    closedir($handle);
}
$num = rand(count($filenames));
include_once $_SERVER['DOCUMENT_ROOT'] . '/variables/'.$filenames[$num];
?>
puge Developer · 54 posts #4

Thank, i will try this out.

puge Developer · 54 posts #5

Bro, this work but i can u help fix a bug.

atef Developer · 224 posts #6
 <?php
$atef = array( 
'page1',
'page2', 
'page3', 
);
$atef = $atef [ rand(0, (count($atef)-1)) ]; 
require($atef.php); 
?>

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close