Jump to content
  • Advertisement
Sign in to follow this  
pintee

How to have index.php load different content

This topic is 2057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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??

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites

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.

Edited by slicer4ever

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

Edited by Andy474

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Edited by Michael Tanczos

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!