• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Frustrated!

Lokannon

New Member
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
 
Code:
<? 
if (!file_exists($tutorial.".html")) { 
     echo("Nice Try"); 
} else { 
     include $tutorial.".html"; 
} 
?>

I dunno PHP, dun ask me.
 
Some chnages to YUPAPA's code
PHP:
<?php 
if (!file_exists($tutorial.".html")) { 
     echo("Nice Try"); 
} else { 
     include($tutorial.".html"); 
} 
?>
 
:mad: ... use this!!

Code:
#!/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";
     }
}
 
uh...

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
 
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.
 
uh...

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...
 
ME forgot something, please overwrite the whole program again

Code:
#!/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
 
Last edited:
Back
Top