Jump to content

Querystring in URL not working


soopafly

Recommended Posts

Hi all!
I've been out of the developing scene for quite a while now and have a very n00by question.  Sorry if I'm not using the correct terminology as well  :P

I'm developing a very simple page. Let's just say I want to have a homepage, and a contact page, but I want to use one php file.

Here's my situation:

- File is called "index.php"
- User clicks a link of "index.php?page=contact" on the homepage which takes them to the contact page

Here's what the PHP part looks like in my index.php:

[code]
<?php
if ($page==contact) {
  echo "Contact me here!";
} else {
  echo "Here is my homepage";
}
?>
[/code]

When I test the site, the page goes straight to the homepage, even when I have "index.php?page=contact" in the URL.  Help?
Link to comment
https://forums.phpfreaks.com/topic/29588-querystring-in-url-not-working/
Share on other sites

[quote author=mgallforever link=topic=117491.msg479368#msg479368 date=1165361341]
[code]
<?php
$page = $_GET['page'];

if($page == contact){
echo "contact page";
}else {
echo "homepage";
//or you can redirect it
//header("Location: index.php?page=home");
};
?>
[/code]
[/quote]

That did it!  Thank you SO MUCH!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.