Mother Earth |
20-11-2004 19:52 |
[CGI] Automatisch linken?
Kijk, ik heb hier een scriptje zodat mensen zich automatisch kunnen laten linken:
Code:
#!/usr/bin/perl
#########################################
#########################################
print "Content-type: text/html\n\n";
####Name of your directory#####
$indexname = "Internet Link Archive";
$path = "/";
$domain = "http://laura.ashleylynn.net";
$countfile = "counts.txt";
$buffer = $ENV{'QUERY_STRING'};
$count =0;
$count = $count + 1;
open(WERE,"$countfile");
@lines = <WERE>;
close(WERE);
foreach $lines (@lines){
chomp($lines);
($plus,$sum)=split(/\|/,$lines);
}
if ($buffer eq 'add'){
&addnew();
}
sub addnew{
print <<ENDHTML;
Add your link to our directory.<br>
<form action=direct.cgi?addnew method=post>
Title: <input type="text" name="title"><br>
Description: <input type="text" name="description"><br>
Url: <input type="text" name="http" value="http://"><br>
Category:<select name=cat>
<option value=link>link
</select><br>
<input type=submit value=Submit><input type=reset value=Reset></form>
ENDHTML
;
exit;
}
if ($buffer eq 'addnew'){
&addnewlink();
}
sub addnewlink{
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {
$buffer = $ENV{'QUERY_STRING'};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
if ($FORM{cat} eq 'link'){
open(AD,">>$path/link.htm");
print AD "<font size=4><a href=$FORM{http}>$FORM{title}</a> - </font><font size=2><B>$FORM{description}<br>";
close(AD);
}
print "Your link has been successfully added!";
exit;
}
$counter = $count + $plus;
if (-e$countfile){
open(TY,">$countfile");
print TY "$counter|0";
close(TY);
}else{
open(UY,">$countfile");
print UY "0|0";
close(UY);
}
print <<ENDHTML;
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.7 [en] (Win95; U) [Netscape]">
<title>$indexname</title>
</head>
<body>
<center><b><font size=+4>$indexname</font></b>
<br>
<hr SIZE=3 NOSHADE WIDTH="100%"></center>
<br>
<center><table BORDER COLS=1 WIDTH="50%" BGCOLOR="#000000" >
<tr>
<td>
<center> <b><a href="direct.cgi?add">Add Your Link</a> </b></center>
</td>
</tr>
</table></center>
<center>
<a href="$domain/link.htm">Links</a>
<br><b></b> <b></b>
<p><b>Total views to this page: $plus</b>
<br>
</body>
</html>
ENDHTML
;
exit;
(sorry, het is een beetje groot)
Op zich werkt alles, maar het belangrijkste niet. Het was mijn bedoeling dat op link.htm de link zou komen te staan, maar dat laatie dus niet zien. Hoe zorg ik daarvoor? Dus dat de link ook echt gepost wordt?
Hier kan je zien hoe het nu is: http://laura.ashleylynn.net/direct.cgi
(layout moet ik nog aanpassen hoor :) )
Alvast bedankt, ik hoop dat iemand het snapt & me kan helpen.
|