Jump to content

Recommended Posts

Hi

 

Thanks all for replied me, yes that is my code.

<?php

 

$pages_dir = 'pages'; // declare an array which pages and is the folder name were all dynamic page located

if(!empty($_GET['p'])){

$pages = scandir($pages_dir, 0); // this read the content

unset($pages[0], $pages[1]); // this line will delete or removed . and ..

 

$p = $_GET['p'];

 

if(in_array($p.'.php', $pages)){ // seqarch for all page ended with .php and second argument all pages $page

include($pages_dir.'/'.$p.'.php');

}else{

echo '<em style="color:red;"><b>Sorry, page not found in the directory..</b></em>'; // if the page is not exist

}

}else{

include($pages_dir.'/home.php'); // default page

}

?>

Edited by Dilshad34
Link to comment
https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410195
Share on other sites

trq: I don't think he's generating the PHP files on the fly, just trying to use a basic include script.

 

Dilshad: Unfortunately that's not enough code to tell us what the problem might be, for that we need the HTML code in one of the files which you're having problems with. If the problem is the CSS rules, then we need an example of a rule which you're having problems with.

Also, please use the [ic]


[/ic] tags around your code, as it helps make both your post and the code a lot easier to read. Thank you.

That said, the code you did post is a bit overly complicated and does a couple of unnecessary operations. You don't have to scan the folder to retrieve all of the filenames first, just filter the input and then check if the file exists with [ic]is_file ()[/ic].
Like this:
// First determine whether or not a page has been specified.
if (isset ($_GET['p')) {
    // This assumes that all include-able pages has filesnames that consists of
    // lower-case letters only, and is maximum 20 characters long.
    $page = substr (strtolower (preg_replace ('/[^a-zA-Z]/', '', $_GET["p"])), 0, 20);
} else {
    $page = "home";
}

$page = "pages/{$page}.php";

// If the file does not exist, or can't be read.
if (!is_file ($page) || !is_readable ($page)) {
    // Make sure we send the proper HTTP response header too.
    header ("HTTP 1.0 404 Not Found");
    echo '<em style="color:red;"><b>Sorry, page not found in the directory..</b></em>';
} else {
    include $page;
}

Edited by Christian F.
Link to comment
https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410204
Share on other sites

Many thanks for your replies.

Administrators, I am brand new with php and have not enough experiences creat dynamic website, however I try to give some more details to all understand me more.

Make very basic have my index page as small template, what I try to do, display my other dynamic pages in to index page, it will works change the pages with the text only not display the images in the dynamic page....

The index.php is in manin file and the dynamic pages in page file, I attached the index file and one page of dynamic pages which is airport, as an examples.

The index page is to larg and have tried to past here but somehow was to big no enough space therefore I attach my post

index.php

airport.php

Edited by Dilshad34
Link to comment
https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410220
Share on other sites

This one doesn't seem quite correct:

  include "lang/http://wwww.kurdish-guide.org/en";

You need to make sure that the directory tree (paths) are the same as the ones you see int the FTP server. Relative from the location of the index.php file. When using include () the URL of the page is not relevant at all.

 

Though, your problem with the images is what I suspected:

img src="../img/EIA.jpg"

When using include () the path the browser sees is not necessarily the same as the location of the file you're including. But rather, the browser works from the folder of the index.php file. Which means that you have to give all relative URLs inside the included files, as if they were in the same folder as the index.php file.

Short version: Remove the ../ from the URLs.

Edited by Christian F.
Link to comment
https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410226
Share on other sites

Hi Gurus

 

Many thanks that help me a lot, airport.php is in the file called page with 9 dynamic pages.

 

If I put the eia.jpg in same file where dynamic pages it will display the image with text of airport page. I prefer to be saparate from the pages because is not one image, as you know have about 10 pages most of them have different image. What you advise me if I want move the images to different file, sorry my english grammar not very well.

 

Thanks

Edited by Dilshad34
Link to comment
https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410271
Share on other sites

Let's say you have the following directory structure:

/
  - img/
  - pages/
  - index.php

 

index.php includes the files from pages/, which makes the code in those included files act as if they're actually executed inside index.php. So, set the paths to the images to be "./img/" instead of "../", to make the browser look for the folder in the correct location.

 

After all, the URL you use to open a page is "domain.com/index.php", not "domain.com/pages/index.php". So it doesn't make sense, from the browsers viewpoint, to go back one folder to find the img/ folder.

Link to comment
https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410308
Share on other sites

Hi Guru

 

I have tried this way week ago display the location of the image in the browese but the actual image not shown, I can make page screen if you know what I means.

 

<img src="../img/eia.jpg" width="400" height="200" title="Erbil Airport" style="float:right; padding-right:10px;"/>

Edited by Dilshad34
Link to comment
https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410357
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.