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
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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.