Skip to content
View in the app

A better way to browse. Learn more.

Tip.It Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Dynamic PHP inclusion

Featured Replies

Well, I've made a dynamic PHP script which includes html files dynamicly and im wondering how to tweak it a little. The script currently only includes HTML files and im wondering how to edit it so that it will include both. So I want it to look at the parameter in page and search for the HTML, if that is not there, search for PHP, and if PHP is not there display the error page. Any solutions?

 

Thanks in advance for any help

 

 

 

[hide=Click here for code]<?php

 

if (isset($_GET['page']) && $_GET['page'] != "") {

 

$page = $_GET['page'];

 

if (file_exists('pages/'.$page.'.html')) {

 

@include ('pages/'.$page.'.html');

 

} elseif (!file_exists('pages/'.$page.'.html')) {

 

include_once('pages/error.html'); }

 

} else {

 

@include ('index.php?page=news.html');

 

}

 

?>

 

[/hide]


<?php

if(isset($_GET['page']) && $_GET['page'] != "")

{

$page = $_GET['page'];

if(file_exists('pages/'.$page.'.html') || file_exists('pages/'.$page.'.php'))

{

include('pages/'.$page.'.html');

} 

else

{

include('pages/error.html'); 

}

} 

else 

{

include ('index.php?page=news.html');

}

?> 


<?php

if(isset($_GET['page']) && $_GET['page'] != "")

{

$page = $_GET['page'];

if(file_exists('pages/'.$page.'.html') || file_exists('pages/'.$page.'.php'))

{

include('pages/'.$page.'.html');

} 

else

{

include('pages/error.html'); 

}

} 

else 

{

include ('index.php?page=news.html');

}

?> 

 

 

 

If the PHP page exists, won't that script try and include the HTML page that won't exist? If I pass index.php?page=mypage and mypage.php exists, but mypage.html does not, this script will see mypage.php exists and then try to include mypage.html, which doesn't exist, so it needs a little work.

 

 

 

A note if this code is to be placed inside index.php itself :

 

The code is a bit inconsistent (not your fault since the OP makes it look like the code wouldn't be included in index.php but it probably will be), in the first instance you decided the variable "page" would be just the name of the file without extension. Further down in your error compensation code you've set page to "news.html" which would cause an endless loop. You also don't want to be including index.php within itself. We also need to declare the variable $page as equal to our GET.

 

 

 

@ OP, if this code is for your index.php page, then this may work a little better :

 

<?php

if(isset($_GET['page']) && $_GET['page'] != "")

{

$page = $_GET['page'];

if (file_exists('pages/'.$page.'.html')) 

{

	include ('pages/'.$page.'.html');

}

elseif (file_exists('pages/'.$page.'.php')) 

{

	include ('pages/'.$page.'.php');

}

else 

{

	include('pages/error.html');

}

}

else

{

include('pages/news.html');

}

?>

  • Author

Thanks to both of you, solved my problem! :thumbsup:

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.