Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Including PHP-Scripts without mess

Hi all!

Reading a lot of articles in this forum and web pages about php didn't help finally. So, I hope you might have a quick answer again.

The problem is to include a php-script for faking mail-addresses (please don't discuss the (non-) sense of it!!!):

<?php
function makeName($ii=10) {
    $s="";
    for ($i=1;$i<=$ii;$i++) {
        $s = $s.chr(rand(97,122));
    }
    return $s;
}

function fakeMail($nOfMails = "20", $breakS = "<br>", $prefix = "", $postfix = "") {
    $tldList = array("com", "net", "org", "mil", "edu", "de", "biz", "de", "ch", "at", "ru", "de", "tv", "com", "st", "br", "fr", "de", "nl", "dk", "ar", "jp", "eu", "it", "es", "com", "us", "ca", "pl");
  $result="";
    for ($j =1; $j<=$nOfMails;$j++) {
        $myMail = makeName(rand(3, 10))."@".makeName(rand(4, 20)).".".$tldList[rand(1, sizeOf($tldList))];
        $myMail = "<a href=\"mailto:".$myMail."\">".$myMail."</a>";
        if ($j == $nOfMails) {
            $result = $result.$myMail;
        } else {
            $result = $result.$myMail.$breakS;
        }
    }
    return $prefix.$result.$postfix;
};

?>

Since I learnt that CD parses php very likely, I tried to include the script the following way:

<?php
include "fakemail.php";
fakeMail();
?>

However, it didn't work. This is my first contact with php, and with this result it might be my last.

CU, Steffen

Dr. Steffen Steinhäuser
Tuesday, January 20, 2004

Hi Steffen.

In your code:

<?php
include "fakemail.php";
fakeMail();
?>

You are missing parentheses about the "fakemail.php" (not examined your code to look if anything else is wrong).

Within CityDesk itself:
I have found that using the CityDeskscript {$ include
"fakemail.php" $} won't include the file as include only seems to work for CityDesk articles (so I create an article called fakemail and put the PHP code into that. Make sure the template has file extension PHP and with PHP code I dare not switch from HTML to normal view).

Another way to include PHP code is to put the PHP code into a CityDesk variable (including the <?PHP and ?> tags). Then insert the variable into your article (again check the template extension is .php).

HTH

Dan
Tuesday, January 20, 2004

Hi all,

last night (in Germany) i learnt, that including php, doesn't work inside .html files. Once I used the command inside a .php file it did work.

See http://die-steinhaeuser.de/test.php.

My problem is now, that I again can' t include this. However, I will link between the man index.html and the test.php. This will be enough to do for the robots, crawler and the other email seekers of spamer.

Thanks again for help,

Steffen

Dr. Steffen Steinhäuser
Wednesday, January 21, 2004

Sorry, link above is broken. I will repair it soon.

Dr. Steffen Steinhäuser
Wednesday, January 21, 2004

Use the following link, please:

http://www.die-steinhaeuser.de/test.php

The (.) dot was too much.

CU, Steffen

Steffen steinhäuser
Saturday, January 24, 2004

someone mentioned above that include was "missing parens", however, include is a language construct, not a function, and the parenthesis are not required.

Also, if you are on apache and have some control over the httpd.conf file, you could force the web server to parse all .html files with php.  This would give you some flexibility (e.g. to do what you are trying) at the expense of some overhead on each page request (for normal html files with no php in them).

HTH

Jason Sweat
Saturday, January 24, 2004

*  Recent Topics

*  Fog Creek Home