Bonjour a tous je vous ai concocter une fonctions sources avec le parametre optionel menuLink.
Ce dernier comparera le lien a l'url et si le nom de la page apparait dans l'url le lien est desactive.
J'ai essayer essayer de creer deux regex qui a elle 2 empeche toute intrusion de parametre http ftp ...apres un fichier de language php ou asp ex index.php?=&=
http://www.sdkaksd index.asp?dfa=ftp.erewr...
Source / Exemple :
<?php
/********************************/
/* AstroProduction */
/* Version 1.1 */
/* All Right Reserved */
/* 2009 */
/********************************/
//Get the url
$url = $_SERVER['REQUEST_URI'];
/**
- @param function:links function that create a link
*
- @param string:$name content of the link for images just give the path of the image
- @param string:$link link path
- @optional param string or array:$attrLink give the attributes parameters class,id,alt,title...
- @optional param string or array:$attrImg give the attributes parameter for an image border,onmuseover...
- two possibilities for attributes string "class='linked'" or array "class" => "imaged"
- @optional param boolean:$menuLink check the link name with the url if true unlink the link
- /
function links($name,$link,$attrLink = null, $attrImg = null,$menuLink = null)
{
global $url;
if($name && !is_string($name))
{
throw new Exception("You need a first string parameter");
return;
}
if($link && !is_string($link))
{
throw new Exception("You need a second string parameter");
return;
}
if(preg_match("#[a-zA-Z1-9./]+[/]{1}[a-zA-Z1-9./]*\?[a-zA-Z1-9_-]+=(http|ftp|www)#i",$url))
{
throw new Exception("try to enter a wrong parameter in the url");
return;
}
if(preg_match("#[a-zA-Z1-9./]+[/]{1}[a-zA-Z1-9./]*\?[a-zA-Z1-9_:\\/-]*=[a-zA-Z1-9_.:\\/-]*(&[a-zA-Z1-9_.:\\/-]*=[a-zA-Z1-9_.:\\/-]*)*(&[a-zA-Z1-9_.:\\/-]*=(http|ftp|www)+)+#i",$url))
{
throw new Exception("try to enter a wrong parameter in the url");
return;
}
if($menuLink)
{
if(preg_match("#[a-zA-Z1-9/]+[/]{1}index.(php|asp(x)?|html)[/]?#i",$link))
{
$search = "([a-zA-Z1-9/]+[/]{1}index.(php|asp(x)?|html)|[a-zA-Z1-9]+[/]{1}$)";
if(!preg_match("#".$search."#i",$url))
{
$Link = "<a href='".$link."'";
if($attrLink)
{
$Link .= " ";
if(is_array($attrLink))
{
foreach($attrLink as $linkKey => $linkValue)
{
$Link .= $linkKey."='".$linkValue."' ";
}
$Link .= ">";
}
else
$Link .= $attrLink.">";
}
else
$Link .= ">";
}
}
else
{
if(!preg_match("#".$link."#i",$url))
{
$Link = "<a href='".$link."'";
if($attrLink)
{
$Link .= " ";
if(is_array($attrLink))
{
foreach($attrLink as $linkKey => $linkValue)
{
$Link .= $linkKey."='".$linkValue."' ";
}
$Link .= ">";
}
else
$Link .= $attrLink.">";
}
else
$Link .= ">";
}
}
}
else
{
$Link = "<a href='".$link."'";
if($attrLink)
{
$Link .= " ";
if(is_array($attrLink))
{
foreach($attrLink as $linkKey => $linkValue)
{
$Link .= $linkKey."='".$linkValue."' ";
}
$Link .= ">";
}
else
$Link .= $attrLink.">";
}
else
$Link .= ">";
}
if(preg_match("#\.(jpg|gif|png|bmp)$#i",$name))
{
$Link .= "<img src='".$name."'";
if($attrImg)
{
$Link .= " ";
if(is_array($attrImg))
{
foreach($attrImg as $imgKey => $imgValue)
{
$Link .= $imgKey."='".$imgValue."' ";
}
}
else
$Link .= $attrImg;
}
$Link .= " />";
}
else
$Link .= $name;
if($menuLink)
{
if(preg_match("#[a-zA-Z1-9/]+[/]{1}index.(php|asp(x)?|html)[/]?#i",$url))
{
$search = "#[a-zA-Z1-9]+[/]{1}|[a-zA-Z1-9/]+[/]{1}index.(php|asp(x)?|html)[/]?#i";
if(preg_match($search,$url))
$Link .= "";
else
$Link .= "</a>";
}
else
$Link .= (preg_match("#".$link."#i",$url)) ? "" : "</a>";
}
else
$Link .= "</a>";
return $Link;
}
?>
Conclusion :
J'ai fait en sorte que la fonction soit la plus complete possible si vous voyez des ameliorations ou quelques autres commentaires ils sont les bienvenues.
Vous pouvez utilisez ma class tag general pour creez des tableaux ou des listes de menu
Le zip contient un fichier exemple en plus de la source.
A bientot
Astro
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.