Jump to content

Basic Include Problem


Smith

Recommended Posts

First of all I must apologise for the pathetic simplicity of my problem, I am not accustomed to using php or html other than for very basic purposes.

 

I wish to use the following in a simple web page:

 

<php include( $page ".txt") >

 

I have tried different minor variations of it but unfortunately I continue to recieve the following message:

 

"Notice: Undefined variable: page in /home/fhlinux172/f/fmpocketguide.co.uk/user/htdocs/index.php on line 97

 

Warning: include(.txt) [function.include]: failed to open stream: No such file or directory in /home/fhlinux172/f/fmpocketguide.co.uk/user/htdocs/index.php on line 97

 

Warning: include() [function.include]: Failed opening '.txt' for inclusion (include_path='.:/usr/share/pear-php5') in /home/fhlinux172/f/fmpocketguide.co.uk/user/htdocs/index.php on line 97"

 

I'm sure there will be a glaring error with the little bit of code or some other simple explanation, sadly I just don't know  :(

 

 

Link to comment
https://forums.phpfreaks.com/topic/44474-basic-include-problem/
Share on other sites

I did use mjlogan's code, but upon attempting to view /index.php?page=test I still only see that home.txt file. I appreciate that this is because $page has now been defined as "home", I just don't know how to alter the code to make it do what I want.

 

I do apologise for my complete lack of understanding here

Link to comment
https://forums.phpfreaks.com/topic/44474-basic-include-problem/#findComment-216042
Share on other sites


<?php 

if (isset($_GET['page'])){
$page = $_GET['page'];
} else {
$page = "index";
}

include("$page.txt"); 

?>

 

or slightly more advanced.

 


if (!isset($_GET['page'])){
$page =  "index";
}elseif (preg_match ("/[^A-z]/", $_GET['page']) || !file_exists("" .$_GET['page']. ".txt")){
$page = "error";						
} else {
$page = $_GET['page'];
}

Link to comment
https://forums.phpfreaks.com/topic/44474-basic-include-problem/#findComment-216053
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.