Re: navigation include not functioning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Okay, I see how href="?page=contact" would work, and I do indeed have only
one file (which loads includes), but it still is not working. Clicking a
link, be href=?page=contact, href=?page=services, whatever, it still loads
the page with the ?page=whatever attached to the URL, but it is not
subsituting the $page variable within the include snippets, and it just
loads the 'about' versions of all includes (/phpincludes/about_content.php
as opposed to /phpincludes/services_content.php or whichever).

This is really stumping me and try as I might I cannot see why it will not
work. Here is some of my code as it is currently:

On default.php:

[code=default.php]

<html>
<head>
<?php

$pages = array(
// list of includes:
 'about' , 'services', 'portfolio', 'contact'
);
$page = isset($_GET['page']) && isset($pages[$_GET['page']])  ?
$_GET['page'] : 'about';
// about is default page here

?>
<title>

[/code]

then in the body tags

[code=default.php]

<td><?php include('phpincludes/' . $page . '_centerbar.php'); ?></td>
</tr>
 <?php include('phpincludes/nav2.php'); ?>
 <tr>

[/code]
[code=nav2.php]

<a href="?page=services">SERVICES</a>

[/code]

It is surprisingly little code and I am starting to wonder if any php
settings on my server are inhibiting this. What do you think?



2009/8/5 ollisso <ollisso@xxxxxxxxxx>

> On Wed, 05 Aug 2009 22:08:30 +0300, Allen McCabe <allenmccabe@xxxxxxxxx>
> wrote:
>
> You can do something like that:
>
> links:
> <a href='?page=contact'>Contact</a>
>
> This will work if you have only one file, all the time and it is default
> one for current folder. (normally that is index.php, might be default.php in
> your case)
>
> Second option is to use more harder approach:
>
> $pos    =
> min(strpos($_SERVER['QUERY_STRING'],'&'),strpos($_SERVER['QUERY_STRING'],'='));
> $act    = ($pos!==false) ? substr($_SERVER['QUERY_STRING'], 0,  $pos) :
> $_SERVER['QUERY_STRING'];
> $page   = strtolower($act);
>
> then you can use links like:
> href='?contact'
> or if you need:
> href='?contact=1' (in case of GET forms)
>
>
> Third option is to use mod_rewrite, but this is slightly harder :)
>
> But then you will be able to use links like:
> www.domain.com/contact/
> (which will work like: index.php?page=contact internally)
>
> About checking what is included:
> Imagine following scenario:
>
> $page   = isset($_GET['page']) ? $_GET['page'] : 'about';
>
> include 'modules/'.$page.'.php';
>
> Problem here is that you can include ANY file.
> For example:
> ?page=../index
> will work as:
> include 'modules/../index.php';
>
> Which is crearly not what is intended.
>
> There is also much more dangerous scenarios of this.
>
> I hope this explains something :)
>
>
>
> Excellent, your snippet is working nicely. Thank you!
>>
>> Unfortunately, when I click a link ( <a href="
>> http://uplinkdesign.hostzi.com/default.php?page=contact";> ),
>> deafult.php?contact shows in the browser, but the default (about) content
>> is
>> loading.
>>
>> Also, I don't know what you mean by checking what is included.
>>
>> 2009/8/5 ollisso <ollisso@xxxxxxxxxx>
>>
>> On Wed, 05 Aug 2009 20:19:00 +0300, Allen McCabe <allenmccabe@xxxxxxxxx>
>>> wrote:
>>>
>>> Sure.
>>>
>>>>
>>>> When I load my site, default.php loads ( displaying:
>>>> http://uplinkdesign.hostzi.com/ in the browser as expected). $thisPage
>>>> is
>>>> set to "about" via:
>>>>
>>>> <?php
>>>> if (!isset($thisPage)) {
>>>>  $thisPage="about";
>>>>  } else {
>>>>  $thisPage = addslashes($_GET['page']);
>>>>  }
>>>> ?>
>>>>
>>>> in the <head> tags.
>>>>
>>>>
>>>> I am seeing this:
>>>>
>>>> The first 2 includes work just fine, loading to proper middle section
>>>> and
>>>> proper right-hand-side page content, the navigation include also loads,
>>>> but
>>>> all the of "tabs" (background images) are the currentpage image, as
>>>> opposed
>>>> to not, as they should be (the the exception of the About Us background
>>>> image).
>>>>
>>>> It seems that $thisPage is equal to all four values, so all the if
>>>> statements within navigation tell PHP to load the current page image for
>>>> all
>>>> 4 links.
>>>>
>>>> Does this help?
>>>>
>>>>
>>> Looks like you need something like that:
>>> $pages  = array(
>>> // list of modules you have, for example:
>>>  'about' , 'help', etc
>>> );
>>> $page   = isset($_GET['page']) && isset($pages[$_GET['page']])  ?
>>>  $_GET['page'] : 'about';
>>> // about is default page here
>>>
>>> then just:
>>> include 'modules/'.$page.'.php';
>>>
>>> Always remember that you have to check what is included.
>>> Best approach(if possible) to have a predefined list of all modules which
>>> can be included.
>>>
>>> Else, there is some nasty things like:
>>> ?page=../index.php
>>> (infinity recurssion)
>>>
>>> ?page=http://otherhost.com/hacker.
>>> (inclusion of malicious script)
>>> and so on.
>>>
>>>
>>>
>>>
>>> On Wed, Aug 5, 2009 at 10:10 AM, Jerry Wilborn <jerrywilborn@xxxxxxxxx
>>>
>>>> >wrote:
>>>>
>>>> Look
>>>>
>>>
>>>
>>>  I'm having trouble understanding your description of the problem.  Can
>>>
>>>> you
>>>>> tell us what you're seeing and what you expect to see?
>>>>> Jerry Wilborn
>>>>> jerrywilborn@xxxxxxxxx
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Aug 5, 2009 at 12:00 PM, Allen McCabe <allenmccabe@xxxxxxxxx
>>>>> >wrote:
>>>>>
>>>>> I am trying to generate pages by importing content in includes, and
>>>>> using
>>>>>
>>>>>> my
>>>>>> navigation include to tell PHP to replace a $thisPage variable which
>>>>>> all
>>>>>> the
>>>>>> includes use <?php include('phpincludes/' . $thisPage . '.php') ?>
>>>>>>
>>>>>> The idea behind it (I know tons of people do it, but I'm new to this
>>>>>> concept), is to have a 'layout' page where only a variable changes
>>>>>> using
>>>>>> $_GET on an href (index.php?page=services or index.php?page=about) to
>>>>>> load
>>>>>> the new 'pages'.
>>>>>>
>>>>>> PROBLEM:
>>>>>> All my links are displaying the current page state, and links are not
>>>>>> building around the link text (hrefs are built conditionally with if
>>>>>> $thisPage != services then build the link, otherwise leave it as
>>>>>> normal
>>>>>> text). Same thing with the background image behind the link text (to
>>>>>> indicate a page's current position). If the condition is not true, all
>>>>>> the
>>>>>> links (except the true current 'page') are supposed reload index.php
>>>>>> and
>>>>>> pass a variable to itself to place into $thisPage using
>>>>>> href="index.php?page=" (after which I have a variable which stores
>>>>>> "about"
>>>>>> or "services" within the if statement near the link text.
>>>>>>
>>>>>> If this sounds like something you are familiar with (former issues and
>>>>>> whatnot) please let me know what I'm doing wrong. I would be happy to
>>>>>> give
>>>>>> you any code you want to look at (index.php or navigation.php,
>>>>>> whatever).
>>>>>>
>>>>>> Thanks again for your help PHP gurus!
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux