I’ve been wondering what links like http://example.com/filename.php?dosomething and http://somesite.net?logoff do.
As I don’t know much about PHP, and english isn’t my native language, I’ve been unable to find good information like this.
I know that http://mysite.com/edit.php?editpassword and http://mysite.com/edit.php?editname could serve totally different content, but how can I implement it?
Let’s say that I want to implement these lines of code to ?editpassword
Password
<input type="password" name="password">
<input type="submit">
and these lines to ?editname
Type your name
<input type="text" name="name">
<input type="submit">
How could I do it in a file that could contain
<?php
require "includes/head.php";
require "includes/nav.php";
if(!isset($_SESSION['login'])){
header("Location: index.php");
}
?>
<div class="row-fluid">
<div class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">New</li>
<li><a href="#">sss</a></li>
</ul>
</div><!--/.well -->
</div><!--/span-->
<div class="span9">
<div class="row-fluid">
<div class="span9">
<h2>Some header</h2>
<p>Some text</p>
</div><!--/span-->
</div><!--/row-->
<div class="row-fluid">
?editname & ?editpassword should appear here.
</div><!--/row-->
<?php require "includes/footer.php"; ?>
something like that?
If there’s just
?foothe whole querystring which is available in$_SERVER['QUERY_STRING']is"foo".When using a HTML form with
method="GET"you get key-value pairs which are then available via$_GET['key']. Actually you also receive those pairs when using POST but then they are not visible in the URL and you access them via$_POST['key'].So your code would look like this assuming you want it totally simple and not use some advanced routing framework:
But I’d really suggest you to use proper GET variables instead of just plain query strings. Simply replace the first line of that snipped with this: