Php get function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gippo
Forum Newbie
Posts: 4
Joined: Tue Nov 17, 2009 10:45 pm

Php get function

Post by gippo »

I want to make my website like.

Code: Select all

http://sitename.com/?=guide
And it will show the guide. And so on.

I have read some tutorials on the $_get[] functions. But I do no't know how to use it for linking other php but using the "?=" instead of "guide.php"
User avatar
angelicodin
Forum Commoner
Posts: 81
Joined: Fri Nov 13, 2009 3:17 am
Location: Oregon, USA

Re: Php get function

Post by angelicodin »

Hi and welcome com phpdn.

With the get method it's all a matter of making sure you are setting and getting the data right. Here is a simple example with mark up.

Code: Select all

<?
if(isset($_GET['isitfriday'])){ //check to see if the value is friday or not
    $isitfriday = $_GET['isitfriday'];
    if(strtolower($isitfriday) === "yes"){
        echo "Thank god it's FRIDAY!!!"; //if=yes echo
    }else{
        echo "Not quite Friday yet."; //if!=yes echo
    }
}else{ //if there is no value set, then echo links.
    echo "<a href=\"page.php?isitfriday=yes\">If today is Friday, click here</a><br><a href=\"page.php?isitfriday=no\">If today is not Friday, click here</a>";
}
?>
so when you are going to send the data to another page (what ever page that may be) first do the link to the page "http://www.yoursite.com/test_page.com" then add the $_GET method to it. "http://www.yoursite.com/test_page.com?v ... x&var3=xxx". var1, 2, and 3 being your own data of course.

Any questions about this?
gippo
Forum Newbie
Posts: 4
Joined: Tue Nov 17, 2009 10:45 pm

Re: Php get function

Post by gippo »

I really still don't get it. :[
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Php get function

Post by Weiry »

When a url uses a link like what your after, the main file is not called guide.php, its actually index.php
Because index.htm, index.html, index.php etc are default pages when a web page opens, it looks for these files first.

So if you have an index.php in a "myDirectory" folder, then you dont actually need to type /index.php
Example:

Code: Select all

http://mywebsite.com/myDirectory/index.php
http://mywebsite.com/myDirectory/
These two links are the same page (assuming you dont have anything other than index.php in the folder that could override it)

So when you want a link like this:

Code: Select all

http://mywebsite.com/myDirectory/?page=guide
Actually refers to the link:

Code: Select all

http://mywebsite.com/myDirectory/index.php?page=guide
To get the page value from the index.php file, you would need something like this:

Code: Select all

<?php
if(!isset($_GET['page']){
    $page = "index";  // if there is no page specified, use the default page
}else{ 
    $page = $_GET['page'];  // if there is a page specified by $_GET, use it instead.
}
 
/*
*  This is where you can now call each page as you need it.
*  There are many ways in which you can do this, but if you
*  wanted to INCLUDE a file 'guide.php' when the page specified
*  is 'guide', then you would use something like this.
*/
 
if($page == "guide"){
    include_once("guide.php");
}elseif($page == "info"){
    include_once("info.php");
}else{
    include_once("index.php"); // the index page is only shown if no other pages are specified.
}
?>
Hope that clears up a few things :D
fubariser
Forum Newbie
Posts: 5
Joined: Thu Nov 19, 2009 2:33 am

Re: Php get function

Post by fubariser »

Just contributing...dirty, but I DO hope you get the concept

Code: Select all

 
 
<?php
 
if( isset($_GET['page']) ):
    
    $page = $_GET['page']; // pass the value of $_GET['page'] to a local variable for easy use;
    
    switch($page): // use a switch condition to refer pages from the var $page
    
        case 'home':
            include_once('home.php');
        break;
        case 'guide';
            include_once('guide.php'); // load the guide page
        break;
        case 'about us';
            include_once('about_us.php');
        break;
        default:
            include_once('home.php');
        break;
    
    endswitch;
 
endif;
 
?>
 
 
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

But, just a note, if that's all you are trying to do, you might as well just go to http://mywebsite.com/myDirectory/guide.php
Post Reply