开发者

PHP Inline URL Redirect?

I was wondering if it was possible to make it where someone could just input the link:

and have it actually go to the real link when people visit.

This is what I have, but I don't know how to implement.

<?php
if( $_GET["k"] == "custom" ) header( "Location: {$_POST["first"]}_{$_POST["last"]}" );

$file = fopen( "link.php", "r" );

$data = fread( $file, filesize( "link.php" ) );


$first = $_GET["n"];
$last = fixN( $last );
$data = str_replace( "first", ucfirst( strtolower( $first ) ), $data );
$data = str_replace( "last", ucfirst( $last ), $data );


print  $data;

}
?>

On the page;

<BODY onLoad="first">

Even if you do the link, it wont only grab the last part. Which is what I need it to redirect to.


<?php
if (isset($_SERVER['REQUEST_URI'])) AND filter_var(trim($_SERVER['REQUEST_URI']),     FILTER_VALIDATE_URL)) {

    header('Location: ' . $_SERVER['REQUEST_URI']);

}
?>
<html&开发者_开发百科gt;
<head></head>
<body>
<a href="first">first</a>
</body>
</html>

This is the exact link http://LikeTreasure.com/google.com

I don't know what's wrong with it.

even if you specify a file type http://LikeTreasure.com/file.html

It always seems to send the entire url.


So long as you are URL rewriting that to a PHP file...

if (isset($_SERVER['REQUEST_URI'])) AND filter_var(trim($_SERVER['REQUEST_URI']), FILTER_VALIDATE_URL)) {

    header('Location: ' . $_SERVER['REQUEST_URI']);

}

This will forward on the request if the REQUEST_URI environmental variable is set (it won't be in IIS) and it looks like a valid URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜