Jump to content

How can I easily insert a PHP scrip into an html page?


George

Recommended Posts

Dear Deverill,

Sorry for being more dummy than you can imagine... but i don't understand what do you mean with:

<?php include $_SERVER['DOCUMENT_ROOT']."/inc/PicStrip.html"; ?>

 

what I suppose to do with this?

As a sample, let's suppose my page is cuzcotrips.html and the PHP I want to use come with this indications:

/**

* ----------------------------------------------

* Simple Animated Counter PHP 1.1

* Copyright ©2001 Chi Kien Uong

* URL: http://www.proxy2.de

* ----------------------------------------------

*/

Requirements:

 

- PHP

 

Installation:

 

Set the permissions for all *.php files to mode 755

and give write permissions to the directory:

 

- pages - 777 (drwxrwxrwx) (directory)

 

Usage:

 

<?php

 

include_once "./acounter.php";

$ani_counter = new acounter();

echo $ani_counter->create_output("page");

 

?>

 

page = the page you want to track

 

REally I don't get how to use your sample with this script - can you please give a further help? I don't understand also what is to "set the permissions for all...etc."

and where I must put all the files, gifs, php, jpgs, etc. that comes with the script?

thank you very much for you patience...

George :(

Link to comment
Share on other sites

I've split the "Can I Use This?" topic and moved these posts under "Scripting & Programming -> PHP - Open Discussion", just as Jim noticed they should be.

It's a new subject, so please start a new topic for it, Geroge. :(

 

As for your question, you insert PHP code into an HTML page by using the opening "<?php" tag and the closing "?>" tag. Everything in between those two tags will be treated as PHP.

 

As for the directions of the script you want to install, I don't know the script but I'll try to help you out.

First of all, you probably need to upload all the files into one single directory, keeping the package's sub-directory structure intact (i.e. don't move any files around before uploading).

 

Then you need to change the permissions ("chmod") for the files. You can do this with CPanel's file manager by cilcking on a filename and then by clicking the "Change permissions" on the right hand menu.

For each of the script's PHP file, set it's permissions to 7 5 5 (use the three text boxes on the last line of the permissions' table, the one labeled "Permission", just below "Execute").

Now comes the part that I'm not sure about. It says to "give write permissions to the directory" - which directory? I'm supposing it refers to the script's directory, so, using CPanel's file manager once again, select the folder where you uploaded the script files and change it's permissions to 7 7 7.

 

 

After this, you just have to add a little PHP script to the webpages where you want the counter to appear. For that, you just need to place the following piece of code wherever you want the counter to show up:

><?php
include_once "./acounter.php";
$ani_counter = new acounter();
echo $ani_counter->create_output("page");
?>

 

You just need to make a little adjustment: replace "page" with the HTML file you want to track.

 

You should also make sure that Apache will treat this file (the one you're changing) as a PHP file, or else it will ignore the PHP block. That's as simple as changing the extension of the file to .php or (if you have other pages that link to this one and don't want to fix all the links by hand) add a .htaccess file to the same directory with the following content:

 

AddType application/x-httpd-php .php .html

 

Phew! Long one but hope it helps ;)

Edited by borfast
Link to comment
Share on other sites

Corrections, corrections...

 

I downloaded the script and after looking at the directory structure, I have a correction to make to my instructions above:

You do upload all the files to your account but you only change the permissions of the "pages" directory, the one that you upload along with the other script files, not the one where you store the script files.

 

Let's say you upload everything into "/public_html/acounter/"; you just need to change the permissions of "/public_html/acounter/pages/", not "/public_html/acounter/".

 

Other than that, I think what I wrote on the previous post is pretty much what you need to do. :(

Edited by borfast
Link to comment
Share on other sites

Another correction:

 

You'll need to adjust the

 

include_once "./acounter.php";

 

to reflect the directory where you placed the script.

For example, if you uploaded the counter script into "/public_html/acounter/" and the page you're putting the counter in is "/public_html/index.html", you'll need to change the "include_once" line to this:

 

include_once "acounter/acounter.php";

Link to comment
Share on other sites

Dear borfast,

Thank you for your efforts,

I did what you suggest but when in the last part I try to change the permission to 777 it keep changing just to 717 (I don't know the meaning).

so, I get just to here... and I'm again scrtching my head...

also I don't know how to introduce the line in the html file...

can you make a further effor to help me?

please?

g. :unsure:

Link to comment
Share on other sites

It doesn't let you change the permissions? Strange... :unsure:

Forgive me if it's too obvious but are you writing each number in it's own box? I mean, each 7 should go into one of the text boxes.

 

Also, instead of writing the numbers, try checking the check-boxes. 777 is equivalent to checking all the boxes.

 

As to inserting the PHP code in the HTML file, it's simple. Just insert it whereever you'd insert a number to act as a counter. You just have to copy the PHP code block into the place you want it to appear.

I'm not sure what else I can say. In order to be more specific, I need to see the HTML code of the page where you'll be inserting the counter, so I can specify exactly where in the code you need to put it.

Edited by borfast
Link to comment
Share on other sites

I too have seen the permission change George described. When I use the numbers it sometimes doesn't "get" it all and will change a 775 to a 715. I think it has to do with the numbers because the checkboxes work fine.

 

Borfast did a great job with his explanation... I didn't realize how complex your task was from the original question - sorry to make it seem so over-simplified.

 

My best to all!!!

Link to comment
Share on other sites

Dear borfast and derevill

You are great

and that's for me the meaning of humanity to help each other to accomplish the better we can and the make it better...

Regarding the PHP...

I still can get the Permission to accept the 7 7 7 (each in it's own box).

Regarding to

instead of writing the numbers, try checking the check-boxes. 777 is equivalent to checking all the boxes
I'd check all the boxes but still the check-boxes changes by themselves to the 7 1 5 instead of keeping the 7 7 7. :blink:

I try to put the PHP code with the changes as you logically suggest, but still I see (in the WYSIWYG mode) just black letters with this text, obviously a part of the code"create_output("index.shtml"); ?>"...

<?php

include_once "acounter/acounter.php";

$ani_counter = new acounter();

echo $ani_acounter->create_output("index.shtml");

?>

 

I wish I can send you the index.shtml page so you can see buy yourself.

this site as only one page since it's a site on-work froma group a firends of mine which I'm trying to help: "in the world of the blind the one-eye man (even with glasses...) is a king" but what a poor dummy king am I!!!

 

dear friends if you can help me further I will thank you forever (since any thing we can learn we keep with us forever...).

george :)

Link to comment
Share on other sites

Well, the permissions problem is something rather strange indeed. A CPanel bug? I haven't seen any problem such as that and I can't seem to be able to reproduce it.

 

Let's try a different approach. Are you comfortable with using FTP clients? I hope so :)

Using an FTP cliente (there are several available for free; I recommend SmartFTP), log in to your account.

Navigate to the folder where you uploaded to script to and select the "pages" directory.

This is where it may be a little different if you use another FTP client but generally you'll be able to right-click the folder and a right menu will appear where you will have something like "Permissions" or "Chmod".

Select that option and then change the permissions to 777 (the interface is very similar to the one in CPanel's File Manager).

If that doesn't work, then there's something wrong with your account and I suggest you drop a help desk ticket so someone can take a look at it. But it should work :blink:

 

As for the HTML code, don't worry about what you see in the WYSIWYG editor. What matters is the code. If you inserted the PHP code in a place where you could write text to be displayed on your webpage, you should be fine. :)

Edited by borfast
Link to comment
Share on other sites

Dear borfast (Raul)

I use WS_FTP95LE (i'm a little confident with it).

But the good news is I give it another try this morning and this time the file manager let me change the 'pages' folder chmod to 7 7 7 !!!

Now, I have loaded the page.

You can see it at www.avantixgroup.com. (I have at TCH another 5 sites under my week responsability...)

At this site there is just one page, no more: 'index.shtml'

then, if it's not too much trubble for you (I can understand that you guys are very busy) with the right click you can access to view the source. near the bottom of the source I have inserted the code. I have uploaded the page to the server of course (and also the ./acounter folders) but still in the browser even after reflresh I can see just text and not the PHP counter... Imust be doing something wrong but I can found WHAT.

So, if you are so kind, I still need those little grey-cels in the bright box up your shoulders... :)

thanks again for your kind help,

george :blink:

Link to comment
Share on other sites

Try using this instead

 

echo $ani_counter->create_output("index.shtml");
You have an extra a in $ani_acounter -> Blah Blah Blah

 

Also, you must remeber to open up acounter.php and edit

 

/* URL to the digitset */

        $this->config['img'] = "http://path'>http://path to digits folder/digits/";

 

        /* URL to the animated digitset */

        $this->config['animated_img'] = "http://path to digits_ani folder/digits_ani/";

 

Should work.....

Link to comment
Share on other sites

Dear Dennis,

Thank you for your help.

As for the second part (to made changes in the acounter.php) i did it OK

I extract the extra a

but still doesn't work...

there must be something else that I'm doing wrong...

but I can's find what!!! woooot

If you enter the page www.avantixgroup.com and look at the botton left you will se in black letters what I mean...

 

Then, if you can give a little further help? please? :goof:

george

Link to comment
Share on other sites

Saw the letter echoed out by php on your site.

 

I think the path to the acounter.php might be wrong....thus php is not parsing this script which is why the last part echoed out the black text instead.

 

Which folder did you upload the acounter.php to? As php need to parse the script for it to work ...this line

 

include_once "acounter/acounter.php";
Link to comment
Share on other sites

When you view the source code, you see the php markup tags

 

<?php

 

?>

 

Which means that the server doesn't know to parse your page as php. So you have two choices:

 

1- rename your page with a php extension

 

So if it's index.htm then you change it to index.php and then upload it to the server and remove the old page.

 

2- follow the instructions given by Borfast

 

You should also make sure that Apache will treat this file (the one you're changing) as a PHP file, or else it will ignore the PHP block. That's as simple as changing the extension of the file to .php or (if you have other pages that link to this one and don't want to fix all the links by hand) add a .htaccess file to the same directory with the following content:

 

AddType application/x-httpd-php .php .html

Link to comment
Share on other sites

Oh, yes...Surefire is right......wouldn't be able to read php source code in your html source if you had carried out the part as illustrated by Borfast....

 

But wait if the server didn't know how to interpret php tags....shouldn't the whole text from <?php ...... ?> be printed out instead of just the last part?

Link to comment
Share on other sites

Dear Dennis and Surefire

Thank you I try your suggestion:

 

<?php

include_once "www.avantixgroup.com/acounter/acounter.php";

$ani_counter = new acounter();

echo $ani_counter->create_output("index.shtml");

?>

but still... as you can see in www.avantixgroup.com

I will try now to add the .htaccess file but I see that there is allready a file like this and it's content is:

# -FrontPage-

 

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

 

<Limit GET POST>

order deny,allow

deny from all

allow from all

</Limit>

<Limit PUT DELETE>

order deny,allow

deny from all

</Limit>

AuthName www.avantixgroup.com

AuthUserFile /home/grupo-a/public_html/_vti_pvt/service.pwd

AuthGroupFile /home/grupo-a/public_html/_vti_pvt/service.grp

 

If I add the suggested line:

AddType application/x-httpd-php .php .html

where I have to insert it?

and, this will not make any problems to the working site?

Thank you for your reply and help,

george :goof:

Link to comment
Share on other sites

You can try this

include_once "www.avantixgroup.com/acounter/acounter.php";
To
include_once "./acounter/acounter.php";

 

or

 

include_once "http://www.avantixgroup.com/acounter/acounter.php";

 

For the part bout AddType....not too sure bout that...(maybe you can try it by trial and error) but best to check with the helpdesk....

 

Just looked thru cpanel.....think u can do it at the mime type part........

 

Yes, tried it on my site, just key in application/x-httpd-php in the mime type box and .shtml in the extension box would do........the rest ain't necessary as it is system defined...

Link to comment
Share on other sites

CHANGED POST

I HAVE INSERTED IN THE MIME TYPE AS YOUR SUGGESTION BUT STILL DOESN'T WORK...

CAN YOU SEE THE SOURCE OF MY WWW.AVANTIXGROUP.COM/INDEX.SHTML?

MAYBE YOU CAN ADVISE ME IF I HAD WRITE SOMETHING WRONG... :o

---------------- OLD POST -------------------

Well, thanks,

I will waith maybe somew one here can post some help where to include the suggested line

AddType application/x-httpd-php .php .html

in the .htaccess file...

I hope some one have the answers...

george :goof: Rock Sign :goof:

 

PS: I think the line was suggested by borfast... maybe he can answer where I should insert it?

Link to comment
Share on other sites

You will laugh at me but...

1) I don't know how to post this to the helpdesk.

2) If I must write all what I have being done this morning

and yestarday to explain it... I will be lost... in my own experiences / missunderstanding / complications...

I'm REALLY not more than a D U M M Y... :goof:

george

Link to comment
Share on other sites

Okay... this has gotten a bit out of control.

 

Borfast gave you some very good information... but he is very advanced in his php knowledge and understanding.

 

We need to back up and make this real simple. Once we get you to step one, then you can work your way up to modifying htaccess. It's not hard. But let's do something even easier.

 

Basic rule:

 

For php code to works your file must be named with a php extension.

 

So... rename your index.shtml to index.php

Then... delete index.shtml from your server

Then... upload index.php

 

Go to your site.

 

That should work.

 

Please try this.

Link to comment
Share on other sites

Hi George.

 

Sorry for taking so long to reply, I wasn't home (it's my sister's birthday, so we went out for dinner)

 

About the AddType stuff, you can add it anywhere in the .htaccess file, it doesn't really matter, as long as you don't put it between two already existing tags.

To be safe, just add it to the end of the file.

And don't worry, it won't mess up your website. :goof:

 

Edit

Oops... I didn't notice Jack's reply.

 

Jack is right about the .php extension. Well, half right, anyway :P

 

The usual way is indeed to use .php extensions for PHP scripts. I just suggested that you used the .htaccess method because I was supposing you'd have other pages on your site and if you were to change the extensions from .shtml to .php, you'd have to change all the links on all the pages.

 

If you are willing to do that (or if you don't have that many links after all), do it. It's the best way to go and you won't need to use the .htaccess stuff.

If you don't want to go to the trouble of changing the links, try the .htaccess method.

 

The problem here is that Apache (the web server) knows that files with .php extension should be processed by the PHP engine but treats files with .html (and .shtml) extensions as being plain HTML files with no scripts in them.

So what we want to do by using the .htaccess method is to tell Apache that on the directory where the .htaccess file resides, every file with an .shtml extension should also be treated as containing PHP code.

 

Which reminds me: you're using just .html in the AddType line when you should have .shtml.

Use this instead:

AddType application/x-httpd-php .php .shtml

 

Let us know if this does the trick or if you prefer to change the .shtml extensions into .php :goof:

 

Edit 2

I just visited the URL you posted but instead of a webpage, I got a dialog asking me what I wanted to do with the file I was trying to get. Is anyone else getting this? I saved the file to my computer and after looking at the code I might have a clue on why it's happening: Microsoft stuff everywhere! The code is so full of non-standard stuff that Mozilla and Opera don't know what to do with it ;)

 

Anyway, I looked at the PHP section and it's placed correctly. Now you just need to fix the .htaccess AddType thing and you should be ready to go :o

Edited by borfast
Link to comment
Share on other sites

Borfast is right on...

 

While I was reading this thread, I realized that the file extension didn't match what you had advised him with the Add Type... and just to make thing simple, I suggested the easiest thing possible.

 

I also noticed that the code was very unusual. Which is one of the reasons that I was recommending the easiest method possible.

 

Borfast, I'm gonna duck out of this thread so I don't end up muddying the waters.

Link to comment
Share on other sites

No need to go away, I won't byte :D

Just kidding, of course :D

 

Seriously, two heads are always better than one, so keep your eyes on this thread, Jack.

No matter how much one knows about something, one never knows when he/she will mess things up without realizing.

That's why I always like others to look at my suggestions and correct me where I'm wrong, or suggest different approaches :)

 

Let's see what George decides. One way or the other, the important thing is that he can do what he wants :)

Edited by borfast
Link to comment
Share on other sites

Then you need to change the permissions ("chmod") for the files.

For each of the script's PHP file, set it's permissions to 7 5 5

PHP files are not themselves executable scripts, they merely *contain* bits of executable script.

Thus, PHP files do not need 755 (rwxr-xr-x) permissions; mode 644 (rw-r--r--) will do nicely.

 

CGI scripts *are* executable; they do need execute permissions (e.g. 755).

Link to comment
Share on other sites

Well dear friends,

You are all great! Indeed!

I wish I know so much as you all (each one by itself and all together... wow!!!)

but I'm just a dummy... someone digging into deep waters without a license...

I have developed the site of my wife bussiness (www.turifax.com) also happyly hosted at TCH (the one with the Total Support Service - as I had have the opportunity to feel it)

But, I do try to change the extension to php... but nothing happen it was also worst... then I try to insert the suggested change in the .htaccess file... but still nothing work... I change back the index.php to index shtml with the same results...

So, I don't know what else I can do...

 

Indeed i try each one of the suggestions. But nothing help...

 

Regarding the lines of code that microsoft insert in the code it's because I 'work' with FrontPage and this program develop the codes this way... Idon't know nothing about html language and it's codes... with the time and the expereince I start to understand some of the codes but so few of them... So I don't feel so confident as to know which codes are microsoft rubbish and which not.

 

If some one of you can afford some extra time to imagine further ideas to solve this issue... I certainly will be grateful.

George :D

Link to comment
Share on other sites

George, let's pause for a little and look at the situation. Perhaps we've skiped an important step of the process somewhere along the way.

Could you please describe exactly the steps you performed until now?

Let's see if we can pinpoint the problem... ;)

Link to comment
Share on other sites

Dear Borfast,

Thank you for your dedication,

Sorry I don't replay inmediatedly...

I was helping some people that virus take control of their computers... wow! was a hard work...

Indeed I did each one of the suggestions and try every way.

Maybe there is something else that I do not did...

I will try to especify the steps I did:

First I insert the code"

<?php

 

include_once "./acounter.php";

$ani_counter = new acounter();

echo $ani_counter->create_output("page");

 

?>

In my index.shtml file replacing "page" with index.shtml file I want to track.

in "public_html" I opne a folder named "acounter"; then inside "public_html/acounter" I open 4 folders as indicated in the .txt of the script:

"public_html/acounter/digits"

"public_html/acounter/digits_ani"

"public_html/acounter/doc"

"public_html/acounter/pages"

also, inside the "public_html/acounter" folder I put the files: "acounter.php", "demo.php", and "ip.txt"

 

Then, as you suggest to me, I insert:

AddType application/x-httpd-php .php .html

in the .htaccess.

and also change the chmod to each of the scrips .PHP files to 7 5 5; and change the permissions to the directory to 7 7 7.

Also I adjust the include_once "./acounter.php" to reflect the directory where I placed the script: include_once "acounter/acounter.php";

so the script now look like this:

<?php

include_once "http://www.avantixgroup.com/acounter/acounter.php";

$ani_counter = new acounter();

echo $ani_counter->create_output("index.shtml");

?>

 

still at the web I saw this echoed create_output("index.shtml");

 

By the way: The acounter folder now have the chmod as 7 5 5. Just the ""public_html/acounter/pages" folder have the chmod as 7 7 7. (I don't know if this relevant, but the "public_html/ chmod is set as 7 5 0 and I don't know if this is correct... I can see now that when in the browser I insert the address "http://www.avantixgroup.com" instead of opening the page I get a windows question if I wahnt to save or open a file... something I did must be very wrong!!! oooops

 

So, here I begin to loose contact with reality and understanting... Now when I enter the address of the site I can't see the original index.shtml... So, I have changed the .acacess to it's original and now I can enter the address in the browser and see the original index.shtml page but... still I saw this echoed letters:create_output("index.shtml");

 

 

So, do you have some advise, please?

Thank you,

g. :D

Link to comment
Share on other sites

OK, I think I found the problem that was preventing the script from working in the first place:

instead of

>include_once "http://www.avantixgroup.com/acounter/acounter.php";

put just

>include_once "acounter/acounter.php";

 

As for the permissions of /public_html , you don't need to change those, so keep them as they were (I can see your website now, so you probably have already done that).

 

Then just add the following line to the end of your .htaccess (the one inside your public_html folder):

>AddType application/x-httpd-php .php .shtml

Note that the last one is ".shtml", not just ".html"

 

I tried pointing my browser to http://www.avantixgroup.com/ and the page showed up fine, with the exception of having the "create_output("index.shtml"); ?>" stuff in the bottom but if you add that line to .htaccess, it should work.

 

Don't change anything else, just add the line I mentioned to the file "/public_html/.htaccess" and remember that it's ".shtml", not just ".html" :D

Edited by borfast
Link to comment
Share on other sites

The use of PHP within .shtml files is of acute interest to me, so I've been closely following this thread. (My site currently uses .shtml files across the board without PHP, but I want to be able to include PHP, along with SSI, within my files.) I tried the

>AddType application/x-httpd-php .php .shtml

as noted by others, with the same effect: a request to download a file.

 

Now that I see that others are running into the same issue I had, I did a search on the web and turned up a number of people saying that servers can't parse for both SSI and PHP together; it's one or the other (e.g., http://www.webmasterworld.com/forum88/1015.htm).

 

In other words, it appears that what I want to do is not possible, and that I will have to convert all my files from SSI to PHP so I can get at the other PHP functionality I want to use. :D

Link to comment
Share on other sites

"Assumption is the mother of all mess ups" (the wording is not exactly this, but you get the point :D)

 

I was indeed assuming that this method (the AddType stuff inside .htaccess) would work but now that I've tried it myself I see that it does not work.

I also searched a little about it and it seems that this is a known problem when the .shtml extension is assigned to SSI files within the main Apache configuration file.

 

So I guess the only option left is to rename all the .shtml files to .php :dance:

 

Thanks for the heads up, Singer. It's been stupid of me not trying this sooner. It would have saved us a lot of time and work. :blink:

Edited by borfast
Link to comment
Share on other sites

Dear Borfast,

Thank you Thumbs Up for all your dedication and thank to Singer for add in his help. Thumbs Up

I have still one question...

To change the shtml to php... is it enough to chnage just the .last name (I mean the 3 last letters as index.php instead of index.shtml?

:dance:

George :D

Link to comment
Share on other sites

Ok, Dear Borfast,

Here I'm again (I'm burried with work (and tomorrow is my birthday...).

So I just try what you suggest and the page open with this message at the bottom:

Fatal error: Cannot instantiate non-existent class: acounter in /home/grupo-a/public_html/index.php on line 258
:(

 

Some further ideas?,

Thanks,

George :goof:

Link to comment
Share on other sites

Humm... that's because PHP can't find the acounter code.

Have you dropped the "http://www.avantixgroup.com" from the "include_once" line on the PHP script?

Instead of

>include_once "http://www.avantixgroup.com/acounter/acounter.php";

put just

>include_once "acounter/acounter.php";

or you can also try this:

>include_once "/home/grupo-a/public_html/acounter/acounter.php";

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...