using index.php with multiple pages?

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 10171 Views - Last Post: 02 September 2011 - 04:03 PM Rate Topic: -----

#1 dbeaird727  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 238
  • Joined: 13-December 10

using index.php with multiple pages?

Posted 02 September 2011 - 03:07 PM

Let's say that I have page1.html, page2.html, page3.html and an index.php file with includes to these pages. Most dynamic pages I have seen are set up with different parts of the page included in the index file.. How would I include these different pages and still make it dynamic? If that makes any sense at all.
Is This A Good Question/Topic? 0
  • +

Replies To: using index.php with multiple pages?

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10391
  • View blog
  • Posts: 38,455
  • Joined: 27-December 08

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:08 PM

Let's step back- what exactly are you trying to do? What is the purpose of the includes? We need more details and specifics to better advise you.
Was This Post Helpful? 0
  • +
  • -

#3 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:15 PM

I'm getting a feeling dbeaird727 is aiming towards something that involves the .htaccess file

OR, dynamic as in the content in the included file is dynamic as well.

Which would use the simple answer of including another php file that uses the same variables declared in the index.php

This post has been edited by VolcomMky: 02 September 2011 - 03:17 PM

Was This Post Helpful? 0
  • +
  • -

#4 dbeaird727  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 238
  • Joined: 13-December 10

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:17 PM

Well I was using the includes in the index.php file in order to make my site dynamic? I'm new to all of this but I'm learning quickly. Basically, if I have a page called page1.html and page2.html, which are different pages. (I would link the first to the second) They are in different folders on my test server. so the path is host/templates/page1.html and host/templates/page2.html. I basically want these to be run by a basic index.php file. Do I need one index file in each folder for each html page or just one in the root? and how would I set these up?

Yes, I will use that. I guess I'm just trying to get the layout of my folders and paths correct before I use the .htaccess file.
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10391
  • View blog
  • Posts: 38,455
  • Joined: 27-December 08

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:17 PM

Why do you want index.php to include both? What exactly are you trying to do? What is the purpose of your application?
Was This Post Helpful? 0
  • +
  • -

#6 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:20 PM

Are you trying to include page1.html, but want to include page2.html if you click a link to look at a different section?
Was This Post Helpful? 0
  • +
  • -

#7 dbeaird727  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 238
  • Joined: 13-December 10

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:24 PM

I have a website, let's call it mysite.com I have a home page where users can log in and then an account page where they can view their information. So I have two different pages that need to work together. How do I make them work together? I looked at this tutorial btw: http://www.dreaminco...bsite-with-php/

Quote

Are you trying to include page1.html, but want to include page2.html if you click a link to look at a different section?



Yes! I have a hard time explaining things I guess
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10391
  • View blog
  • Posts: 38,455
  • Joined: 27-December 08

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:27 PM

Quote

Are you trying to include page1.html, but want to include page2.html if you click a link to look at a different section?

So:
$link = "<a href=";
if($someCondition){
    $link .= "\"page1.html\"";
}
else{
    $link .= "\"page2.html\"";
}



Then when index.php is finished processing and modifying the HTML output, it can just return the HTML string to the browser (ie., output it).

Also, to clarify, in RudiVisser's tutorial, he is simply including header and footer pages, basically. Remember that HTML is static content, and that it is just a markup language. HTML describes appearance, not functionality.
Was This Post Helpful? 0
  • +
  • -

#9 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:31 PM

Well if I am understanding you correctly now, you are wanting to figure out this part of that tutorial,

include("templates/header.htm");   

if (!empty($_GET['action'])) {  
    $action = $_GET['action'];   
    $action = basename($action);   
    include("templates/$action.htm");   
} else { 
    include("templates/index.htm"); 
} 

include("templates/footer.htm");


What this code does is it tries to load a file with the name that was requested in the $_GET['action'] variable, which is set by the URL, aka http://www.yoursite.com/index.php?action=page1
http://www.yoursite.com/index.php?action=page2

Which would then include the "templates/page1.html" or "templates/page2.html" into the index.php

This post has been edited by VolcomMky: 02 September 2011 - 03:33 PM

Was This Post Helpful? 0
  • +
  • -

#10 dbeaird727  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 238
  • Joined: 13-December 10

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:35 PM

Awesome! But I have a question. Why does it seem that in each folder I need to have page.html and index.php of the same exact code(htmlpage). But when I edit anything at all I only need to edit the index.php file
Was This Post Helpful? 0
  • +
  • -

#11 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:41 PM

You don't need a index.php or page.html in each folder, all you need are the pages you plan on using.

The only reason I could think of you NEEDING a index.php and page.html in each folder is if you were trying to go to that index.php or page.html, for example if you were to go to "yoursite.com/templates" it would look for the default page, normally index.html,index.php, default.html, depending on your servers supported langauge. Like so, "yoursite.com/templates/index.php"

Which is less than likely how you want your visitors to browse your website. :gun_bandana:

If you are trying to update a specific section/page of your website then you would edit your "template/PAGE", if you were going to update your main (index.php) page, then that's all you would need to edit.

This post has been edited by VolcomMky: 02 September 2011 - 03:43 PM

Was This Post Helpful? 0
  • +
  • -

#12 dbeaird727  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 238
  • Joined: 13-December 10

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:43 PM

Perhaps this is because I have empty links(ie. href="#") in my html code.. I suppose the only reason I needed both is to keep the page from crashing when clicking on an empty link. Could I remove any empty links and then just edit the index.php page and leave page.html something like <html><body></body></html>? almost a placeholder.
Was This Post Helpful? 0
  • +
  • -

#13 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:45 PM

Using the "#" in a link is for anchors, it should not leave the current page if clicked unless it has a page then anchor, like "second.php#more"

That would load the second.php and go down to the "more" anchor in your page.
Was This Post Helpful? 0
  • +
  • -

#14 dbeaird727  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 238
  • Joined: 13-December 10

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:52 PM

I was just using that as an example, sorry. So basically I'm asking how to arrange the folders correctly. Where does index.php sit on my server and where does page1.html and page2.html sit. And what would need to go into index.php in order to work with those two pages.
Was This Post Helpful? 0
  • +
  • -

#15 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10391
  • View blog
  • Posts: 38,455
  • Joined: 27-December 08

Re: using index.php with multiple pages?

Posted 02 September 2011 - 03:55 PM

There is a logic to things. Generally, child directories are used to store related files. So think about the logical ordering of things. Also, generally speaking, when a user types in the URL, they expect to be taken to your homepage. The index file should satisfy this expectation.

Look, I don't mean to be rude, but you need to sit down and think things through some.
Was This Post Helpful? 2
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2