ulthane — 2012-02-16T07:49:57-05:00 — #1
Hey guys, whats the best way of creating PHP files using php?
I want to create a new file for each article for example, how to do that?
I want the file to be created using PHP because the content in the file might change later on .
The file is something like that...
Changeable content (taken from a database)
thanks for the help.
logic_earth — 2012-02-16T08:23:22-05:00 — #2
Errr...why do that? Just pull content from the DB depending on the URL the user supplies...
$pageID = $_GET['pageid'];
# get page content from DB.
You only need one file that way.
ulthane — 2012-02-16T08:34:27-05:00 — #3
I had it working that way but i'm using many APIs such as facebook send button which doesnt accept page parameters, eg if u got a page called getarticles.php?ID=5 it will ignore everything after the '?', making it useless...
belsnickle — 2012-02-16T08:49:45-05:00 — #4
You can't do this with Post?
I mean, what you ask certainly is possible, it's just generally probably not a good idea if it can be avoided through any other means.
ulthane — 2012-02-16T08:54:20-05:00 — #5
I know its horrible (facebook's fault) but i dont have any other solution to do that..
get is not a solution because they dont accept page parameters
post is not a solution either because then all articles will be under 1 page that will have the same name always, like articles.php ... (correct me if im wrong?)
belsnickle — 2012-02-16T09:07:52-05:00 — #6
You can still send post parameters to that assuming at any point you're submitting a form, you could always make your form action submit to itself and the form submission be an <a> link.
ulthane — 2012-02-16T09:13:10-05:00 — #7
that will still not make my API work as the send button (for example) accepts a link only, so it will still get articles.php and have no clue to which article to point.
logic_earth — 2012-02-16T09:26:33-05:00 — #8
ulthane — 2012-02-16T09:56:32-05:00 — #9
i read this article: http://www.cyberdesignz.com/blog/website-design/url-rewriting-top-5-ways-of-php-url-rewriting/
But i don't excactly know what apache is, and how to work with it on my hosting..?
ulthane — 2012-02-16T10:31:41-05:00 — #10
dont think that my hosting has apache....not listed on phpinfo() at least...
I think ill have to stick with my suggestion of creating pages, whats the negetivites it has besides of webspace wasting?
and can some1 guide me on the best way to do that ? thanks..
samanime — 2012-02-16T11:30:51-05:00 — #11
You're probably running Apache. If you aren't, you're likely running nginx. If you are running anything else, I recommend changing hosts. =p
Both of those are web servers, which are what make it possible for your pages to be a website. It runs under PHP.
With Apache, you just create a file named .htaccess and put it in the root of your site. With nginx, you have to put it somewhere a little different, but it's still pretty similar.
ulthane — 2012-02-16T11:46:58-05:00 — #12
I'll ask my hosting what i got, i dont see either of these when running phpinfo() function...
ahundiak — 2012-02-16T13:44:29-05:00 — #13
To answer your original question (even though getting the urls to work is probably better), do the same thing you would to generate an html page. Have a template with something like:
// Here is a php function that will end up in my generated php file
$a = "<?php echo $aPassed; ?>";
And then use a basic template processing approach:
// Here I am with my generator
// Want to pass this to the generated file
$aPassed = 'some demo info';
// Pull in the template
$body = ob_end_clean();
// And store it with a php tag
" . $body);
This is also handy for generating caches file of one sort or another.
ulthane — 2012-02-16T15:23:41-05:00 — #14
Well i checked with my hosting and they said they do have url rewritting with a .htaccess file
When i tested something like this:
RewriteRule ^test\\.html$ test.php [L]
But when i'm trying something like the following (taken from an example) it doesn't work..:
RewriteRule ^([0-9]+)$ getpets.php?id=$1 [L]
What i wanna do is something like, changing getpets.php?id=11111 to example.com/pets/11111
Can someone give me the correct code to do such a thing?
samanime — 2012-02-16T19:06:28-05:00 — #15
You want something like:
RewriteRule ^pets/([0-9]+)/?$ getpets.php?id=$1 [L]
ulthane — 2012-02-17T03:50:36-05:00 — #16
thank you so much it works
And thanks everyone for the suggestions & help