Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Tying php with html, shtml, javascript, etc

    As someone completely new to php (and trying to learn by slowly adding little things, and verifying that they work before moving on), the first question at least to my mind is how php can be made to work with html, javascript, and so on. No book or tutorial I have found quite does this. They all seem to tacitly assume you want to run php and MySQL, and nothing else.
    If you're *not* using php, you start at the "top" with indix.html, or in my case, index.shtm to be able to use my hosting company's provided hit counter.
    I've discovered I can rename this file to index.php, and everything then works, but not the hit counter. As I understand it, the index file must have a .php extension (Haven't tried php3--- my guess is that's obsolete), else the server won't have a clue that there are any php function calls in it (in this case, at this point, simply posting the date and time according to the webserver).
    Perhaps the answer is to "call" a separate .shtml file with the hit counter code? If so, how do I do "call" such a function in php? Some sort of an "include" statement, maybe?
    If someone can simply point me somewhere to get a tutorial on this, I would be very grateful. The trouble I'm having, though is that this isn't a "purely" php question. Am I at least correct in my assumption that an index.php file needs to be at the root node of everything?

  • #2
    New Coder
    Join Date
    Dec 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP language works tightly with HTML and Javascript.
    HTML and Javascript are, mainly, user-side languages, where PHP would be server-side (read: all scripts are processed on the server real-time).
    A 'shtml' file is normally a Server side include (SSI) and is an old way to implement server-side scripting into the pages, including counters.
    If you want a php counter to work, you can research hotscripts.com for a variaty of available php counters that work either with plain text files or with database.

  • #3
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks for your reply

    I knew that php was implemented on the server side and Javascript and html on the Client side in the browser, but I didn't know what you told me about SSI. So I thank you for that.
    What I would prefer to do at this point (if only so I can learn how to do it) is to still incorporate older style SSI counter. This is what I losely referred to as a "function call." To put it another way, can php work with SSI? It seems as though the SSI interpreter (or whatever you'd call it) never gets invoked because of the .php extension on the root index file. I'm guessing that having the code for the SSI counter in a separate file with a .shtml extension will do it, though I'm not at all sure of this. Nor do I know quite how to write the call.
    I any case, seems to me that it would be great if someone who knew how to tie all of this (javascript, php, SSI) together had a brief tutorial, or even just a few sample files that said "hello from php," "hello from SSL," "hello from Javascript," etc. I could then build upon that.

  • #4
    New Coder
    Join Date
    Dec 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Main reason it won't work is that server configuration is tighted with file extension. You could try using <IFRAME> within the HTML to point it to SSI file.

  • #5
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    Here's the basic breakdown:

    HTML is a mark-up language. You surround plain text with tags to denote what sort of text you're dealing with. Example: <p>This is a paragraph.</p>

    Javascript is a client-side scripting language. It's a programming language that runs in real time, and is processed by your browser.

    PHP is a hypertext pre-processor and a server-side scripting language. In its simplest terms, this means PHP code is run on the server, and the results are spit out as HTML. So if you have a really simple .php page:

    PHP Code:
    <html>
    <body>

    <?php echo "<p>Hello world!</p>"?>

    </body>
    </html>
    What the browser sees (the result of the PHP code) is this:

    Code:
    <html>
    <body>
    
    <p>Hello world!</p>
    
    </body>
    </html>
    SSI (server-side include) is just a way for the server to insert text into your html. The PHP version is the include function:

    PHP Code:
    <?php include("somefile.php"); ?>
    As far as the counter goes, you have to see what is powering the thing (is it a CGI script? A Javascript? ASP? PHP?) first.

  • #6
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FileName.ssi?

    The actual code for the counter is:

    <!-- #exec cgi="/cgi-bin/text_counter.pl" --><br>

    So long as the file is named index.shtml, the counter works. If I change the file name to index.php (changing nothing in the file) it doesn't work. So, to make it work (with the .php file extension) do I need to have that counter in a separate .shtml file, that gets "included" in index.php somehow?
    I know this is very basic, but I'm having trouble finding anyone who can explain this to me. When I ask, people seem to just tell me all the stuff I already know (javascript runs in the client side, php runs on the server side, etc., etc.) but not how to make all of this work together (i.e., how to invoke both the php and the ssi preprocessors).





    Quote Originally Posted by Prikid
    Main reason it won't work is that server configuration is tighted with file extension. You could try using <IFRAME> within the HTML to point it to SSI file.

  • #7
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The line for the counter is

    <!-- #exec cgi="/cgi-bin/text_counter.pl" --><br>

    So long as the file is named index.shtml, the counter works. But I want to start adding some php stuff, so I need to name the file index.php. Is it possible for me to utilize both php and ssi?

  • #8
    New Coder
    Join Date
    Dec 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, you need to include the counter page (with valid shtml extension) into the php page sepparately.
    Code:
    <html>
    <body>
    <?php include ("counter.shtml"); ?>
    </body>
    </html>

  • #9
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or, just use a PHP counter and be spared the hassle of including a page with an SSI include to a perl script. Doing so would cut out one-two steps to the entire process, depending on how you went about it.
    "$question = ( to() ) ? be() : ~be();"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •