Toon posts:

Hulp nodig bij scriptje aanpassen

Pagina: 1
Acties:
  • 49 views sinds 30-01-2008

Verwijderd

Topicstarter
Ik kan zelf geen PHP schrijven, daarvoor weet ik er te weinig vanaf. Wat ik wel kan is PHP scripts die door anderen geschreven zijn enigszinds aanpassen en gebruiken. Alleen deze keer lukt me dat niet helemaal. Ik ben bezig een weblog te maken en heb een scriptje gevonden dat laatste refferers kan opslaan en laten zien op mijn pagina. Werkt perfect, niks aan het handje. Maar, wat ik wil is dat deze links die op mijn pagina komen te staan, openen in een nieuw venster. En dat is waar ik wat hulp bij nodig heb. Volgens mij moet dat geen probleem zijn voor iemand die PHP begrijpt. Hieronder heb ik alle code enzo gezet zodat jullie kunnen zien hoe het script eruit ziet.

Het geheel bestaat uit deze bestandjes:
lgf-reflog.txt -bestandje waar de adressen in worden opgeslagen
lgf-semaphore.ref -leeg bestandje
lgf-reflog.php -het script

In het bestandje lgf-reflog.txt worden de adressen opgeslagen. En dat ziet er ongeveer zo uit:
code:
1
http://www.voorbeeld.nl/http://www.google.com/http://www.testing.nl/voorbeeld.php?id=47855

Dit is de inhoud van lgf-reflog.php:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/*
    --------------------------------------------
        LGF Referrer Log
        By Charles F. Johnson
        Copyright 2001 LGF Web Design
        All Rights Reserved.
        http://littlegreenfootballs.com

        This file may be freely distributed
        as long as the credits and copyright
        message above remain intact.
    --------------------------------------------
*/

// Name of referrer log file
$reflog = 'lgf-reflog.txt';

// Name of semaphore file
$semaphore = 'lgf-semaphore.ref';

// Maximum number of referrers to log
$maxref = 10;

// Domain name of this site (minus "http://www.")
$mydomain = 'mijndomein.nl';

// From whence did Bunky come?
$ref = getenv("HTTP_REFERER");

// Cover me. I'm going in.

if (($ref) and (!strstr($ref, $mydomain))) {    // if there's a referrer, and it's not someone bouncing around this site
    $ref .= "\n";                               // append a line feed
    $sp = fopen($semaphore, "w");               // open the semaphore file
    if (flock($sp, 2)) {                        // lock the semaphore; other processes will stop and wait here
        $rfile = file($reflog);                 // read the referrer log into an array
        if ($ref <> $rfile[0]) {                // if this referrer is different from the last one
            if (count($rfile) == $maxref)       // if the file is full
                array_pop($rfile);              // pop the last element
            array_unshift($rfile, $ref);        // push the new referrer onto the front
            $r = join("", $rfile);              // make the array into a string
            $rp = fopen($reflog, "w");          // open the referrer log in write mode
            $status = fwrite($rp, $r);          // write out the referrer URLs
            $status = fclose($rp);              // close the log
        }
    }
    $status = fclose($sp);                      // close the semaphore (and release the lock)
}
?>

En dit is wat je moet gebruiken om de links op je pagina te zetten:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
// Name of referrer log file
$reflog = "lgf-reflog.txt";
?>
<html>
<head></head>
<body>

<?php
$rfile = file($reflog);                             // read the referrer log into an array
echo "<p>\n";
foreach ($rfile as $r) {                            // loop through the array
    $r = chop(strip_tags($r));                      // remove trailing whitespace and any bogus HTML
    if (($r <> "Direct request") and (!stristr($r, 'javascript:'))) echo "<a href=\"$r\">$r</a><br />\n";   // if not a direct request, link it up
}
echo "</p>\n";
?>

</body>
</html>

Zoals ik al zei, alles werkt perfect, het enigste dat ik wil is dat de links zullen openen in een nieuw venster zonder de base target aan te hoeven passen. Wat dus ideaal zou zijn is dat dit script iedere link automatisch voorziet van deze tag: target="_blank"
Is dat mogelijk? En zo ja, Hoe?

bvd

  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

Je weet hoe je in HTML linkjes toevoegt...

Ik zie toch echt een echo staan, met:
PHP:
1
echo "<a href=\"$r\">$r</a><br />\n";


Wellicht hier iets aanpassen? ;)

[ Voor 33% gewijzigd door BtM909 op 05-08-2003 19:11 ]

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.


  • gorgi_19
  • Registratie: Mei 2002
  • Laatst online: 20-08 11:40

gorgi_19

Kruimeltjes zijn weer op :9

Ja dat is mogelijk.

Waar denk je zelf dat het hoort?

Digitaal onderwijsmateriaal, leermateriaal voor hbo


  • justmental
  • Registratie: April 2000
  • Niet online

justmental

my heart, the beat

Dit is te eenvoudig en vragen om een quickfix oplossing en daar doen we hier niet aan.
Uitleg over wat wel en niet mag staat hier:
P&W Beleid

Who is John Galt?


Dit topic is gesloten.