passing information from a browser

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
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

passing information from a browser

Post by michaelk46 »

:banghead: I am rather confused on how this works...

I have setup a MySQL database that contains information for individual webpages. I also setup a PHP page to automatically create those webpages based on the pagename that is stored in the database.

The part that I do not understand is how the information necessary to create the pages is supposed to get from the browser to the PHP page so the correct webpage can be generated.

I hope that is clear enough to answer... If not I can clarify.

Thanks in advance
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: passing information from a browser

Post by AbraCadaver »

In many cases people opt for the following:

http://www.example.com/index.php?page=home

Then in index.php you can take the value of $_GET['page'] and use that.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

Re: passing information from a browser

Post by michaelk46 »

Is that something that is passed automatically, or is there something that you have to setup before it works. The part that i am referring to is index.php?page=home. I understand how to use the get to read the information.

That might not be clear, but that's just how confused I am about this.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: passing information from a browser

Post by AbraCadaver »

You would construct your links on the pages to look like that. Imagine you have a header on every page with links to 'About Us', 'Contact', 'Support', etc.. Then you would write the links like this:

Code: Select all

<a href="index.php?page=about_us">About Us</a>
etc...
Then in index.php any of the variables in the URL (get parameters) are availbale in the $_GET array. So you could do something like this (very simplified example):

Code: Select all

switch ($_GET['page']) {
    case 'about_us':
        //get page stuff from database and assign to var or vars, etc...
        break;
    //etc...
} 
//echo your page
-- or --

Code: Select all

$query = "SELECT * from pages WHERE page_name = '" . mysql_real_escape_string($_GET['page']) . "'";
//echo or do stuff with results
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: passing information from a browser

Post by Christopher »

Moved to PHP Code.
(#10850)
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

Re: passing information from a browser

Post by michaelk46 »

So the name of every page would be index.php?page= and then whatever the actual page name is. Am i getting that correctly?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: passing information from a browser

Post by AbraCadaver »

michaelk46 wrote:So the name of every page would be index.php?page= and then whatever the actual page name is. Am i getting that correctly?
Yes, it could be or it could be a number or whatever you have stored in the DB that you can query to get your page data.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

Re: passing information from a browser

Post by michaelk46 »

Thanks for all your help...that's what I needed to know
Post Reply