Jump to content

[SOLVED] php help!! newbie here...urgent!


s6arface

Recommended Posts

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!

Link to comment
Share on other sites

"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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
?>

 

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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?

Link to comment
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.