s6arface Posted June 27, 2007 Share Posted June 27, 2007 hey guys, im trying to get a php script running so i can make updating my template easier. i have used the script below on other servers and i havnt had any problems until now on this server. this is urgent, and i would apprecaite it if you guys can help me out the website is... http://daralnoor.org/saad/main.php?id=news i get the error... Warning: include(.shtml) [function.include.html]: failed to open stream: No such file or directory in D:\Websites\bhwww\daralnoor\daralnoor.org\www\saad\main.php on line 165 Warning: include() [function.include.html]: Failed opening '.shtml' for inclusion (include_path='.;c:\php\includes') in D:\Websites\bhwww\daralnoor\daralnoor.org\www\saad\main.php on line 165 i am using the code: <?php include ("$id.shtml"); ?> thanks in advance!!! i tried searching via google, but i am a complete n00b with php! Quote Link to comment Share on other sites More sharing options...
solarisuser Posted June 27, 2007 Share Posted June 27, 2007 No such file or directory in D:\Websites\bhwww\daralnoor\daralnoor.org\www\saad\main.php Make sure $id is pointing to the correct path of the file you are trying to include Quote Link to comment Share on other sites More sharing options...
soycharliente Posted June 27, 2007 Share Posted June 27, 2007 Where are you creating $id? Are you doing $id = $_GET["id'] ? Quote Link to comment Share on other sites More sharing options...
s6arface Posted June 27, 2007 Author Share Posted June 27, 2007 "Make sure $id is pointing to the correct path of the file you are trying to include" how would i do this? (probably a newbie comment, but yes i am) and i use this script so i can have a template and have rest of my pages go on the template and makes updating pages a hella lot easier Quote Link to comment Share on other sites More sharing options...
s6arface Posted June 27, 2007 Author Share Posted June 27, 2007 Where are you creating $id? Are you doing $id = $_GET["id'] ? no im not, the script im using is the one i have listed in the first post Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 27, 2007 Share Posted June 27, 2007 i think we all need to go back to the basics here. If you get the id from the database/whatever and use it in a link you need to use $_GET['id'] to retreve the id from the link ok. Now if you using the id on a page that is set to varable id then you can use normall $id. If you using a include on other pages then your include will need the $id=$_GET['id'] for that include to work. Quote Link to comment Share on other sites More sharing options...
s6arface Posted June 27, 2007 Author Share Posted June 27, 2007 i think we all need to go back to the basics here. If you get the id from the database/whatever and use it in a link you need to use $_GET['id'] to retreve the id from the link ok. Now if you using the id on a page that is set to varable id then you can use normall $id. If you using a include on other pages then your include will need the $id=$_GET['id'] for that include to work. i know i def need to go back to the basics, and learn them hahaha. this is how i was planning on setting it up. i will have how every many pages with just content in them (for example....news.html, info.html, contact.html, about.html) and in that same directory i will have the main.php (which will have the template and the code i have listed in the first post) and im tryin to get this code to pull out the content pages whenever called upon such as http://blah.com/main.php?id=news http://blah.com/main.php?id=about http://blah.com/main.php?id=contact etc... would this fall under your first or 2nd catergory of usin the code? and also, when you say put in "id" so i have to include ".shtml" at the end like i have it now? Quote Link to comment Share on other sites More sharing options...
soycharliente Posted June 28, 2007 Share Posted June 28, 2007 You can't just say include("$id.shtml"); You have to define what $id is. As of now, you haven't convinced me that you've done that in your code. You can't just define a variable with the same name as something in the URL and want it to pull it out for you. Quote Link to comment Share on other sites More sharing options...
per1os Posted June 28, 2007 Share Posted June 28, 2007 It generally isn't a good idea to include files using get data. I would either make a real id which will go into an array and pull out the file to include or store it in a DB. You want a good reason why? Well I am glad you asked http://www.yourunsecuresite.com/main.php?id=http://www.mysite.com/myfile.txt Now all i have to do is create the myfile.txt on my server with some fopen code and I can return all your pages on the server and write new code inside your server pages which would redirect users to my site. Not a very good idea to do just "blindly" Quote Link to comment Share on other sites More sharing options...
s6arface Posted June 28, 2007 Author Share Posted June 28, 2007 You can't just say include("$id.shtml"); You have to define what $id is. As of now, you haven't convinced me that you've done that in your code. You can't just define a variable with the same name as something in the URL and want it to pull it out for you. well, it always worked on the other servers ive been on for some reason? what format would i have to use to define all the $id's? Quote Link to comment Share on other sites More sharing options...
per1os Posted June 28, 2007 Share Posted June 28, 2007 The other servers had register_globals on which is a huge security flaw. $id = $_GET['id']; Just remember what I stated above you are opening yourself up if you do not add in some checks etc. Quote Link to comment Share on other sites More sharing options...
soycharliente Posted June 28, 2007 Share Posted June 28, 2007 I did that and just wrote a script to check the directory to see if a file with that name existed and if it didn't returned a 404 error message. So you could do that, but IMHO frost's explanation of you should put the filenames in a DB and grab ids is probably MUCH, MUCH easier. It will save you a ton of time, handle error checking (for the most part) for you, and be safer. Quote Link to comment Share on other sites More sharing options...
s6arface Posted June 28, 2007 Author Share Posted June 28, 2007 I did that and just wrote a script to check the directory to see if a file with that name existed and if it didn't returned a 404 error message. So you could do that, but IMHO frost's explanation of you should put the filenames in a DB and grab ids is probably MUCH, MUCH easier. It will save you a ton of time, handle error checking (for the most part) for you, and be safer. I under where Frost is coming from now, but how would I set up a DB? =x I'm looking for a quick way to update my template without having to go through all the pages and update the links. Quote Link to comment Share on other sites More sharing options...
per1os Posted June 28, 2007 Share Posted June 28, 2007 You don't necessarily need a "DB" persay, for a quick fix store them in an array like so: <?php $filearr = array("news" => "news.html", "index" => "index.html"); $filearr2 = array(1 => "news.html", 2 => "index.html"); ?> Something like that would suffice than to call the page you would do this: <?php $filearr = array("news" => "news.html", "index" => "index.html"); $filearr2 = array(1 => "news.html", 2 => "index.html"); $page = in_array($_GET['id'], $filearr):$filearr[$_GET['id']]?"unknown.html"; include($page); ?> Quote Link to comment Share on other sites More sharing options...
soycharliente Posted June 28, 2007 Share Posted June 28, 2007 <?php $page = in_array($_GET['id'], $filearr):$filearr[$_GET['id']]?"unknown.html"; ?> Did you reverse your ? and : Shouldn't it be the other way around? Quote Link to comment Share on other sites More sharing options...
s6arface Posted June 28, 2007 Author Share Posted June 28, 2007 Frost, thanks for your help. I have a few questions ...so I contacted you via AIM, is that okay? More specificially, im kind of confused on where to put those codes, and how I would go about if I wanted to add more pages.. Im pretty sure I can figure it out, but right im trying to get 2 pages to work with each other (main.php [the template] and news.html [being the content]) thanks again for everyones help so far Quote Link to comment Share on other sites More sharing options...
s6arface Posted June 29, 2007 Author Share Posted June 29, 2007 bump. can anyone help me with where im suppose to put the codes that frost has provided, and what values i would change/add if i wanted to add more content/pages to the template thanks Quote Link to comment Share on other sites More sharing options...
s6arface Posted June 30, 2007 Author Share Posted June 30, 2007 bump yet again. sorry for all the bumps, but this is urgent and i am on a time basis. i have to construct a website for a non profit organization and my only set back is tryin to figure this template system out. anyone willing to help me out or explain frosts post in a little more detail? Quote Link to comment Share on other sites More sharing options...
s6arface Posted July 2, 2007 Author Share Posted July 2, 2007 bump once again. any help would be appreciated!! Quote Link to comment Share on other sites More sharing options...
soycharliente Posted July 2, 2007 Share Posted July 2, 2007 What exactly do you need help with? Quote Link to comment Share on other sites More sharing options...
s6arface Posted July 4, 2007 Author Share Posted July 4, 2007 Frost has provided some codes on the first page, but im not sure how to approach this, and what files to put it in in etc. id greatly appreciate it!!!! Quote Link to comment Share on other sites More sharing options...
soycharliente Posted July 4, 2007 Share Posted July 4, 2007 If you try and put some of the code together and post your problems I'd be glad to take a look. Quote Link to comment Share on other sites More sharing options...
s6arface Posted July 6, 2007 Author Share Posted July 6, 2007 this issue is finally solved! thanks to charlie! kudos to him! Quote Link to comment 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.