How to have index.php load different content

Started by
9 comments, last by MichaelNIII 10 years, 11 months ago

Hi everyone,

I would like to have my website display different content while remaining on the same index.php page. The functionality I am after is demonstrated by www.sryth.com. If you sign up for an account, login, and start a new game, you will see what I mean. The address stays the same throughout the game(i.e. www.sryth.com/game/index.php), even as new content is being displayed. How do I achieve this effect??

Advertisement

Look into mod-rewrite.

mod-rewrite allows you to redirect the content into the same php handler, index.php for example, and you pass it the URL.

This is the basis for the MVC model.

Hopefully this link will get you started fast:
http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/

Good luck!

I was just working on this for a simple database for my work. I used the get method and sent a page name to my index page, and then have a switch statement to load each page the user will need to have access to using the include function. If you don't want the ?page= in your url, you can use the post method instead. Hope that helps some.

http://www.w3schools.com/xml/xml_http.asp

you basically make a request to another php page in the background, and it responds with a plain-text response(exactly as if a user had accessed the page with their browser), you can attach post/get data and have the php on that page handle the input, and generate a response. then use javascript to modify the user's page with this new data.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

sorry michael, my php knowledge is rudimentary. I thought get and post methods were only if a form is involved. What if its just a page with links, and when you click on a link it remains as index.php but with different content? Thanks for your time.

The get method doesn't require a new form. It just requires the data be correctly added to the url. I use links that look like www.mysite.com/index.php?page=home. I am also fairly crude with my php aswell though. I wanted this so I could use it to make the nav bar really simple.

i think you can get away with


<?php include "someGenericButtons.html"; ?>

<?php
var $navigationBarToShow = GET['nav']; //Get Navigation from header (So 'TOPLEVEL' or something)
 
if($navigationBarToShow == 'TOPLEVEL')
    include "Navigation/ToplevelNavigation.html";
?>

then, in your navigation bar, your buttons simply point at


<a href="index.php?Nav=Button1">Button 1</a>

or Similar, My web knowledge isn't great, but this is how i did my 2nd Year Uni Web Project.

EDIT: Note this is Semi-psudo code :P

I've been experimenting with www.sryth.com in order to glean how it might be reverse-engineered.

* Firstly I login and start off from www.sryth.com/game/index.php. (this has content on it like text and links)

* Secondly, I open a link on the page in a new window. This brings up the address http://www.sryth.com...ioussectionid=1

for a split second before redirecting to the address http://www.sryth.com...f_c=parser2.inc (this page also has content on it like text and links).

Any guesses as to the implementation from what I have just described?

To add to Andy474... You can do the same with .php files if you want he content to be dynamic from a database. I just add modrewrite to my htaccess file and it is no problem.

So instead of going to www.example.com/index.php?somepage=blah&somethingelse=something

using modrewrite you can handle links to be like,

www.example.com/blah/something to clean it up...

have the index.php file handle the $_GET[somepage] and $_GET[somethingelse]

then as Andy474 stated do include "blah/something.php"

You can of course change that however you like and allow for a lot more parameters if you need to. Hope this helps a little.

eek.. I think what you want to look into is a combination of jQuery and ajax. jQuery has all the capabilities on the browser end you need, including a way to update the history and append hashbangs to urls so users can still use the back button with their browser. Instead of an xmlhttprequest call directly you're better off using a mature library like jquery.

Maybe start with looking at something like this: http://iviewsource.com/codingtutorials/learning-how-to-use-jquery-ajax-with-php-video-tutorial/

An ajax example on our site is when you click "Top Members" and start typing a username.. no page reloads to generate the content on the members page.

This topic is closed to new replies.

Advertisement