• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

How do I launch a PHP from within an Server Side Include HTML program?

The attached file is an html program that is included via a server side include from the index.html page. The SSI gets called via:

<!--#include virtual="view_cart.html" -->
<!--#include virtual="vcitemdetail.php" -->

The html program runs fine EXCEPT I cannot click on the <li> that gets displayed.
How do I launch the PHP from the <li>?




code.txt
0
kbios
Asked:
kbios
  • 8
  • 5
  • 2
  • +1
1 Solution
 
twohawksCommented:
The php include can only execute if the server knows to execute the page type it is being displayed in.
So, for instance,  if were in a php page it would happen naturally, but not so in an htm or html page

So if the page type is not xxxx.php, but is xxxxxx.htm, then you need to tell the server to process ".htm" files for scripts.

There are various methods for doing this... It depends on the type of server you are using, and sometimes the type of php that is being run can come into play (i.e., if it is php executable or php-cgi) depending on some other factors.

If you are running apache, typically it is a matter of adding the necessary lines in a ",htaccess" file for executing the targeted file-type.  You can find out anywhere some of the various methods for telling apache to process a certain file type for scripts.

Before "going there", however, it is good practice to first consider if you really want the server to process all of the relevant file-types for php AND/OR SSI, or just how you plan on managing that.

For instance, in many cases where I have a basic/simple site serving up html pages, and I have a smattering of php and ssi, I will place the php and/or ssi into ".htm" includes.  Then I instruct the server to process htm filetypes for scripts, instead of telling the server to process ALL html files for scripts.

In small sites it is no big deal to pass htm and/or html/etc pages onto the server for processing scripts, but if the site becomes popular/large or is a corporate site that is very busy, then this becomes a concern you should more responsibly manage (i.e., not simpyl having all html pages processed for scripts) as it can become a load on the server you may not want.

So that's the basics, imho.  Let us know what type of server and platform you are using if you need more help figuring out setting up the processing.  The thing is, I could lay a few lines of "what to put into ".htaccess" for this, but actually, different deployments may have slightly unique requirements (you may not even be using apache - I don't know),  so I would rather hear back from you first before presuming to instruct a specific direction to take.

0
 
twohawksCommented:
Something else...
...looking at the code you posted, what I don't get is how the question applies to the fact that there is a link to a php file in an include that you call that renders a div with an anchor into your page.  Form what you mention I would presume that does happen -- the anchor is there with...

href=vcitemdetail.php?showserver=

...rendered in it.

...SO it seems to me this is not an issue of rendering a script inside an anchor tag, but an issue of, when you click the link, is the page being called and...
 - are you running php, so when the link is clicked the php file can be called and processed
 - if the pathway to the file correct (file exists, scripts inside it work, and the server can find it)

Did I miss something?
0
 
twohawksCommented:
Lastly, if its about not being able to click the anchor tag, then you simply need to troubleshoot the resultant html syntax rendered (possibly the code needs a massage), OR where the div is appearing in the flow of the document (perhaps the mere relative placement is shielding it from being accessible from the mouse.

If php generally works on the site, I would check things out closely in the browser developer bar to get a good eye on the resultant rendering context. This may not be a php issue.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kbiosAuthor Commented:
twohawks: thanks for the info. A lot to digest for relative newbie. I need to digest.

I am running apache.

I would like to get more info on your comment.

" For instance, in many cases where I have a basic/simple site serving up html pages, and I have a smattering of php and ssi, I will place the php and/or ssi into ".htm" includes.  Then I instruct the server to process htm filetypes for scripts, instead of telling the server to process ALL html files for scripts. "

I simply want to run the PHP code when the <li> item is selected.
0
 
COBOLdinosaurCommented:
The href is no properly quoted

html += "<li><a href=vcitemdetail.php?showserver=" + localStorage.ShowServer
                 + "&lsctr=" + i + "&item="
		 + localStorage["item" + i]
	         + ">"

Open in new window


needs to be:
html += "<li><a href='vcitemdetail.php?showserver=" + localStorage.ShowServer
                 + "&lsctr=" + i + "&item="
		 + localStorage["item" + i]'
	         + ">"

Open in new window


if I am reading that very messy statement correctly.  You might want to try breaking up long concatenations into 2 or 3 statement to make it a little easier to follow. With all those pieces, it is anybodys guess what you actually want the line to look like.
0
 
kbiosAuthor Commented:
COBOLdinosaur thanks for the tip.

I incorporated your tip and with your suggestion the <li> items no longer appear.
0
 
COBOLdinosaurCommented:
Oh; I probably read the quoting wrong then.  What did it look look like in the page source before it was changed?  Probably what I should have asked first.  Sorry for going to step 2 without doing step 1.

0
 
Dave BaldwinFixer of ProblemsCommented:
If you are using PHP, there is no need for SSI includes.  PHP does 'includes' just fine.  In addition, I believe it is not a good idea to tell your server to run 'htm' files thru the PHP interpreter.  I especially believe these things if you are just starting out.

If you are expecting to work on other people's web sites, you will find that they are virtually Never done like you are trying to do.  Use '*.php' for PHP files and '*.htm' and '*.html' for HTML files and '*.shtml' for SSI files.  Probably 99.9% of the web is done that way.

As for "run the PHP code when the <li> item is selected", that won't happen unless that is a link to a PHP page.  There is an order to these things.  PHP and SSI run their code First on the server and HTML runs after that in the browser.
0
 
kbiosAuthor Commented:
The application will be for a mobile device. So instead of each link pointing to a separate URL I'm using div statements in each of the html programs. The SSI is to include the additional html code from the main index.html program. My code with the PHP works fine when jumping from one URL to another.

In my app I build a list of <li>'s from localStorage.  As you can see from the code above I'm wanting to select the appropriate <li> and pass info onto a PHP and have it return some db info from mysql. Again, this works when the code is going from URL to URL. But I'm missing something in this SSI environment.
0
 
twohawksCommented:
kblos said: "I would like to get more info on your comment.

2said:" For instance, in many cases where I have a basic/simple site serving up html pages, and I have a smattering of php and ssi, I will place the php and/or ssi into ".htm" includes.  Then I instruct the server to process htm filetypes for scripts, instead of telling the server to process ALL html files for scripts. "

I simply want to run the PHP code when the <li> item is selected.

=======================================================
What you "simply want to do" is call a php page from an anchor that is being rendered within a javascript in an html page.  The distinctions are important, and in fact, you are not running any php code in that chunck of code.  Reason I missed it, it was late and I didn't see the link to your clip, and I started by answering your question directly as stated - and it turned out no to be fully relevant (at the outset).

So understanding my statement quoted there  (just this minute) wont necessarily help you solve this (happy to address it later).  More important questions now are...

1) are you setup for running php?  If yes,
2) are you using the proper doctype?  If yes,
3) is the syntax correct, and all the things being called available?  
    ...on that note, I don't know if you should be double-quoting the "item" since I think it is a number - try single quote. Its a guess - I have not yet used localStorage functions)
If yes,
4) did you test in more than one browser? (do not rely on IE alone to legitemise (spelling please) your code.

Some other things I wonder...
 - was the code working before, or in another deployment, and after some other changes it suddenly yielded this problem?
 - where does the code come from... some other coder project, or did you write it, or??

We may need the full context to help you troubleshoot this correctly.
Please address the questions above and post back.
0
 
twohawksCommented:
BTw, if the page can be made accessible on the web then we can be better facilitated to look at this and perhaps help. See if you can you provide a link ;^)
0
 
kbiosAuthor Commented:
The PHP code works fine when 'called' from within a 'regular' html program. I can select the <li> and the proper data is passed to PHP and it executes.

When I changed all of my html programs to no longer contain the tags <html> and <body> and went the SSI approach whereby which I am now referencing div tags in each of the html programs, the call to PHP no longer works. I'm thinking this may require JSON and/or some AJAX. I'm just not sure.

All I know is that click handler for the <li> does not execute the PHP.

Thanks for ALL of your insightful comments. This code is not on the web. Just developing. I'm using Safari 5 as the browser.
0
 
twohawksCommented:
If the code otherwise works, I suspect the relative path to the document in the link, i.e., vcitemdetail.php, needs to be addressed - this is a common problem, i.e., if the include is in a subdirectory different fromt the calling page, you may need to adjust the anchor's file path call to accommodate  the calling that file relative from the include directory (in some cases), or (more often) relative from the calling file.

You should address the relative path issue for the file in the anchor using one html page (pick one). Once you get it fundamentally working from "one" page, i.e., we know that essentially the script can run and its code is executed properly, ...then... if this script is called from other files throughout the site, you will need to do one of two things...
 - adjust the relative path for files at different recursive locations on the site
 - use a script to manage relative path differences globally

No need to freak out on the second part there, we can help you get on track, but it does well to mention that addressing the case for sitewide pages may be a factor.

0
 
kbiosAuthor Commented:
Thanks for all of your help. I appreciate your efforts and time spent helping. Although I didn't completely follow everything you wrote (my fault not yours) you gave me enough to go on. Thanks.
0
 
twohawksCommented:
Glad you got it sorted.

sorry for the confusing post... I realized a little while ago my keyboard isn't all here today (resembling my mind in some respects ;^)

For posterity, since this answer is now closed I would like to address Dave's comment (briefly) that has bearing on something I seemingly proposed...
1) Everything Dave said I am in full agreement with as correct, however, I do not share the opinion that "it is not a good idea to tell your server to run 'htm' files thru the PHP interpreter".  While not standard practice, and even avoided in enterprise deployments, oftentimes a solution may be better accommodated by running other-than-php files through the interpreter, and a lot people do it - some carelessly, and some efficiently.

2) Notwithstanding acceptable standard protocol, and that one 'typically' does not need ssi if one is using php...
...the reason I mentioned a non-standard method I use is that, as Dave alluded to, over the years I have run into so many convoluted pre-existing scenarios that it has been better in many cases to creatively repair what exists rather than re-do it according to what may be considered strict standards (which would have been way more time and work than budget would allow).

...and in your case it seemed obvious the situation already exists.

So rather than criticize the use of ssi and php together, I presumed to leave that go and just look at the issue being inquired over... and since mixing ssi and php was on the table, I deemed it worth proposing a mindfulness to be better managing such a scenario, leaving finer details for later should anyone ask.

Just don't want my peers (and seniors) thinking I am being careless in presuming guidance.  Actually, I have some really interesting mixed ssi and php deployments, and I know other professionals who this has happened to as well.  Its good to know we have options to handle it, and in an acceptably "proper" manner, when the chips are down.

All that said, **if you are starting out**, don't mix ssi and php.  Choose one.
0
 
twohawksCommented:
forgot to say thank you... thanks for the points ;^)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 8
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now