PDA

View Full Version : How would I go about doing this?



dawizman
June 8th, 2002, 20:31
ok, say I have 20 links or buttons etc.. on my page. Well how would I make it so, when I click on one of those it changes the location of $filename.

ex) $filename = main.txt
I click on a link
$filename = contact.txt

how would I do this in php, or something similar in perl or asp, but I would prefer php.


Thanks in advance.

YUPAPA
June 9th, 2002, 02:10
Why don't you do it using HTML directly?
<A HREF="your_file.txt">your_file.txt</A>

dawizman
June 9th, 2002, 02:13
this way, in the middle of the page, in the content table, I can go include(contact.txt) or include(main.txt) etc...

YUPAPA
June 9th, 2002, 02:26
#!/usr/bin/perl
use strict;
use CGI qw(:standard :form);


#################### CONFIG ####################

# Path to your header file
my $header_file = q(/home/yourdomain.com/www/header.htm);

# Path to your footer file
my $footer_file = q(/home/yourdomain.com/www/footer.htm);

# Path to the directory storing all your content file (web pages)
my $content_dir = q(/home/yourdomain.com/www);

################################################


my $query = new CGI();
my $content_file = $query->param('page');

my ($header,$footer);

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

&head_foot;

sub head_foot {
open(HEADER,"<$header_file") or die print "Could not open header $header_file - $!\n";
while(<HEADER>) {
chomp $_;
$header .= "$_\n";
}
close(HEADER);
open(FOOTER,"<$footer_file") or die print "Could not open footer $footer_file - $!\n";
while(<FOOTER>) {
chomp $_;
$footer .= "$_\n";
}
close(FOOTER);
print_page($header,$footer);
}

sub print_page {
print $_[0];
open(CONTENT, "<$content_file") or die print "Could not open content file $content_file - $!\n";
print <CONTENT>;
close(CONTENT);
print $_[1];
}

__END__

YUPAPA
June 9th, 2002, 02:28
Edit the config part

Assume (page.pl) is the script name
call the pages like that: http://www.yourdomain.com/page.pl?page=the_web_page.htm

#Note the the_web_page.htm shouldn't have any header or footer because you already assigned that in the script.