Re: I didnt understand the how work pathtovars, a php gpl script
| From: | David D | Date: | Thu, 25 Jul 2002 21:08:12 +0000 |
| Subject: | Re: I didnt understand the how work pathtovars, a php gpl script | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109608@lists.php.net to get a copy of this message | ||
I make my own :
What u think about :
begin ================================================
<?
// Author : David Devidal dd@asi.fr
// Licence : GPL
//
// include one time this script at the beginnig of the script
// file will do the mapping
//
// for the revers mapping think of using normurl2trans($url);
/*
print_r($HTTP_GET_VARS);
print_r($HTTP_POST_VARS);
echo "PHP_SELF $PHP_SELF <br>";
echo "REQUEST_URI $REQUEST_URI <br>";
echo "SCRIPT_NAME $SCRIPT_NAME <br>";
echo "PATH_INFO $PATH_INFO <br>";
echo "PATH_TRANSLATED $PATH_TRANSLATED <br>";
// Array ( ) Array ( ) PHP_SELF /path2vars/index.php/var1,val1/var2,val2/
// REQUEST_URI /path2vars/index.php/var1,val1/var2,val2/
// SCRIPT_NAME /path2vars/index.php
// PATH_INFO /var1,val1/var2,val2/
// PATH_TRANSLATED c:\\easyphp\\www\\var1,val1\\var2,val2\\
exit();
*/
//phpinfo();
// we will transform vars from 1 style to 2 style
// 1) http://localhost/path2vars/index.php?&var1=val1&var2=val2
en
// 2) http://localhost/path2vars/index.php/var1,val1/var2,val2/
// that will permit a better crawls with web crawlers
// from type 1) to type 2)
function normurl2trans($url) {
// we cut the url in 2 part 1 to keep and the other to manipulate
$urldecoup = split($GLOBALS[SCRIPT_NAME],$url);
$urldecoup[1] = str_replace('?&','&',$urldecoup[1]); // for easily
progs
$urldecoup[1] = strtr($urldecoup[1], '&=', '/,'); // map particulars
chars
return $urldecoup[0].$GLOBALS[SCRIPT_NAME].$urldecoup[1].'/';
}
// from type 2) to type 1)
function trans2norm($url) {
// we cut the url in 2 part 1 to keep and the other to manipulate
$urldecoup = split($GLOBALS[SCRIPT_NAME],$url);
$urldecoup[1] = strtr($urldecoup[1],'/,','&='); // map particulars chars
$urldecoup[1] =
$urldecoup[0].$GLOBALS[SCRIPT_NAME].'?'.$urldecoup[1].'/';
return str_replace('&/','',$urldecoup[1]); // for easily progs
}
// little test unit for fonctions
//echo normurl2trans
("http://localhost/path2vars/index.php?&var1=val1&var2=val2");
//echo
trans2norm("http://localhost/path2vars/index.php/var1,val1/var2,val2/");
/*************
// the vars parser :
// we make it here not in a fucntions for globals vars context
// works at each case no vars 1 2 ...
**************/
$urltemp = str_replace($SCRIPT_NAME.'/','',$PHP_SELF); // get string to
explode
// gives var1,val1/var2,val2/
// we had to cut into with /
$urldecoup = split('/',$urltemp);
// gives Array ( [0] => var1,val1 [1] => var2,val2 [2] => )
$urltempsize = count($urldecoup)-1; // we dont treat the last elemnts that
is empty
for ($urltempi=0;$urltempi<$urltempsize;$urltempi++) {
$nameval = split(',',$urldecoup[$urltempi]); // cut 2 elts var1,val1
${$nameval[0]} = $nameval[1]; // affect $var1 with value val1
//$var1="val1";
} // end parse
/*
// little test unit
echo "$var1<br>";
echo "$var2<br>";
*/
/**
<html>
here is a little query string parser to get work web crawlers
url test :<br>
<?
require_once('query_string_parser.php');
$thelink = normurl2trans
("http://localhost/path2vars/index.php?&var1=val1&var2=val2");
echo "<a href='$thelink'>lien ni1</a><br>";
echo $var1.'<br>';
echo $var2.'<br>';
?
<html>
**/
?>
=================================end cut
Thanks