2

So i made a site that allows users to create their own site, with stuff like wysiswyg editors etc. When they register they get an url like user.site.com and they can create files, folders, upload files etc, they can create and edit html files, example if someone created index.html = user.site.com/index.html they can edit that with my site tools, and access it through user.site.com/index.html, i just want to know if i can append a php code to all the html files they create without actually adding content to the file. Like

echo 'Created with AppName';

would automatically be added to all the html files that every user created without actually being inside it, can htaccess do this?

  • rewrite the URLs to automatically go through a script of your choosing. – Amelia May 06 '13 at 22:31
  • no it has to run with the html files, so i can dynamically manage content etc with javascript, php etc – user2356325 May 06 '13 at 22:34
  • then fetch the files based on the URL... – Amelia May 06 '13 at 22:36
  • 3
    Considering you have three answers answering three different questions, you may want to take some time to think about what you are trying to accomplish and rephrase this question with a bit more care. – Cypher May 06 '13 at 22:44
  • possible duplicate of [Parse HTML as PHP](http://stackoverflow.com/questions/7181853/parse-html-as-php) – Ejaz May 07 '13 at 01:11

4 Answers4

1

Just that all the pages that users send are rotated based on another php file.

Assuming the user (assuming the User's name is john) sent the file foo.html

to access the file foo.php need to go to a URL like this:

john.site.com/partners.php?path=foo.html [fixed]

With .htaccess (mod rewrite), you can modify this URL making it look like this:

john.site.com/foo.html

just the subdomain has access to php file partners.php (which should be the root)

mod_rewrite/.htaccess: http://www.sitepoint.com/guide-url-rewriting/


[edited]

Example:

.htaccess:

RewriteEngine On
RewriteRule ^/([A-Za-z0-9\/\-_. ]+)$ /partners.php?path=$1

PHP code:

include('youscript.php');

//Get username
$tmp = $_SERVER['HTTP_HOST'];
$tmp = explode('.',$Q);
$username = $test[0];

//Print file in page
if(isset('users/'.$username.'/'.$_GET['path'])){
  echo file_get_contents('users/'.$username.'/'.$_GET['path']);
}

Results:

paul.site.com/partners.php?path=mypage.html

to

paul.site.com/mypage.html


john.site.com/partners.php?path=folder1/mypage.html

to

john.site.com/folder1/mypage.html


william.site.com/partners.php?path=css/style.css

to

paul.site.com/css/style.css

silverfox
  • 130
  • 7
1

I think what you're asking is that you want to have your web server process .htm or .html files for php code. Is that correct? If so, you'll probably want to do something like this in your .htaccess file:

AddHandler x-httpd-php .html .htm 

Simply put, this will tell Apache to process .html and .htm files for php code (if any).

http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addhandler

Cypher
  • 2,608
  • 5
  • 27
  • 41
  • The app will allow users to create their own html, js files etc... i just want to know if i can somehow append a php code to all the files that was created – user2356325 May 06 '13 at 22:42
  • This will add the php code at "runtime", and won't actually edit the user's file. – alfadog67 Jul 20 '15 at 21:36
1

If you have access to edit your php.ini, you can use auto_prepend_file. This is not accessible from .htaccess, but otherwise achieves what you are trying to do:

http://www.php.net/manual/en/ini.core.php#ini.auto-prepend-file

From the manual:

Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the require function, so include_path is used.

The special value none disables auto-prepending.

This will allow you to run a specified PHP file before each request.

Note if you're wanting to run this on HTML files, not just PHP, you will also need to set a handler to run those files through PHP, as mentioned above:

AddType application/x-httpd-php .html
Community
  • 1
  • 1
Alex Osborn
  • 9,831
  • 3
  • 33
  • 44
  • If this answer isn't exactly right for you, try this variant **.htaccess:** `AddHandler application/x-httpd-php54 .html .htm` **php.ini** `auto_append_file = '/home/[MY USER'S USERERNAME]/public_html/sub_footer.php'` – TecBrat Sep 24 '14 at 19:04
0

You mean like using a include command?

Try this:

<?php
include 'yourphpscript.php';
?>

More info here:

http://php.net/manual/en/function.include.php

totallyuneekname
  • 2,000
  • 4
  • 16
  • 27
  • Yes i mean like that but without actually adding the include("script.php"); to the files they create, they can create html files – user2356325 May 06 '13 at 22:36
  • I haven't heard of such a thing. Usually people include things at the beginning (or end) of their scripts anyway, so it isn't that hard to add in the include. I haven't ever heard of anyone using .htaccess to do that, but that doesn't mean it isn't possible. – totallyuneekname May 06 '13 at 22:42
  • The app will allow users to create their own html, js files etc... i just want to know if i can somehow append a php code to all the files that was created... so it will be user.site.com/filecreatedbyuser.html, i hope you all understand what i mean :) – user2356325 May 06 '13 at 22:43