• 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

Is it possible ?

TOMAZAS

New Member
Let's say, I want to do a script which redirects with values from TXT file like that:
index.php?go=news
The script should take a value from, lets say links.txt, and redirect user to the place written in TXT (like: news=http://www.mysite.com/news/daily/news.html)

What PHP code I should include in index.php ?
How and where to store values (TXT) ?

Anyone understood ? :classic2:
If no, please ask, I will try to explain more correct.
 
The syntax in Perl is so much easier when it comes to doing a task like this. If you want it in perl (this is a more comprehensive version):

Code:
#!perl
# replace perl with /usr/bin/perl or whatever
# if perl is not in the system path
# Copyright 2002 the wired
use CGI qw/:param/;
# 
#

# variables to modify
$path=""; # absolute path to file
$file = "myfile.txt"; # relative path to your data file
$delimiter=""; # character used to seperate fields in data file


# do not modify

print "Location: ";
if (-e "$path$file"){
  print "about:File%20does%20not%20exist.") and exit;
}

open (DB,$file) or die ("about:Permission%20denied");
@array=<DB>;
for $line (@array){
    @array2=split(/$delimiter/, $line);
    if ($array2[0]==param("name")) print $array2[1]; close (DB); exit;
    }
} close (DB);
print "Page%20not%20found.";

This should be the layout of your data file:

(If the delimiter is "|")
Code:
news|news.shtml
blah|blah.shtml
moreblah|moreblah.shtml
asfdasdfasdf|afdhlajdlkjasdf.shtml
blahbalhadfasdfasdf|asdfasdf.shtml
forums|forums/index.php
 
Last edited:
Thank you very much, but I need this in PHP too. :p
Anyways what is the link ? go.cgi?go=news like this?

Waiting for PHP suggestions....
 
Yes, there is no difference in the way you use it, it's just a different scripting language. As long as you have support, why wait for a PHP solution, when a Perl one is readily avaiable?
 
no, php is is much easier... and the person asked for a php solution, not your biased opinion on which language is better.

Code:
<?
$file=file('links.txt');
foreach($file as $x)
{
$x=explode('=',$x);
if $go==$x[0]
{
header('Location: '.$x[1]);
exit;
}
}
header('Location: http://www.whatever.com/default.html');
?>
 
Originally posted by Woofcat
no, php is is much easier... and the person asked for a php solution, not your biased opinion on which language is better.

Code:
<?
$file=file('links.txt');
foreach($file as $x)
{
$x=explode('=',$x);
if $go==$x[0]
{
header('Location: '.$x[1]);
exit;
}
}
header('Location: [url]http://www.whatever.com/default.html[/url]');
?>

Thanks ! :classic2: :classic2: :classic2:
 
php is is much easier ... biased opinion on which language is better.
I know how extremely biased you are against Perl, so I'll not target that. I'll just show that Perl can be written concisely as well.
Code:
#!perl

($go)=($ENV{'QUERY_STRING'}=~/go=(.*)/);
open(FILE,"links.txt");
while(<FILE>[b][/b]){
	$url=$1 if $_=~/^$go\|(.*)/;
}
close(FILE);
print "Location: ".$url."\n\n";
 
Back
Top