begin process at 2012 05 27 21:29:23
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > FUNCTION LINK

FUNCTION LINK


 Information sur la source

Note :
Aucune note
Catégorie :Divers Classé sous :link, lien, image, attribut, function Niveau :Débutant Date de création :09/08/2009 Vu / téléchargé :3 022 / 106

Auteur : astro53

Ecrire un message privé
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

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

  • <?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;
  • }
  • ?>
<?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

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip CLASS TAG GENERAL
Source avec Zip FUNCTION IMAGE SIMPLE ET ARRAY

 Sources de la même categorie

Source avec une capture MODULE JOOMLA 1.5 NOW LISTENING par Alcantornet
Source avec Zip Source avec une capture UPLOAD CENTER par basssem81
Source avec Zip COMPTEUR DE CLIQUE PHP AVEC JQUERY par devgoneti
Source avec Zip LIVRE D'OR SIMPLE (POUR DÉBUTANT) par devgoneti
Source avec Zip SCRIPT TRAVAUX POUR VOTRE SITE par FleuryK

 Sources en rapport avec celle ci

REDIMENSIONNEMENT D'IMAGE PHP par JStevens
PROTÉGEZ VOS LIENS DE TÉLÉCHARGEMENT PAR MOT DE PASSE ET/OU ... par unlien
Source avec Zip Source avec une capture GESTIONNAIRE DE NEWS BASIQUE AVEC UPLOAD D'IMAGES par cod57
Source avec Zip Source avec une capture UPLOADEUR DE FICHIERS MULTIPLES V1 par cod57
CLASS GALERIE PHOTO par Xiryl

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

BDD et les image / lien [ par kodiask ] bjr je voudrai savoir coment on peu faire pr envoyer ds la BBD un lien sui sera clikable lorsqu'il sera afficher ds la page.ou pour faire qu'une im Lien hypertexte avec une image : pas propre [ par BSide ] Bonjour,je veux mettre un lien hyptxt sous frme d'image afin d'alléger et d'égayer un peu la présentation de mon intranet.Le problème, c qu'apparait a affichage de texte et d'image quand on passe sur un lien [ par forngot ] Voila je voudrais savoir si c possible en php que quand on passe sur lien dans une page une petite fenetre apparait est affiche du texte et de l'image changer le lien d'une image [ par ouned ] 'lo allbon voilà mon pb, c'est surement tout con mais j'n'arrive pas à trouver.j'aimerais que le lien de mes images ne soient pas affichés dans une pa changement image au survol d'1 lien [ par aze555666 ] sltest-il possible qu'une image change au survol d'une lien situé à coté (et non pas de l'image elle meme)???aze555666 Changer d'image dans une frame a chaque lien [ par symphox ] Bonjour, J'ai un site avec plusieurs frames. La frame d'en haut o&#249; il y a bien sur tout les liens, la frame du milieu pour le contenu. Je voudr Les retours chariot dans l'attribut title d'un lien hypertexte [ par michel_roger ] Alors voilà, je voudrais savoir s'il y a un moyen de forcer le retour chariot d'un attribut title d'un lien :&lt;a href="mapage.html" title="Nom:nom_d lien image [ par magicsmacks ] Bonjour,Voil&#224; j'ai un lien image de ce type:&lt;img src='....../......./.....'&gt; et j'avais d&#233;j&#224; demand&#233; comment faire pour r&#2 Images lien [ par medpurple ] Bonjour a touss voila j'ais un ptit prob je voudrai faire une chose pour mon module de news je voudrai crer un bouton apeler image pour incerer une im Excuter une fonction [ par milkasoprano ] Bonjour tous le monde, Je vous &#233;cris&nbsp; car j'ai une question sur le fait comment executer une fonction a partir d'un lien... exemple: je suis


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,640 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales