Jump to content

Recommended Posts

Hello, I pretty much got the part of how to do file.php?content=Whatever. The way I have my site set up is I have one div where all the content is shown. So something like this:

 

<div id="header">
<div id="content">
$_GET['conent'] etc......
</div>
</div>

 

That works perfectly. Now what I'm trying to do is on another page I have something like a Guide. Where the guides content is shown inside another div that's already inside the content div shown above. Did that make sense? oO Here's what I'm talking about:

 

 

<div id="header">
<div id="content">
$_GET['conent'] etc......
       <div id="guide">
              Links here
       </div>
       <div id="guidecontent">
               $_GET['links']
       </div>
</div>
</div>

 

Hope that makes sense. Now the way I have my links on under where it says "id=guides" is index.php?content=PHP&links=Intro". But I know that is wrong. Is there any way to do the way I'm showing? Here's a link to the page:

 

http://divnx.net/index.php?page=PHP

 

As you see, if you click on the right links, you will get errors saying not found. Here's how I laid out the code for the php:

 

	  <?php
     $guide = $_GET['guide'];
     if(!$guide) {
     include "guides/php/intro.php";
     }
     else if($guide=='Install')		{ include "guides/php/install.php"; }
     else if($guide=='Syntax')		{ include "guides/php/syntax.php"; }
     else if($guide=='Variables')	{ include "guides/php/variables.php"; }
     else if($guide=='Date')		{ include "guides/php/date.php"; }
     else if($guide=='Include')		{ include "guides/php/include.php"; }
     else if($guide=='Cookies')		{ include "guides/php/cookies.php"; }
     else if($guide=='Sessions')	{ include "guides/php/sessions.php"; }
     else if($guide=='DB_Intro')	{ include "guides/php/db_intro.php"; }
     else if($guide=='Connet')		{ include "guides/php/connect.php"; }
     else if($guide=='Create')		{ include "guides/php/create.php"; }
     else if($guide=='Insert')		{ include "guides/php/insert.php"; }
     else				{ echo "404 Page Not Found!"; }
  ?>

 

I was thining of making $guide = $_GET['guide']; to something like $_GET['&guide']; but that sounds wrong too.

 

Hope I made sense. Thank You  :)

Link to comment
https://forums.phpfreaks.com/topic/105310-solved-_get-question/
Share on other sites

I'd do this:

if(isset($_GET['guide']))
{
    $path = $_SERVER['DOCUMENT_ROOT'] . '/guides/php/';

    switch($_GET['guide'])
    {
        case 'Install':
        case 'Syntax':
        case 'Variables':
        case 'Date':
        case 'Include':
        case 'Cookies':
        case 'Sessions':
        case 'DB_Intro':
        case 'Insert':
                $path .= strtolower($_GET['guide']) . '.php';
        break;

        default:
            $path .= 'intro.php';
        break;
    }

    include $path;
}

Link to comment
https://forums.phpfreaks.com/topic/105310-solved-_get-question/#findComment-539292
Share on other sites

"$path = $_SERVER['DOCUMENT_ROOT'] . '/guides/php/';"

 

The

$_SERVER['DOCUMENT_ROOT']

is just telling the script basicly to find the root folder of the site, the main folder that www.whatever.com goes to, then it tells it to append guides/php/ to the end of that so it becomes www.whatever.com/guides/php/ that way later in your scripting you can just call the file itself with the use of that predefined variable with the doc root..

 

I could be wrong though that may also be just getting something like /htdocs/www/mysite/ and telling it to add the trailing guides/php/ part of it.. all in all its just to help make things a bit more dynamic, and easier on you in the end :-)

Link to comment
https://forums.phpfreaks.com/topic/105310-solved-_get-question/#findComment-539447
Share on other sites

$_SERVER['DOCUMENT_ROOT'] returns the full file path to your websites document root (where you upload your html/php files to etc). if you echo $_SERVER['DOCUMENT_ROOT'] it'll display your websites document root path, example path would be something like /home/yourite.com/public_html/

 

strtolower() converts the string defined in $_GET['guide'] to lowercase characters.

Link to comment
https://forums.phpfreaks.com/topic/105310-solved-_get-question/#findComment-539481
Share on other sites

I'd do this:

if(isset($_GET['guide']))
{
    $path = $_SERVER['DOCUMENT_ROOT'] . '/guides/php/';

    switch($_GET['guide'])
    {
        case 'Install':
        case 'Syntax':
        case 'Variables':
        case 'Date':
        case 'Include':
        case 'Cookies':
        case 'Sessions':
        case 'DB_Intro':
        case 'Insert':
                $path .= strtolower($_GET['guide']) . '.php';
        break;

        default:
            $path .= 'intro.php';
        break;
    }

    include $path;
}

 

I think the switch might be overkill.  You could get away with a single line of tertiary notation

 

$path = $_SERVER['DOCUMENT_ROOT'] . '/guides/php/';
$page = isset($_GET['guide']) ? strtolower($_GET['guide']) : 'intro';

include "$path/$page.php";

 

For those that don't get the notation it is

 

variable = (condition) ? if_condition_true : if_condition_false

 

so if $_GET['guide'] is set, $page takes the name of php file (which gets the .php in the include).  if not, then $page is set to intro. 

 

however it looks like your bigger issue was how you were referencing the $_GET and that seems to be in order now.

Link to comment
https://forums.phpfreaks.com/topic/105310-solved-_get-question/#findComment-539486
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.