Dilshad34 Posted February 5, 2013 Share Posted February 5, 2013 Hi everyone I am new with php have one problem with dynamic page. I have create small website with a few dynamic page when I click to the dynamic page it works display all text but not the images anyone have an idea or some tips to discuss with, PLZ. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/ Share on other sites More sharing options...
KevinM1 Posted February 5, 2013 Share Posted February 5, 2013 How do you expect anyone to help without seeing code? Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410133 Share on other sites More sharing options...
Christian F. Posted February 5, 2013 Share Posted February 5, 2013 Do you have a link to the page, or a sample of the code and URL you're using? Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410135 Share on other sites More sharing options...
Dilshad34 Posted February 5, 2013 Author Share Posted February 5, 2013 (edited) 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 February 5, 2013 by Dilshad34 Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410195 Share on other sites More sharing options...
trq Posted February 5, 2013 Share Posted February 5, 2013 Why are you creating php pages on the fly in the first place? It seems you have misinterpreted the definition of a dynamic website. Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410201 Share on other sites More sharing options...
Christian F. Posted February 5, 2013 Share Posted February 5, 2013 (edited) 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 February 5, 2013 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410204 Share on other sites More sharing options...
Dilshad34 Posted February 5, 2013 Author Share Posted February 5, 2013 (edited) 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 February 5, 2013 by Dilshad34 Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410220 Share on other sites More sharing options...
Christian F. Posted February 5, 2013 Share Posted February 5, 2013 (edited) 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 February 5, 2013 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410226 Share on other sites More sharing options...
Dilshad34 Posted February 5, 2013 Author Share Posted February 5, 2013 (edited) 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 February 5, 2013 by Dilshad34 Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410271 Share on other sites More sharing options...
Christian F. Posted February 5, 2013 Share Posted February 5, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410308 Share on other sites More sharing options...
Dilshad34 Posted February 6, 2013 Author Share Posted February 6, 2013 (edited) 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 February 6, 2013 by Dilshad34 Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410357 Share on other sites More sharing options...
Dilshad34 Posted February 6, 2013 Author Share Posted February 6, 2013 Ok It works now many thanks there was two .. remove one . now display the image. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/274034-dynamic-page/#findComment-1410358 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.