Many have asked me via Skype how to create "dynamic" pages in PHP. What I'm talking about is a URL such as: "www.example.com/post.php?id=47294729" or "www.example.info/page.php?name=aboutme".
Doing this is very simple. Here's how.
Firstly, you'll want to check to make sure the GET variable is "set". We'll use a PHP function called "isset" (see? isset -> is set) to check this.
So, what this will do is look in the GET array (basically what's IN the URL) for that variable. So, if there is a page variable set in the URL, then that will go to "//do something" and otherwise it will show that message.
Now, to make a "dynamic" page with this, you'll want to check what page they're looking for.
This is how you'd do that:
Now, what the code does after the above is head inside of the isset condition and check what that variable is actually set to. If it's set to "about" (http://example.info/page.php?page=about), then it will show "Some info all about me!", and if there is nothing set or something unrecognized set (http://example.info/page.php?page.php or http://example.info/page.php?page=4gpreds), then it will show "This is the home page!"
Thanks for reading and I hope this helped out in some way 🙂 :great:
Doing this is very simple. Here's how.
Firstly, you'll want to check to make sure the GET variable is "set". We'll use a PHP function called "isset" (see? isset -> is set) to check this.
Code:
<?php
if (isset($_GET['page'])) {
//do something
} else {
echo "Sorry, there was no page provided. I have no clue what you're looking for!";
}
?>
So, what this will do is look in the GET array (basically what's IN the URL) for that variable. So, if there is a page variable set in the URL, then that will go to "//do something" and otherwise it will show that message.
Now, to make a "dynamic" page with this, you'll want to check what page they're looking for.
This is how you'd do that:
Code:
<?php
if (isset($_GET['page'])) {
if ($_GET['page'] == "about") {
echo "Some info all about me!";
} else {
echo "This is the home page!";
}
} else {
echo "Sorry, there was no page provided. I have no clue what you're looking for!";
}
?>
Now, what the code does after the above is head inside of the isset condition and check what that variable is actually set to. If it's set to "about" (http://example.info/page.php?page=about), then it will show "Some info all about me!", and if there is nothing set or something unrecognized set (http://example.info/page.php?page.php or http://example.info/page.php?page=4gpreds), then it will show "This is the home page!"
Thanks for reading and I hope this helped out in some way 🙂 :great:







