Jump to content

[SOLVED] blocking my sitemap from viewing files


serverman

Recommended Posts

Ok i wrote (mainly form random snippets) a site map tool... but i have pages i want it not to read (like my quiz grader and the add member stuff :P here is the code

 

<?php 
// starting directory. Dot means current directory
$BD = ".";
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;

echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Site Map</title>
</head>
<body>';
// function to count depth of directory 
function depth($fn){
  return (($p = strpos($fn, "/")) === false) ? 0 : (1 + depth(substr($fn, $p+1)));
}


// main function that scans the directory tree for web pages 
function listdir($BD){
    if ($handle = @opendir($BD)) { 
        while (false !== ($fn = readdir($handle))){ 
            if ($fn != '.' && $fn != '..'){ // ignore these
                $dir = $BD."/".$fn; 
                if (is_dir($dir)){ 
                    listdir($dir); // recursive call to this function
                } else { //only consider .html etc. files
                    if (preg_match("/[^.\/].+\.(htm|html|php)$/",$dir,$fname)) {
                       printlink($fname[0]); //generate the html code
                    }
							} 
            } 
        } 
        closedir($handle); 
    } 
} // function to print a line of html for the indented hyperlink
function printlink($fn){
  $indent = depth($fn); // get indent value
  for ($i = 1; $i <= $indent; $i++) {
    echo "  ";
} 
  echo "<a href=\"$fn\">"; //print url
$handle = fopen($fn, "r"); //open web page file
$filestr = fread($handle, 1024); //read top part of html
fclose($handle); //clos web page file
if (preg_match("/<title>.+<\/title>/i",$filestr,$title)) { //get page title
    echo substr($title[0], 7, strpos($title[0], '/')-; //print title
} else {
    echo "No title";
}
  echo "</a><br />\n"; //finish html
}

// function call 
listdir($BD); //this line starts the ball rolling
//timer end
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 4);
echo '<p>Page generated in '.$total_time.' seconds.</p>'."\n";
echo'
</body>
</html>
';
?>

 

here is my idea how to do it (i just don't know how to make my idea work :P)

in code tell to not read page if the page has

<?php $r = n; ?>

and read it if $r = y(so i would add <?php $r = n; ?> in the header of every page i don't want it to print in the site map and i would put <?php $r = y; ?> on all the other pages)

... i hope i made sense

... but i really have no idea how to get that to work! lol im a noob!!!!!

oh one last thing if where i got the snippet from doesn't put a copyright do i need to add a copyright to it for them(add //copy right = website i got it from) or just leave it be

... hehe i forgot about all the notes i wrote to myself in there :P

 

Link to comment
Share on other sites

ad tag

<!-- no show -->

just after </title> tag in same line

 

change your functio to

function printlink($fn){
$handle = fopen($fn, "r"); //open web page file
$filestr = fread($handle, 1024); //read top part of html
fclose($handle); //clos web page file
        if(strpos($filestr,'<!-- no show -->')) return false;
  $indent = depth($fn); // get indent value
  for ($i = 1; $i <= $indent; $i++) {
    echo "  ";
} 
  echo "<a href=\"$fn\">"; //print url
if (preg_match("/<title>.+<\/title>/i",$filestr,$title)) { //get page title
    echo substr($title[0], 7, strpos($title[0], '/')-; //print title
etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.