PDA

View Full Version : Frustrated!



Lokannon
April 10th, 2002, 19:52
Im having a serious PHP problem... its not that hard, i dont think... so if you could help, i would be very appreciative..

I want it so that the sites address shows mypage.php?tutorial=sometutorial

The code im using is:

<?
if (!file_exists($tutorial.".html")) {
die("Nice Try");
} else {
include $tutorial.".html";
}
?>

It works, except for the fact that the die part of the code acts on the page i put it on... i dont want it to do that. I want it to act on the tutorial page, so that if someone tries to call it from my website, it wont work

Also, when i click the link to include the tutorial (im doing this without the die function now), it works, except it includes the file at the top of the page the link is on, leaving the page with the link on it, at the bottom of the screen, while the tutorial is still at the top!

I hope you can tell me a better way to do this! THNX!

:: Lokannon

roly
April 10th, 2002, 20:04
if you search you will find how to do this

YUPAPA
April 10th, 2002, 20:37
<?
if (!file_exists($tutorial.".html")) {
echo("Nice Try");
} else {
include $tutorial.".html";
}
?>


I dunno PHP, dun ask me.

roly
April 10th, 2002, 21:09
Some chnages to YUPAPA's code
<?php
if (!file_exists($tutorial.".html")) {
echo("Nice Try");
} else {
include($tutorial.".html");
}
?>

Lokannon
April 10th, 2002, 21:15
is that supposed ot help me roly..?

YUPAPA
April 10th, 2002, 21:52
:mad: ... use this!!



#!/usr/bin/perl
use strict;

my $tutorial, $line, @source;

print "Content-Type: text/html\n\n";

if(!-f "$tutorial.html") {
print "Not exist";
} else {
sysopen(FILE, "$tutorial.html", O_RDONLY) || die print "Could not READ $tutorial.html: $!";
@source = <FILE>;
close(FILE);
foreach $line (@source) {
chomp $line;
print "$line\n";
}
}

Lokannon
April 11th, 2002, 17:22
Where do i put it? In the CGI bin? Or in the file? how does it work... and where do i link it to... explain a little mroe please. Im totoally illiterate when it comes to PERL.

THNX

:: Lokannon

YUPAPA
April 11th, 2002, 18:39
1. Save it as a PL file
2. Upload it ASCII Mode and put it in your CGI-BIN folder. If the server allows you to run PERL in any directory, then you can place it anywhere. Change permission 0755.
3. Make sure the HTML files are stored in the same directory. (IF NOT, edit line 8 and 11 to correct the path.)
4. RUN.

Lokannon
April 11th, 2002, 19:55
Okay... it wont let me run it...

Where do i put the link to?

cgi-bin/tutorial.pl?tutorial=sometuto

is that right ^?

sorry... im so confused...

YUPAPA
April 11th, 2002, 20:06
ME forgot something, please overwrite the whole program again



#!/usr/bin/perl
use CGI qw(:standard);
use strict;

my $line;
my @source;
my $tutorial = param('tutorial');

print "Content-Type: text/html\n\n";

if(!-f "$tutorial.html") {
print "Not exist";
} else {
open(FILE, "$tutorial.html") || die print "Could not READ $tutorial.html: $!";
@source = <FILE>;
close(FILE);
foreach $line (@source) {
chomp $line;
print "$line\n";
}
}




You access to the file like this:
http://www.yourdomain.com/cgi-bin/yourscript.pl?tutorial=index