<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Daniel Segovia</title>
	<atom:link href="http://www.danielsegovia.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danielsegovia.com</link>
	<description>Blog personal</description>
	<lastBuildDate>Wed, 11 Apr 2012 16:33:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Diferentes sintaxis en Insert</title>
		<link>http://www.danielsegovia.com/diferentes-sintaxis-en-insert/</link>
		<comments>http://www.danielsegovia.com/diferentes-sintaxis-en-insert/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 15:23:22 +0000</pubDate>
		<dc:creator>Daniel Segovia</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[insert como update]]></category>
		<category><![CDATA[insert into]]></category>
		<category><![CDATA[sintaxis insert]]></category>

		<guid isPermaLink="false">http://www.danielsegovia.com/?p=836</guid>
		<description><![CDATA[Tenemos una opción no muy conocida y también no muy usada para realizar un Insert en MySql (no conozco en detalle otros motores de base de datos) La sintaxis clásica INSERT INTO usuarios &#40;nombre, nivel&#41; VALUES &#40;'Daniel', 1&#41;; Esta sintaxis es similar a la del Update INSERT INTO usuarios SET nombre='Daniel', nivel=1 Con cualquier el [...]]]></description>
			<content:encoded><![CDATA[<p>Tenemos una opción no muy conocida y también no muy usada para realizar un Insert en MySql (no conozco en detalle otros motores de base de datos)<br />
La sintaxis clásica</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> usuarios <span style="color: #66cc66;">&#40;</span>nombre<span style="color: #66cc66;">,</span> nivel<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Daniel'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Esta sintaxis es similar a la del Update</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> usuarios <span style="color: #993333; font-weight: bold;">SET</span> nombre<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Daniel'</span><span style="color: #66cc66;">,</span> nivel<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span></pre></div></div>

<p>Con cualquier el resultado será el mismo.</p>
<p>Aquí un ejemplo funcional de ésta última sintaxis</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$mysqli</span> <span style="color: #000000;">=</span> <span style="color: #0000FF;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #158C15;">&quot;localhost&quot;</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;usuario&quot;</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;password&quot;</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;nombre_base&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysqli_connect_errno</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000FF;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #158C15;">&quot;Imposible conectarse: <span style="color: #009933; font-weight: bold;">%s</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #000000;">,</span> <span style="color: #990000;">mysqli_connect_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
    <span style="color: #0000FF;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #000000;">=</span> <span style="color: #158C15;">&quot;INSERT INTO usuarios SET nombre=?, nivel=?&quot;</span><span style="color: #000000;">;</span>
&nbsp;
<span style="color: #000088;">$nombre</span> <span style="color: #000000;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #158C15;">'Daniel'</span><span style="color: #000000;">;</span>
<span style="color: #000088;">$nivel</span> <span style="color: #000000;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #cc66cc;">1</span><span style="color: #000000;">;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span> <span style="color: #000000;">=</span> <span style="color: #000088;">$mysqli</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000088;">$stmt</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">bind_param</span><span style="color: #009900;">&#40;</span><span style="color: #158C15;">'si'</span><span style="color: #000000;">,</span> <span style="color: #000088;">$nombre</span><span style="color: #000000;">,</span> <span style="color: #000088;">$nivel</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
    <span style="color: #000088;">$stmt</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
    <span style="color: #000088;">$stmt</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielsegovia.com/diferentes-sintaxis-en-insert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Datos sensibles en cookie</title>
		<link>http://www.danielsegovia.com/datos-sensibles-en-cookie/</link>
		<comments>http://www.danielsegovia.com/datos-sensibles-en-cookie/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 20:46:42 +0000</pubDate>
		<dc:creator>Daniel Segovia</dc:creator>
				<category><![CDATA[7.5 Cookies]]></category>
		<category><![CDATA[seguridad]]></category>
		<category><![CDATA[seguridad cookie]]></category>

		<guid isPermaLink="false">http://www.danielsegovia.com/?p=828</guid>
		<description><![CDATA[Cualquier dato puede ser almacenado en una cookie, pero es importante saber que lo que almacenamos puede tener un mal uso por terceros, por lo que debemos tomar los recaudos pertinentes. Una manera de hacer un login automático puede ser guardar el nombre de usuario en una cookie y también la contraseña, cuando el visitante [...]]]></description>
			<content:encoded><![CDATA[<p>Cualquier dato puede ser almacenado en una cookie, pero es importante saber que lo que almacenamos puede tener un mal uso por terceros, por lo que debemos tomar los recaudos pertinentes.<br />
Una manera de hacer un login automático puede ser guardar el nombre de usuario en una cookie y también la contraseña, cuando el visitante ingresa si las cookies están definidas y tiene contenido podríamos buscar en la base para validar estos datos y loguearlo automáticamente.<br />
Esto sería una manera de hacerlo pero aquí se comprometen los datos del usuario de una manera grosera, la contraseña nunca puede ser guardada en un archivo de texto, cualquier con acceso físico a la computadora podría leer esta información.<br />
Por lo tanto debemos tener en cuenta que es lo que deseamos guardar y tomar determinados recaudos a la hora de guardarlos, en el capítulo de <a href="http://www.danielsegovia.com/category/manual-de-php/7-desarrollar-una-aplicacion-web/7-8-seguridad/" title="Seguridad en aplicaiones web">seguridad en aplicaciones web</a> veremos un poco más en detalle que y como guardarlo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielsegovia.com/datos-sensibles-en-cookie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eliminar una cookie</title>
		<link>http://www.danielsegovia.com/eliminar-una-cookie/</link>
		<comments>http://www.danielsegovia.com/eliminar-una-cookie/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 20:39:46 +0000</pubDate>
		<dc:creator>Daniel Segovia</dc:creator>
				<category><![CDATA[7.5 Cookies]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[eliminar]]></category>
		<category><![CDATA[eliminar cookie]]></category>
		<category><![CDATA[setcookie]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://www.danielsegovia.com/?p=825</guid>
		<description><![CDATA[Eliminar una cookie puede hacerse de 2 maneras, la primera es definir una una cookie con el mismo nombre de la que deseamos eliminar sin ningún parámetro extra &#60;?php setcookie&#40;&#34;nombre_cookie&#34;&#41;; ?&#62; Y la segunda es usar setcookie y enviar como parámetro un tiempo de caducidad pasado. &#60;?php setcookie&#40;&#34;nombre_cookie&#34;, &#34;&#34;, time&#40;&#41; - 3600&#41;; //Fijate la fecha [...]]]></description>
			<content:encoded><![CDATA[<p>Eliminar una cookie puede hacerse de 2 maneras, la primera es definir una una cookie con el mismo nombre de la que deseamos eliminar sin ningún parámetro extra</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #0000FF;">setcookie</span><span style="color: #009900;">&#40;</span><span style="color: #158C15;">&quot;nombre_cookie&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Y la segunda es usar <em>setcookie</em> y enviar como parámetro un tiempo de caducidad pasado.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #0000FF;">setcookie</span><span style="color: #009900;">&#40;</span><span style="color: #158C15;">&quot;nombre_cookie&quot;</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;&quot;</span><span style="color: #000000;">,</span> <span style="color: #0000FF;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000;">-</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #666666; font-style: italic;">//Fijate la fecha de caducidad 1 hora atrás</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielsegovia.com/eliminar-una-cookie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Definir una cookie</title>
		<link>http://www.danielsegovia.com/definir-una-cookie/</link>
		<comments>http://www.danielsegovia.com/definir-una-cookie/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 20:33:58 +0000</pubDate>
		<dc:creator>Daniel Segovia</dc:creator>
				<category><![CDATA[7.5 Cookies]]></category>

		<guid isPermaLink="false">http://www.danielsegovia.com/?p=821</guid>
		<description><![CDATA[La función setcookie define una cookie para ser enviada en las cabeceras HTTP, al ser enviada a través de las cabeceras es obligatorio que nuestro script no genere ninguna salida, esto se debe a que es una restricción del protocolo. Cualquier carácter que sea impreso, inclusive hasta una espacio, antes de usar setcookie producirá un [...]]]></description>
			<content:encoded><![CDATA[<p>La función <em>setcookie</em> define una cookie para ser enviada en las cabeceras HTTP, al ser enviada a través de las cabeceras es obligatorio que nuestro script no genere ninguna salida, esto se debe a que es una restricción del protocolo.<br />
Cualquier carácter que sea impreso, inclusive hasta una espacio, antes de usar <em>setcookie</em> producirá un error</p>
<p><em>setcookie</em> acepta 7 parámetros, sin embargo, solamente es obligatorio el primero, aquí una lista de los parámetros en el orden correcto de la función.</p>
<ul>
<li><strong>name</strong>: El nombre de la cookie.</li>
<li><strong>value</strong>: El valor que será guardado en la cookie.</li>
<li><strong>expire</strong>: El tiempo en el que expira la cookie. Es una fecha Unix, por lo que probablemente use la función <em>time()</em> o <em>mktime()</em>.</li>
<li><strong>path</strong>: Por defecto utiliza &#8216;/&#8217;, esto significa que la cookie estará disponible para todo el dominio. Por ejemplo sí este parámetro es seteado en &#8216;/administrador&#8217; la cookie podrá ser utilizada en el directorio administrador y todos sus subdirectorios.</li>
<li><strong>domain</strong>: La cookie estará disponible para el dominio</li>
<li><strong>secure</strong>: Indica si la cookie debe viajar en forma segura en una conexión HTTPS desde el cliente</li>
<li><strong>httponly</strong>: Si este parámetro esta en TRUE la cookie será legible solo por el protocolo HTTP, es decir no será posible acceder por otros lenguajes como ser javascript</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #0000FF;">setcookie</span><span style="color: #009900;">&#40;</span><span style="color: #158C15;">&quot;nombre_cookie&quot;</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;Este es el valor de mi cookie&quot;</span><span style="color: #000000;">,</span> <span style="color: #0000FF;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000;">+</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #666666; font-style: italic;">// La cookie expira en 1 hora.</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Ahora para recuperar la cookie tenemos $_COOKIE</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #0000FF;">echo</span> <span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'nombre_cookie'</span><span style="color: #009900;">&#93;</span><span style="color: #000000;">;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Recordemos que estos procesos se realizan a través de los headers HTTP, entonces si en un mismo script, seteo la cookie, recién ésta estará disponible en el próximo request que se realice sobre el dominio. Es decir, en nuestro primer request la cookie será enviada y se generará el archivo de texto con la información, por ende si necesito usar esta cookie estará disponible en el próximo request.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielsegovia.com/definir-una-cookie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducción a las Cookies</title>
		<link>http://www.danielsegovia.com/introduccion-a-las-cookies/</link>
		<comments>http://www.danielsegovia.com/introduccion-a-las-cookies/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 20:14:14 +0000</pubDate>
		<dc:creator>Daniel Segovia</dc:creator>
				<category><![CDATA[7.5 Cookies]]></category>

		<guid isPermaLink="false">http://www.danielsegovia.com/?p=817</guid>
		<description><![CDATA[Una cookie es información que se envía a través del servidor web y es almacenada en el disco rígido del visitante por medio del navegador en un archivo de texto. Cuando haya una nueva petición al mismo dominio las cookies desde nuestro disco rígido serán enviadas al servidor web, por lo tanto, de esta manera [...]]]></description>
			<content:encoded><![CDATA[<p>Una cookie es información que se envía a través del servidor web y es almacenada en el disco rígido del visitante por medio del navegador en un archivo de texto.<br />
Cuando haya una nueva petición al mismo dominio las cookies desde nuestro disco rígido serán enviadas al servidor web, por lo tanto, de esta manera nos permitirá recuperar la información guardada en la cookie, entonces de acuerdo a hayamos guardado en las cookies podremos determinar siguientes acciones.<br />
Una manera frecuente de usar una cookie es en los inicios de sesión automáticos, el famoso checkbox que dice &#8220;No cerrar sesión&#8221; en la mayoría de los portales.<br />
La identificación de la cookie es una combinación de la computadora, navegador y usuario.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielsegovia.com/introduccion-a-las-cookies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuración de sesiones</title>
		<link>http://www.danielsegovia.com/configuracion-de-sesiones/</link>
		<comments>http://www.danielsegovia.com/configuracion-de-sesiones/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 16:13:38 +0000</pubDate>
		<dc:creator>Daniel Segovia</dc:creator>
				<category><![CDATA[7.4 Sesiones]]></category>

		<guid isPermaLink="false">http://www.danielsegovia.com/?p=810</guid>
		<description><![CDATA[Ahora una explicación de los items más importantes en la configuración de las sesiones en PHP, en la siguiente imagen puede verse la configuración actual del servidor donde estemos corriendo nuestros scripts, con la función info(), nativa de PHP, en la sección Sessions session.auto_start en caso de estar encendido iniciará las sesiones automáticamente cuando los [...]]]></description>
			<content:encoded><![CDATA[<p>Ahora una explicación de los items más importantes en la configuración de las sesiones en PHP, en la siguiente imagen puede verse la configuración actual del servidor donde estemos corriendo nuestros scripts, con la función <em>info()</em>, nativa de PHP, en la sección Sessions</p>
<p><img src="http://www.danielsegovia.com/images/sessions.png" alt="Sesiones" /></p>
<ul>
<li><strong>session.auto_start</strong> en caso de estar encendido iniciará las sesiones automáticamente cuando los visitantes ingresen a nuestro sitio, por defecto esta apagado</li>
<li><strong>session.cache_expire</strong> determina el tiempo de vida de la sesión, éste está expresado en minutos</li>
<li><strong>session.name</strong> especifica el nombre de la sesión que se utiliza como nombre de la cookie. El valor predeterminado es PHPSESSID.</li>
<li><strong>session.save_path</strong> define el argumento que se pasa al controlador de almacenamiento. Esta será la ruta donde se creen los archivos de las sesiones.</li>
<li><strong>session.use_cookies</strong> especifica si el módulo usará cookies para almacenar el identificador de sesión en el cliente. El valor predeterminado es 1 (habilitado).</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.danielsegovia.com/configuracion-de-sesiones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trabajar con sesiones</title>
		<link>http://www.danielsegovia.com/trabajar-con-sesiones/</link>
		<comments>http://www.danielsegovia.com/trabajar-con-sesiones/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 20:27:48 +0000</pubDate>
		<dc:creator>Daniel Segovia</dc:creator>
				<category><![CDATA[7.4 Sesiones]]></category>
		<category><![CDATA[$_SESSION]]></category>
		<category><![CDATA[sesiones]]></category>
		<category><![CDATA[sesion_start()]]></category>

		<guid isPermaLink="false">http://www.danielsegovia.com/?p=804</guid>
		<description><![CDATA[Cómo hemos explicado anteriormente las sesiones nos guardarán información mientras pasemos de una página a la otra. Las sesiones en PHP trabajan con un array llamando $_SESSION y cada key que generemos serán el contenedor de la información que deseemos guardar. session_start() creará una nueva sesión o reanudará la sesión que ya fue creada. Esta [...]]]></description>
			<content:encoded><![CDATA[<p>Cómo hemos explicado anteriormente las sesiones nos guardarán información mientras pasemos de una página a la otra.</p>
<p>Las sesiones en PHP trabajan con un array llamando <strong>$_SESSION</strong> y cada key que generemos serán el contenedor de la información que deseemos guardar.<br />
<em>session_start()</em> creará una nueva sesión o reanudará la sesión que ya fue creada. Esta función envía varias cabeceras HTTP  por eso es importante que sea llamada antes de imprimir algún carácter en el navegador.</p>
<blockquote><p>
Nota: La configuración de PHP posee <strong>session.auto_start</strong>, por defecto en 0, por ende, deshabilitado. Sí es habilitado no se requerirá inicializar las sesiones con session_start()
</p></blockquote>
<p>Veamos un ejemplo, en el que con sesiones contaremos la cantidad de páginas que va visitando el usuario.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//header.php</span>
<span style="color: #0000FF;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
<span style="color: #0000FF;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000FF;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'contador'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'contador'</span><span style="color: #009900;">&#93;</span><span style="color: #000000;">++;</span>
<span style="color: #009900;">&#125;</span><span style="color: #0000FF;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'contador'</span><span style="color: #009900;">&#93;</span> <span style="color: #000000;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #000000;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span>
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Contador&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;header&quot;&gt;&lt;a href=&quot;1.php&quot;&gt;1&lt;/a&gt; - &lt;a href=&quot;2.php&quot;&gt;2&lt;/a&gt; - &lt;a href=&quot;3.php&quot;&gt;3&lt;/a&gt;&lt;/div&gt;
&lt;div id=&quot;contenido&quot;&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//footer.php</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span>
&lt;/div&gt;&lt;!--fin de div id contenido--&gt;
&lt;div id=&quot;footer&quot;&gt;Usted ha visitado <span style="color: #FF0303; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'contador'</span><span style="color: #009900;">&#93;</span><span style="color: #000000;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//1,php</span>
<span style="color: #0000FF;">require_once</span> <span style="color: #158C15;">'header.php'</span><span style="color: #000000;">;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span>
Usted esta en la p&amp;aacute;gina 1.php
<span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #0000FF;">require_once</span> <span style="color: #158C15;">'footer.php'</span><span style="color: #000000;">;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//2.php</span>
<span style="color: #0000FF;">require_once</span> <span style="color: #158C15;">'header.php'</span><span style="color: #000000;">;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span>
Ahora estamos en 2.php
<span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #0000FF;">require_once</span> <span style="color: #158C15;">'footer.php'</span><span style="color: #000000;">;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//3.php</span>
<span style="color: #0000FF;">require_once</span> <span style="color: #158C15;">'header.php'</span><span style="color: #000000;">;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span>
Esta es la &amp;uacute;ltima 3.php
<span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #0000FF;">require_once</span> <span style="color: #158C15;">'footer.php'</span><span style="color: #000000;">;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielsegovia.com/trabajar-con-sesiones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducción a sesiones</title>
		<link>http://www.danielsegovia.com/introduccion-a-sesiones/</link>
		<comments>http://www.danielsegovia.com/introduccion-a-sesiones/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 19:12:06 +0000</pubDate>
		<dc:creator>Daniel Segovia</dc:creator>
				<category><![CDATA[7.4 Sesiones]]></category>
		<category><![CDATA[sesion]]></category>
		<category><![CDATA[sesiones]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://www.danielsegovia.com/?p=801</guid>
		<description><![CDATA[Es habitual trabajar con sesiones en desarrollos PHP. El objetivo de las sesiones es almacenar información a través de los diferentes archivos mientras dure la navegación del usuario. Es decir, el usuario puede estar visitando las diferentes secciones de nuestra aplicación y nosotros podemos guardar determinados datos que creamos convenientes. Cuando un usuario ingresa a [...]]]></description>
			<content:encoded><![CDATA[<p>Es habitual trabajar con sesiones en desarrollos PHP. El objetivo de las sesiones es almacenar información a través de los diferentes archivos mientras dure la navegación del usuario. Es decir, el usuario puede estar visitando las diferentes secciones de nuestra aplicación y nosotros podemos guardar determinados datos que creamos convenientes.</p>
<p>Cuando un usuario ingresa a nuestra aplicación una sesión única es generada, ésta será exclusiva de él y durará el tiempo que él este en nuestro sitio. Cualquier información puede ser almacenada en ellas, datos del usuario, páginas que visite o algunas preferencias que seleccione.</p>
<p>PHP posee un conjunto de sencillas funciones para trabajar con las sesiones que veremos a continuación en este capítulo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielsegovia.com/introduccion-a-sesiones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Seguridad en aplicaciones Web</title>
		<link>http://www.danielsegovia.com/seguridad-en-aplicaciones-web/</link>
		<comments>http://www.danielsegovia.com/seguridad-en-aplicaciones-web/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 18:40:55 +0000</pubDate>
		<dc:creator>Daniel Segovia</dc:creator>
				<category><![CDATA[7.8 Seguridad]]></category>

		<guid isPermaLink="false">http://www.danielsegovia.com/?p=795</guid>
		<description><![CDATA[Es verdad que un porcentaje muy alto de los usuarios que usen nuestras aplicaciones seguirán los pasos que nosotros pretendemos que hagan. Luego tendremos un grupo reducido de usuarios que por medio de algún error hagan que la aplicación no se comporte como nosotros deseamos. Por último tendremos un grupo de usuarios malintencionados que busquen [...]]]></description>
			<content:encoded><![CDATA[<p>Es verdad que un porcentaje muy alto de los usuarios que usen nuestras aplicaciones seguirán los pasos que nosotros pretendemos que hagan.<br />
Luego tendremos un grupo reducido de usuarios que por medio de algún error hagan que la aplicación no se comporte como nosotros deseamos.<br />
Por último tendremos un grupo de usuarios malintencionados que busquen errores en nuestra aplicación con fines varios, pueden buscar robar información, el hecho romper simplemente por maldad, instalar algo en el servidor donde corre nuestra aplicación o cualquier otro fin.<br />
Sin importar que grupo de usuarios está accediendo a nuestra aplicación debemos tener un sistema seguro.<br />
Existen muchos niveles que puede ser blanco de ataque, así que desde el lado que nos compete debemos tomar todos los recaudos para que su funcionamiento sea óptimo y seguro.</p>
<p>Como primera medida es fundamental no creerle al usuario, nosotros pretendemos que el usuario nos envíe un número y él nos termina enviando una cadena de texto, por error, negligencia o mal intención. Para evitarlo validaremos que lo que recibimos es lo que pretendemos recibir.</p>
<p><a href="http://www.danielsegovia.com/entradas-de-usuarios/">En el ejemplo</a> anterior lo que se envía por el formulario ingresa directamente en la base de datos, ahora nosotros sabemos que queremos que llegue, entonces haremos un cast, esto significa forzar a que el dato se convierta en el tipo de dato que deseamos.</p>
<p>PHP ofrece estas posibilidades para forzar los tipos de datos.</p>
<ul>
<li>(int), (integer) &#8211; forzado a integer</li>
<li>(bool), (boolean) &#8211; forzado a boolean</li>
<li>(float), (double), (real) &#8211; forzado a float</li>
<li>(string) &#8211; forzado a string</li>
<li>(array) &#8211; forzado a array</li>
<li>(object) &#8211; forzado a object</li>
<li>(unset) &#8211; forzado a NULL (PHP 5)</li>
</ul>
<p>Le agregamos algunos campos al formulario para trabajar con más tipos de datos.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Registrarse&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Registraci&amp;oacute;n&lt;/h1&gt;
&lt;form method=&quot;post&quot; action=&quot;registrarse.php&quot;&gt;
    &lt;table width=&quot;400&quot;&gt;
        &lt;tr&gt;
            &lt;td width=&quot;150&quot;&gt;&lt;label&gt;Nombre:&lt;/label&gt;&lt;/td&gt;
            &lt;td width=&quot;250&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;nombre&quot; /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;label&gt;Email:&lt;/label&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;email&quot; /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;label&gt;Edad:&lt;/label&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;edad&quot; /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;label&gt;Colores:&lt;/label&gt;&lt;/td&gt;
            &lt;td&gt;
                Rojo - &lt;input type=&quot;checkbox&quot; name=&quot;colores[]&quot; value=&quot;Rojo&quot; /&gt; &lt;br /&gt;
                Celeste - &lt;input type=&quot;checkbox&quot; name=&quot;colores[]&quot; value=&quot;Celeste&quot; /&gt; &lt;br /&gt;
                Blanco - &lt;input type=&quot;checkbox&quot; name=&quot;colores[]&quot; value=&quot;Blanco&quot; /&gt; &lt;br /&gt;
                Negro - &lt;input type=&quot;checkbox&quot; name=&quot;colores[]&quot; value=&quot;Negro&quot; /&gt; &lt;br /&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;label&gt;Contrase&amp;ntilde;a:&lt;/label&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type=&quot;password&quot; name=&quot;contrasena&quot;/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td colspan=&quot;2&quot; align=&quot;right&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;registrarse&quot; value=&quot;Registrarse&quot;/&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Y aquí el procesamiento de lo que viene por el formulario tomando los recaudos de los que estamos hablando.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$mysqli</span> <span style="color: #000000;">=</span> <span style="color: #0000FF;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #158C15;">&quot;localhost&quot;</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;usuario&quot;</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;password&quot;</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;nombre_base&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysqli_connect_errno</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000FF;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #158C15;">&quot;Imposible conectarse: <span style="color: #009933; font-weight: bold;">%s</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #000000;">,</span> <span style="color: #990000;">mysqli_connect_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
    <span style="color: #0000FF;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #000000;">=</span> <span style="color: #158C15;">&quot;INSERT INTO usuarios (nombre,email,edad,colores,contrasena) VALUES (?,?,?,?,?)&quot;</span><span style="color: #000000;">;</span>
&nbsp;
<span style="color: #000088;">$nombre</span> <span style="color: #000000;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'nombre'</span><span style="color: #009900;">&#93;</span><span style="color: #000000;">;</span>
<span style="color: #000088;">$email</span> <span style="color: #000000;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #000000;">;</span>
<span style="color: #000088;">$edad</span> <span style="color: #000000;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'edad'</span><span style="color: #009900;">&#93;</span><span style="color: #000000;">;</span>
<span style="color: #000088;">$colores</span> <span style="color: #000000;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000FF;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'colores'</span><span style="color: #009900;">&#93;</span><span style="color: #000000;">;</span>
<span style="color: #000088;">$contrasena</span> <span style="color: #000000;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'contrasena'</span><span style="color: #009900;">&#93;</span><span style="color: #000000;">;</span>
&nbsp;
<span style="color: #000088;">$colores</span> <span style="color: #000000;">=</span> <span style="color: #0000FF;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$colores</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;,&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Ejecuto el método prepare y este me va a devolver el objeto */</span>
<span style="color: #0000FF;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span> <span style="color: #000000;">=</span> <span style="color: #000088;">$mysqli</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* Reemplazo las ? por las variable con bind_param */</span>
    <span style="color: #000088;">$stmt</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">bind_param</span><span style="color: #009900;">&#40;</span><span style="color: #158C15;">'ssiss'</span><span style="color: #000000;">,</span> <span style="color: #000088;">$nombre</span><span style="color: #000000;">,</span> <span style="color: #000088;">$email</span><span style="color: #000000;">,</span> <span style="color: #000088;">$edad</span><span style="color: #000000;">,</span> <span style="color: #000088;">$colores</span><span style="color: #000000;">,</span> <span style="color: #000088;">$contrasena</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* ejecuto el  query */</span>
    <span style="color: #000088;">$stmt</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* cierro stmt */</span>
    <span style="color: #000088;">$stmt</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span>
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Registrarse&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;<span style="color: #FF0303; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$nombre</span><span style="color: #000000;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>, usted se ha registrado exitosamente&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielsegovia.com/seguridad-en-aplicaciones-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entradas de usuarios</title>
		<link>http://www.danielsegovia.com/entradas-de-usuarios/</link>
		<comments>http://www.danielsegovia.com/entradas-de-usuarios/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 19:38:40 +0000</pubDate>
		<dc:creator>Daniel Segovia</dc:creator>
				<category><![CDATA[7.3 Entradas de usuarios]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[formularios php]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[procesar]]></category>
		<category><![CDATA[submit]]></category>

		<guid isPermaLink="false">http://www.danielsegovia.com/?p=786</guid>
		<description><![CDATA[Ahora que podemos mezclar el HTML y PHP necesitaremos que el usuario empiece a interactuar en nuestra plataforma. Una registro de usuarios es un ejemplo de la interacción que estoy hablando, el usuario completará sus datos en un formulario, luego estos serán enviados a un archivo PHP para ser procesados, de esta manera comenzaremos a [...]]]></description>
			<content:encoded><![CDATA[<p>Ahora que podemos mezclar el HTML y PHP necesitaremos que el usuario empiece a interactuar en nuestra plataforma.<br />
Una registro de usuarios es un ejemplo de la interacción que estoy hablando, el usuario completará sus datos en un formulario, luego estos serán enviados a un archivo PHP para ser procesados, de esta manera comenzaremos a ver como el usuario nos enviará información, en este caso lo guardaremos en una base de datos, pero es a modo de ejemplo ya que el proceso a realizar es indiferente para nosotros por que cualquiera sea la acción que tomemos no es importante, lo importante aquí es que estaremos recibiendo información a través del formulario para realizar la acción que creamos conveniente.</p>
<p>Los formularios HTML podemos, a grandes rasgos, dividirlos en 4.</p>
<ul>
<li>Apertura del formulario con el tag &lt;form></li>
<li>Los tags para que el usuario ingrese la información, por ejemplo &lt;input>, &lt;textarea> o &lt;select> entre otros</li>
<li>El botón para enviar el formulario con el tag &lt;input></li>
<li>EL cierre del formulario con el tag &lt;/form></li>
</ul>
<p>Creamos un formulario que pida al usuario ingresar su nombre completo, su email y una contraseña, estos datos serán enviados a un archivo PHP y será el encargado de guardarlos en una base de datos MySQL</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Registrarse&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Registraci&amp;oacute;n&lt;/h1&gt;
&lt;form method=&quot;post&quot; action=&quot;registrarse.php&quot;&gt;
    &lt;table width=&quot;400&quot;&gt;
        &lt;tr&gt;
            &lt;td width=&quot;150&quot;&gt;&lt;label&gt;Nombre:&lt;/label&gt;&lt;/td&gt;
            &lt;td width=&quot;250&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;nombre&quot; /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;label&gt;Email:&lt;/label&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;email&quot; /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;label&gt;Contrase&amp;ntilde;a:&lt;/label&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type=&quot;password&quot; name=&quot;contrasena&quot;/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td colspan=&quot;2&quot; align=&quot;right&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;registrarse&quot; value=&quot;Registrarse&quot;/&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Como podemos observar muchos de los tags HTML que utilizamos tienen lo que se denominan atributos</p>
<p>El tag &lt;form> posee 2 atributos, el primero es <em>method</em> y éste especificará el método HTTP que usará cuando envíe la información. El segundo es <em>action</em> y especifica donde será enviada la información cuando el formulario sea enviado.</p>
<p>Luego tenemos el tag &lt;input> nuestro primero atributo es <em>type</em> y posee las siguientes variantes button, checkbox, file, hidden, image, password, radio, reset, submit, text, en este ejemplo usamos 3 de éstas, text que será un campo de texto libre, password que también será un campo de texto libre pero no serán mostrados los caracteres que iremos tipeando y por último submit que será un botón que al presionarlo enviará el formulario completo al <em>action</em> del <em>form</em>. También tenemos el atributo <em>name</em> que es un nombre que identificará al elemento y el último atributo usado aquí es <em>value</em> este será el valor predeterminado que tomará el elemento.</p>
<p>Ahora recibamos la información que nos provee el formulario y guardemos ésta en la base de datos.<br />
Creamos un archivo registrarse.php (que es el action del formulario) e insertamos los datos.<br />
La información nos llegará al archivo PHP en un array llamado $_POST los índices del array serán igual a los <em>name</em> que hemos definido en el formulario</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #FF0303; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$mysqli</span> <span style="color: #000000;">=</span> <span style="color: #0000FF;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #158C15;">&quot;localhost&quot;</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;usuario&quot;</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;password&quot;</span><span style="color: #000000;">,</span> <span style="color: #158C15;">&quot;base&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysqli_connect_errno</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000FF;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #158C15;">&quot;Imposible conectarse: <span style="color: #009933; font-weight: bold;">%s</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #000000;">,</span> <span style="color: #990000;">mysqli_connect_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
    <span style="color: #0000FF;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #000000;">=</span> <span style="color: #158C15;">&quot;INSERT INTO usuarios (nombre,email,contrasena) VALUES (?,?,?)&quot;</span><span style="color: #000000;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Ejecuto el método prepare y este me va a devolver el objeto */</span>
<span style="color: #0000FF;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span> <span style="color: #000000;">=</span> <span style="color: #000088;">$mysqli</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* Reemplazo las ? por las variable con bind_param */</span>
    <span style="color: #000088;">$stmt</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">bind_param</span><span style="color: #009900;">&#40;</span><span style="color: #158C15;">'sss'</span><span style="color: #000000;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'nombre'</span><span style="color: #009900;">&#93;</span><span style="color: #000000;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #000000;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'contrasena'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* ejecuto el  query */</span>
    <span style="color: #000088;">$stmt</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* cierro stmt */</span>
    <span style="color: #000088;">$stmt</span><span style="color: #000000;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #FF0303; font-weight: bold;">?&gt;</span>
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Registrarse&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;<span style="color: #FF0303; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #158C15;">'nombre'</span><span style="color: #009900;">&#93;</span><span style="color: #000000;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>, usted se ha registrado exitosamente&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.danielsegovia.com/entradas-de-usuarios/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

