Skip to main content
GameDev.net gamedev.net
🔒 Locked

How to have index.php load different content

Started by pintee Apr 30, 2013 at 10:09 PM 9 replies 6.4k views
Original Post
pintee
pintee

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

MichaelNIII
MichaelNIII
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.
slicer4ever
slicer4ever

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.

pintee
pintee

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.

MichaelNIII
MichaelNIII
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.
Andy474
Andy474

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


Button 1

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

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

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.

Michael Tanczos
Michael Tanczos

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.

MichaelNIII
MichaelNIII

Indeed, sorry I couldnt give decent example code, I was on a phone. Andy's method is what I was refering to.

My index page loading looks like

if ($Page == 'home') {include('MainPage.html');}
else if($Page == 'login') {include('LoginPage.html');}
else if($Page == 'loginsuccess'){include('LoginSuccess.php');}
else if($Page == 'logout') {include('Logout.php');}
else {include('MainPage.html');}

for displaying the different pages, and

  • Login
  • for the different navagation bars. This is a really poor example and could be inproved on a lot, but Eh maybe you will find it more userful then just saying steps, my syntax is ugly as hell but I tend not to worry about my syntax rules until my 2nd or 3rd rewrite for sometime when its less "lets try and get this to work right" and more "lets try and make this modifyable, work right, and easy to read"

    
    <?php
    session_start();
    
    echo "
    <ul> <li>Home</li>"; if($_SESSION['myusername']==''){echo "<li>Signup</li> <li>Login</li>";} else{echo "<li>Logout</li>";} echo" </ul>
    "; echo $_SESSION['myusername']; echo "
    "; $Page = $_GET['Page']; if ($Page == 'home') {include('MainPage.html');} else if($Page == 'login') {include('LoginPage.html');} else if($Page == 'loginsuccess'){include('LoginSuccess.php');} else if($Page == 'logout') {include('Logout.php');} else {include('MainPage.html');} echo"
    "; ?>

    Topic Locked

    This topic has been locked by a moderator. New replies are not allowed.

    Sign in to reply to this topic.