<?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>Seichleon &#187; Tutorial</title>
	<atom:link href="http://seich.martianwabbit.com/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://seich.martianwabbit.com</link>
	<description>Legendarido...</description>
	<lastBuildDate>Wed, 08 Sep 2010 00:27:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Basic of $_GET variables (PHP)</title>
		<link>http://seich.martianwabbit.com/basic-of-_get-variables-php/</link>
		<comments>http://seich.martianwabbit.com/basic-of-_get-variables-php/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 08:30:55 +0000</pubDate>
		<dc:creator>Seich</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://seich.martianwabbit.com/?p=96</guid>
		<description><![CDATA[Hello everyone, today I am posting a tutorial on the basic usage of the $_GET super variable in php. This tutorial was originally posted at the MWPS community forums, which almost never is read so I figured that this would be a better place for it to be. It goes through the basics of the [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everyone, today I am posting a tutorial on the basic usage of the $_GET super variable in php. This tutorial was originally posted at the MWPS community forums, which almost never is read so I figured that this would be a better place for it to be. It goes through the basics of the $_GET variable and some basic usage examples.<br />
<span id="more-96"></span><br />
First, I know most people will ask, especially if you are new with PHP, what’s so special about the $_GET Variable?</p>
<p>Well, there’s something really special about this variable, it allows you to get information directly from the url&#8230;. yeah that’s right there’s a way to get fast user input directly from the url no forms or anything, it doesn&#8217;t necessarily needs to be user input it can also be a script leaving behind some variables for the next script and many other uses you will be able to figure out by yourself after you are done with this tutorial&#8230;. the most know use for is used on most CMS and simple page scripts. Still figuring out how does it work? I am pretty sure you will recognize how it works with this example:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http://www.martianwabbit.com/page.php?id=home</div></td></tr></tbody></table></div>
<p>In the above example you can see something odd about the url the &#8220;?id=home&#8221; after the file name well that’s exactly where your $_GET variables are gotten from. I guess some of you will just think of the thousands of possibilities this opens and, how you can use it to improve your scripts.<br />
But how do I get the information stored on the &#8220;?id=home&#8221;?<br />
That’s simple first of you need to know that the above its saying that &#8220;id&#8221; equals &#8220;home&#8221; just as a variable $x = y;. Now that you know what it means you should be able to get the information easily.<br />
Well to use that information it is recommended that you assign a variable with it so, you could use it directly but you won’t be able to edit it along the script also this helps making it easier to call and read. This is how it works:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>simple isn&#8217;t it? now you can call the variable using $id and you will see how it gets whatever text it’s on the url.<br />
a simple way to see this in action is making a simple script:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">//set $id 's value to whatever is contained on the url.</span><br />
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//echo the variable's value.</span><br />
<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>In the above example we set $id with the value that came with url and then we echo &#8216;ed it.<br />
This is the simplified basics behind this variable but you can use this for a multitude of things. Before we go on to the &#8220;multitude of things&#8221; I want to show you how to get multiple values from a single url, yep that’s right you aren&#8217;t limited to 1 variable after the ?, you are limited&#8230;.well you are not limited on the number of values you can get from the url like this.<br />
But how do I get multiple values from the url do I separate them with a comma or what?<br />
well in fact you could separate them with a comma but that’s the less practical way the best way is to add additional values to the url like this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http://www.martianwabbit.com/page.php?id=20&amp;page=2</div></td></tr></tbody></table></div>
<p>Noticed how I added an additional variable and value there? yeah I simply added a &#038;(meaning &#8220;and&#8221;) and added an additional Name = Value, please notice that there is no additional ? after the &#038;.<br />
ok now I have two variables to play with but how do I manipulate both of them?<br />
well this simple example can explain it better than what I could:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <br />
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;you are looking for <span style="color: #006699; font-weight: bold;">$id</span>'s page <span style="color: #006699; font-weight: bold;">$page</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>see how simple it is? if the file above was named &#8220;page.php&#8221; and I typed in:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http://www.martianwabbit.com/page.php?id=home&amp;page=2</div></td></tr></tbody></table></div>
<p>In the browser I would get this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">you are looking for home's page 2</div></td></tr></tbody></table></div>
<p>Easy right? well this is how you add multiple variable names and values through the url.<br />
Now what? What can I do with all this information I just learned? well, I decided to include a little practical example.</p>
<p>Remember that I mentioned that this is commonly used in simple page systems? Well this is how it’s done:<br />
Imagine you want to have a specific page style to be used to display some articles you could make a new HTML page for each article (which would make you waste time and effort on ) or you could use a dynamic page to grab whatever page is requested from the url and simply append the contents to the page style you want to use.<br />
If you voted for the second option this is a way of doing it, it might get a little out of the scope of the tutorial but its only to illustrate a use for it:<br />
First, we need to make sure a value is always set, we going to use the variable $id and $page to specify a page name($id) and a page number($page). to make sure that there’s a variable value always not only when it’s specified on the url (i.e. to display a homepage) we do a simple check !isset (means &#8220;is not set&#8221;) if this is true then a default value is used. this is how it should look like:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">//we set a default value in case no page is being looked for.</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</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><br />
<span style="color: #666666; font-style: italic;">//in case no file is being looked up.</span><br />
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Home&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//if theres a value.</span><br />
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">//we set a default value in case no page number is specified.</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</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><br />
<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//if theres a value look for it.</span><br />
<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>ok now we are sure the variable is always there next thing we need is the html, our &#8220;template&#8221; so we make a simple html template mine looks like this:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>That’s enough for it to work. Okay, now it’s time to add some content. so we add a include into the body:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;html&gt;<br />
&lt;title&gt;&lt;/title&gt;<br />
&lt;/html&gt;<br />
&lt;body&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pages/<span style="color: #006699; font-weight: bold;">$id</span>-<span style="color: #006699; font-weight: bold;">$page</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <br />
&lt;/body&gt;</div></td></tr></tbody></table></div>
<p>ok that should work perfectly but let’s add some additional stuff to make it look nicer and more dynamic&#8230; we can add a title dynamically getting it from the page name:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;html&gt;<br />
&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;<br />
&lt;/html&gt;<br />
&lt;body&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pages/<span style="color: #006699; font-weight: bold;">$id</span>-<span style="color: #006699; font-weight: bold;">$page</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <br />
&lt;/body&gt;</div></td></tr></tbody></table></div>
<p>ok our tile is dynamically changed but this script is still missing some stuff for it to be practical we will add a file check before including the content and an error in case the file doesn&#8217;t exist:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">//make sure file exists before attempting to open it.</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/file_exists"><span style="color: #990000;">file_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pages/<span style="color: #006699; font-weight: bold;">$id</span>-<span style="color: #006699; font-weight: bold;">$page</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//if it exists open the file.</span><br />
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pages/<span style="color: #006699; font-weight: bold;">$id</span>-<span style="color: #006699; font-weight: bold;">$page</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//in case file doesn't exist throw a error.</span><br />
<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;file not found&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;/body&gt;</div></td></tr></tbody></table></div>
<p>now it’s done you should have this or something quite similar to it:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <br />
<span style="color: #666666; font-style: italic;">//By Seich(http://martianwabbit.com/)</span><br />
<span style="color: #666666; font-style: italic;">//we set a default value in case no page is being looked for.</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</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><br />
<span style="color: #666666; font-style: italic;">//in case no file is being looked up.</span><br />
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Home&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//if theres a value.</span><br />
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">//we set a default value in case no page number is specified.</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</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><br />
<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//if theres a value look for it.</span><br />
<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;html&gt;<br />
&lt;!--html part--&gt;<br />
&lt;head&gt;<br />
&lt;!--set title dynamically depending on what file is being read.--&gt;<br />
&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$id</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;!--Change body Dynamically depending on the content--&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">//make sure file exists before attempting to open it.</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/file_exists"><span style="color: #990000;">file_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pages/<span style="color: #006699; font-weight: bold;">$id</span>-<span style="color: #006699; font-weight: bold;">$page</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//if it exists open the file.</span><br />
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pages/<span style="color: #006699; font-weight: bold;">$id</span>-<span style="color: #006699; font-weight: bold;">$page</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">//in case file does not exist throw a error.</span><br />
<span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;file not found&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;/body&gt;</div></td></tr></tbody></table></div>
<p>now you need to create a folder called &#8220;pages&#8221; in the same directory you have this script , files inside should be ending with a .php and should be named like this &#8220;name-number.php&#8221; starting from number 1 for it to work with no problems. With this you can now call the file using the a url.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http://martianwabbit.com/page.php?id=name&amp;page=2</div></td></tr></tbody></table></div>
<p>this would open file : name-2.php in the body.<br />
Okay, there you got it we have gone through all the basics behind the $_GET variable and now you know how special it is. You also know how practical it can be and how much time it can save you (as PHP can in general) and we also went through a practical example which can obviously be expanded as much as you want to make&#8230; idk&#8230; a full CMS or anything you can dream of&#8230;<br />
Hope this helped you understand one important part behind PHP. if by any reason you don&#8217;t understand something or have a question or simply love it just leave a comment here.</p>
]]></content:encoded>
			<wfw:commentRss>http://seich.martianwabbit.com/basic-of-_get-variables-php/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
