PHP ID help

Hello,

I haven’t used PHP in many years, and just started getting back into making website. I was looking for a great PHP Script, and I found some stuff to use like: index.php?id=news

Here is my site: http://7sinconfessions.com/

What I want to happen is when you click on the link Confess, instead of it opening in a new page, I want it to open on the same page right below the menu items. Same would go for any link clicked on that page. How do I go about this? I remember a script a long time ago that was easy to use, but cant remember it.

Thanks for help!

-Eric

index.php
[php]<?php
session_start();

//----------------------------------------------------------------------------------------
// Allow direct access to this page
//----------------------------------------------------------------------------------------

define(‘securepage’, true);

//----------------------------------------------------------------------------------------
// Include page display logic
//----------------------------------------------------------------------------------------

include_once(’./includes/display_pages.php’);

//----------------------------------------------------------------------------------------
// Include Page Header
//----------------------------------------------------------------------------------------

include_once(’./includes/header.php’);
?>

<?php include_once('./includes/navbar.php'); ?>
     <div class="col-md-3">
        <?php include_once('./includes/menu.php'); ?>
     </div>

     <div class="col-md-9">
        <?php include_once("$include"); ?>
     </div><!-- /.col-md-9 -->
     
  </div><!-- /.row -->
</div> <!-- /.container -->
<? include_once('./includes/footer.php'); ?>
[/php]

display_pages.php
[php]<?php

//------------------------------------------------------------------------
// Restrict access to these files
//------------------------------------------------------------------------

// Specify some disallowed paths
$restricted_files = array(
‘header’,
‘footer’
);

//----------------------------------------------------------------------------------------
// Display Pages
//----------------------------------------------------------------------------------------

if (isset($_GET[‘p’]))
{

$page = basename($_GET['p']);

if (!in_array($page, $restricted_files) && file_exists("./includes/$page.php"))
    {
    $include = "./includes/$page.php";
    }
else
    {
    $include = './includes/default.php';
    }
}

else
{
$include = ‘./includes/default.php’;
}
?>[/php]

includes/default.php
[php]<?php
if (!defined(‘securepage’)) {
die(‘

Direct File Access Prohibited

’);
}
?>

Welcome

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel

[/php]

I put in all of those files, but I am still a bit confused…

If you go back to my site, I have the menu links on the site, when you click on the link it still opens up in a new window, how do I get it to open below?

menu.php

[php]<?php
if (!defined(‘securepage’)) {
die(‘

Direct File Access Prohibited

’);
}
?>

Confessions

[/php]

Thanks for the help btw!!!

http://7sinconfessions.com?p=confess

That worked! Thank you so much!!!

-Eric

Feel free to give a brutha some karma. Link is next to my name

Okay, I need a little more help.

If you goto:

http://7sinconfessions.com/?p=confess

The link that says “lust” on the top, I’m having that goto another directory in the includes folder. the directory being: confession/lust/lust.php, the link I have is:

Lust

That does not work however, it goes to the main page.

Help please! Thanks

Its not setup to work like that.

Anyway to put it in the script for it to work like that as well? Or will I just have to include everything in one directory (thats a lot of files!!)

[php]index.php?p=pageNameHere&f=folderNameHere[/php]

[php] $page = basename($_GET[‘p’]);
$folder = basename($_GET[‘f’]);

if (!in_array($page, $restricted_files) && file_exists("./$folder/$page.php"))
    {
    $include = "./$folder/$page.php";
    }[/php]

I don’t know what I am doing wrong here… I tried to input exactly what you said, and I guess maybe I am just being dumb.

Here is what I have for the code now:

Display_pages.php

[php]<?php

//------------------------------------------------------------------------
// Restrict access to these files
//------------------------------------------------------------------------

// Specify some disallowed paths
$restricted_files = array(
‘header’,
‘footer’
);

//----------------------------------------------------------------------------------------
// Display Pages
//----------------------------------------------------------------------------------------

if (isset($_GET[‘p’]))
{

 $page = basename($_GET['p']);
 $folder = basename($_GET['f']);
 
 // If it's not a disallowed path, and if the file exists, update $action
 if (!in_array($page, $restricted_files) && file_exists("./$folder/$page.php"))
 
 {
     $include = "./$folder/$page.php";
     }
	  else
     {
     $include = "./includes/$page.php";
     }

     {
     $include = './includes/default.php';
     }
 }

else
{
$include = ‘./includes/default.php’;
}

?>[/php]

menu.php
[php]<?php
if (!defined(‘securepage’)) {
die(‘

Direct File Access Prohibited

’);
}
?> Home | Confess | Confessions [/php]

Confess.php

[php]

  • Lust
  • Gluttony



    [/php]

    Currently with the code, now my menu links arent going anywhere, and when they did go somewhere, the links werent opening up to the folder…

    If you wanna PM me, I can give you access to the ftp site so you can view the files better if you wish!

    Sorry to be so dumbfounded here

    -Eric

  • What is your directory structure for all the page files? The code I gave you is for the other folders to be at the same level as includes, not in it.

    Code I gave you would be like this
    <a href="?p=gluttony&f=gluttony"

    NOT
    <a href="?p=gluttony&f=confess/gluttony"

    are you wanting:??

    includes/folder1/
    includes/folder2/

    or

    rootDir/includes/
    rootDir/folder1/
    rootDir/folder2/

    If all the folders will be in the confess folder then do this:

    [php] if (!in_array($page, $restricted_files) && file_exists("./confess/$folder/$page.php"))

     {
          $include = "./confess/$folder/$page.php";
          }[/php]

    http://7sinconfessions.com

    When you click on “confess” it’s currently not opening up to any page, with the new code I put in for the folders… the “confess” link is in the includes folder. I put it in root too, to see if that was the problem and its not…

    All the other folders are in the includes folder as:

    includes/confess/lust/lust.php
    includes/confess/envy/envy.php

    etc etc

    [php] if (!in_array($page, $restricted_files) && file_exists("./includes/confess/$folder/$page.php"))

     {
           $include = "./includes/confess/$folder/$page.php";
           }[/php]
    

    ?p=lust&f=lust ?p=envy&f=envy

    Still having a problem opening up the menu link to see if the subdirectory stuff works

    [php]<?php

    //------------------------------------------------------------------------
    // Restrict access to these files
    //------------------------------------------------------------------------

    // Specify some disallowed paths
    $restricted_files = array(
    ‘header’,
    ‘footer’
    );

    //----------------------------------------------------------------------------------------
    // Display Pages
    //----------------------------------------------------------------------------------------

    if (isset($_GET[‘p’]))
    {

     $page = basename($_GET['p']);
     $folder = basename($_GET['f']);
     
     // If it's not a disallowed path, and if the file exists, update $action
     if (!in_array($page, $restricted_files) && file_exists("./includes/confess/$folder/$page.php"))
     
     {
         $include = "./includes/confess/$folder/$page.php";
         }
    	  else
         {
         $include = "./includes/$page.php";
         }
    
         {
         $include = './includes/default.php';
         }
     }
    

    else
    {
    $include = ‘./includes/default.php’;
    }

    ?>[/php]

    menu.php

    [php]<?php
    if (!defined(‘securepage’)) {
    die(‘

    Direct File Access Prohibited

    ’);
    }
    ?> Home | Confess | Confessions [/php]

    When you are on http://7sinconfessions.com/ and click on the “confess” link, it just sits on the index page and doesnt goto the actual url I have nested in the same folder as display_pages.php

    The confess link is missing the folder part of the url. It needs to be how you have the confessions link right now. The way the confessions link is, there needs to be a folder in includes named envy and a page in the envy folder named envy.php

    Sponsor our Newsletter | Privacy Policy | Terms of Service