0

I created index.php that basically looks up all the individual php files (articles) in a few subfolders and prints them out. Since the quantity of articles is over 30 and growing, I implemented a multi-page solution using PHP session(). So, page2.php simply prints out the second part of my array titled "page2" and page3.php prints out the third part of my array titled "page3". These array parts are arrays themselves (it's an array of arrays).

All works fine.

However, this requires me to hard code "page2.php", "page3.php", etc. This will get out of hand at some point.

How would you guys handle this? Can I dynamically create "pageX.php" upon user clicking the "Next" button? Or, should I do some type of AJAX solution? Is there a standard way of doing a multipage PHP index?

asked May 14, 2015 at 23:14

1 Answer 1

0

It is much more common to use url parameters. For example:

example.com/index.php?page=1
example.com/index.php?page=2

Then on index.php you can use $_GET['page'] to figure out which page you are retrieving, then serve that data. If you are actually generating php files on your server you can serve that page using:

include 'page2.php';

Or even better:

include 'page'.$_GET['page'].'.php';

Disclaimer: You should sanitize your variable before using it: such as:

$page = sanitize($_GET['page']); //You need to write the sanitize function
include "page$page.php";
answered May 14, 2015 at 23:45
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.