LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-27-2004, 01:43 PM   #1
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Rep: Reputation: 30
PHP should ignore a missing page.


Hi, I use this code to load meta names into my template driven website:
PHP Code:
<?php
 $meta_page
="$page.php";
 
$inc_name=array ("$page"=>"meta/$meta_page");
 if (isset(
$inc_name[$page]))
 require_once(
$inc_name[$page]);
?>
All is fine, but if the $meta_page isn't found, the page doesn't load showing errors and warnings. How can I tell the script to load a defaul page, say, index.php if $meta_page is not found? It should be some kind of elseif, but I don't know what. Thanks.
 
Old 01-27-2004, 04:49 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
You could check to see if the file exists with:
http://uk.php.net/manual/en/function.file-exists.php
 
Old 01-28-2004, 02:24 AM   #3
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Original Poster
Rep: Reputation: 30
Thanks, that's what I need, but I am still struggling with implementation.

Basically PHP should check whether the $page has a matching file name in a meta folder.
index.php?page=main will insert a file meta/main.php
If there is a new page, say:
index.php?page=new
script should insert meta/new.php
If there is no such a file, it should insert the defaul file meta/main.php

I am thinking on how to write it, and in a mean time, if anyone has a suggestion I'd be very grateful.
 
Old 01-28-2004, 06:20 AM   #4
aadaileh
LQ Newbie
 
Registered: Jan 2004
Location: Germany
Posts: 9

Rep: Reputation: 0
I am not sure if I got your point correctly !!
Anyway I hope the following code may help you:

<?
$page = "meta/" . $page . ".php";
// Having in mind that the value of 'page' is obtained via GET, POST or maybe set in the script.

if (file_exists($page)) {
require_once($page);
} else {
require_once("meta/main.php");
}
?>
 
Old 01-29-2004, 09:53 AM   #5
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Original Poster
Rep: Reputation: 30
You got the point right! In this case this is even better:
PHP Code:
<?
$metapage 
"meta/" $page ".php";
if (
file_exists($metapage)) {
require_once(
$metapage);
} else {
require_once(
"meta/main.php");
}
?>
MANY THANKS! This script inserts engine optimized meta data, and if I don't have time to write new meta data file it inserts default file, which is a lot better than nothing.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
php page will not load kaplan71 Linux - Software 6 09-11-2004 07:37 AM
Reloading page with php emilioestevezz Programming 1 09-07-2004 04:40 PM
Setting a web page with php! mithras Linux - General 14 07-25-2003 03:25 PM
PHP server page detect radnix Programming 4 06-29-2003 02:27 PM
save and run php page !!! hitesh_linux Linux - General 2 04-16-2003 03:32 PM


All times are GMT -5. The time now is 09:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration