ProgramacionWeb - Ayuda al webmaster
Not logged in
User login | Sign Up Now
Categorías Articulo
 
8 votos
Passage of variables by URL
 
 
! This article has been translated using machine translation. ProgramaciónWeb.net offers these articles so that users that doesn't understand Spanish can understand them, but is not responsible of the technical and linguistic quality of the translations.
We are going to see a very simple subject of the work with basic PHP but for any application Web, for which already conoceisthe work with variables passed through URL is possible q puts a littleto the day on this type of task.

The subject consists of acceding to a direction of the type pagina.php?variable1=valor1&variable2=valor2 and that interpreter PHP accedes to the values passed in the direction of the page to form the page that will be sent to the user.
 
000 
001 
002 
003 
<?
echo '<b>variable1:</b> ' $_POST["variable1"]
 
throw ' <br><b>variable2:</b> ' $_POST["variable2"]
 
?>
 
For example, we are going to show a message in a page depending on a parameter passed through URL:
 
variables.php
000 
001 
002 
003 
004 
005 
006 
007 
008 
009 
010 
011 
012 
013 
014 
015 
<?
if(isset($_GET["mensaje"])) 
 switch (
$_get["mensaje"]) {
 
0 marries
 
throw ' Welcome to my web'
 break; 
 
1 marries
 
throw ' Message 2 '
 break; 
 
marry 2
 
throw ' Last mensajé; 
 break; 
 default: 
 I throw ' 
Error in parametró
 } else 
throw ' did not go parametró; 
 ?>
 
This I cosay, reads parametro call message, the way to do it is from $_get["mensaje"], asi as if parametro was another one (variables.php?mensaje=1&usuario=343) accederiamos to from $_get["usuario"].

From ahi, we watched if this defined the variable to see if this last one with the function isset, soon we make a cycle switch in order to show to an u another message according to the value of the last variable.

The example, will show a different message to us depending on if message it is worth 0, it is worth 1, it is worth 2, it has another value or not this defined.

Note: We must observe that according to which parametros we pass through URL some finders how google, did not add our URL, for example,google does not index pages with the variable you go.
 
 
Comentarios
09/09/09 Comentario 1331
Muchas gracias por tomarte el tiempo de explicarle a los que no sabemos!!

Es muy buena la explicacion!!
04/04/11 Comentario 1684
y todos estos años preguntandome para que esas asignaciones en la barra de direccion...¬¬
 
Resolver dudas
Si tienes problemas o dudas con el contenido del artículo no dudes a preguntar en los foros de PHP de Programación Web indicando el artículo al que te refieres.