Php Script displaying source on browser instead of executing it

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Php Script displaying source on browser instead of executing it

    i was just testing a script i made, but it didn't display design or any html..

    Instead, it showed all my codes in highlighted format. Meanwhile, some scripts work perfectly alright, but few still gives me problem..

    Any help?

    #2
    without seeing the script and also not knowing exactly what the problem is - there is no way of helping apart from guessing

    Comment


      #3
      Browser show source code if your php is not properly formated
      BAD WAY TO FORMAT PHP,SOME SERVERS DO NOT RECOGNIZE FORMATING AND OUTPUTS SOURCE CODE
      PHP Code:
      <? 
      print "Bad formating";
      ?>
      Corect way to do it
      PHP Code:
      <?php
      print "Corect formating";
      ?>

      Comment


        #4
        Originally posted by chelios View Post
        Browser show source code if your php is not properly formated
        BAD WAY TO FORMAT PHP,SOME SERVERS DO NOT RECOGNIZE FORMATING AND OUTPUTS SOURCE CODE
        PHP Code:
        <? 
        print "Bad formating";
        ?>
        Corect way to do it
        PHP Code:
        <?php
        print "Corect formating";
        ?>
        This is most probably your problem, you have to setup a server to accept shorthand code, if not it will be commented/printed to screen. General rule of thumb is to always start php code with <?php and NOT <?

        Comment


          #5
          Thanks your your replies.. But, i've done evrytin needed to be done.. Pls see http://nxsite.t15.org/forum
          Last edited by wapdxoo; 12.06.13, 07:38.

          Comment


            #6
            Please copy your whole source here so that we can inspect

            Viewing the sourcecode from browser I see there is a tag after body "<code>", not sure why that was done but remove it, if that doesn't solve your issue please upload the php so that we can properly check
            Last edited by phoenix90; 12.06.13, 09:22.

            Comment


              #7
              Originally posted by wapdxoo View Post
              i was just testing a script i made, but it didn't display design or any html..

              Instead, it showed all my codes in highlighted format. Meanwhile, some scripts work perfectly alright, but few still gives me problem..

              Any help?
              show us ur script or check your script again

              Comment


                #8
                Originally posted by wapdxoo View Post
                Thanks your your replies.. But, i've done evrytin needed to be done.. Pls see http://nxsite.t15.org/forum
                Check this php files for errors ..
                PHP Code:
                require("../inc/engine.php"); 
                Reason why to check engine.php is that if there is no errrors ,
                but error is in
                PHP Code:
                  // Main 
                main(); 
                anything should be in order until main() function is called

                Comment


                  #9
                  Originally posted by wapdxoo View Post
                  Thanks your your replies.. But, i've done evrytin needed to be done.. Pls see http://nxsite.t15.org/forum
                  Its an result of using PHP: highlight_string - Manual by looking in the source.
                  <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

                  Comment


                    #10
                    Originally posted by chelios View Post
                    Browser show source code if your php is not properly formated
                    BAD WAY TO FORMAT PHP,SOME SERVERS DO NOT RECOGNIZE FORMATING AND OUTPUTS SOURCE CODE
                    PHP Code:
                    <? 
                    print "Bad formating";
                    ?>
                    Corect way to do it
                    PHP Code:
                    <?php
                    print "Corect formating";
                    ?>
                    Originally posted by phoenix90 View Post
                    This is most probably your problem, you have to setup a server to accept shorthand code, if not it will be commented/printed to screen. General rule of thumb is to always start php code with <?php and NOT <?
                    I wonder how you two PRO's manage to run your sites...
                    FYI, both ''formating'' are perfectly correct !
                    It is just a matter of server setting
                    php.ini => short_open_tag = on !
                    then there is absolutely NO difference between <? and <?php
                    Originally posted by wapdxoo View Post
                    Thanks your your replies.. But, i've done evrytin needed to be done.. Pls see http://nxsite.t15.org/forum
                    your way to solution is in arnage's reply...
                    most likely you are looking for code like this(or similar):
                    PHP Code:
                    <?php 
                    function string_syntax_xhtml$string$return false ) {
                        
                    $highlight highlight_string$stringtrue );
                        
                    $replace   str_replace(
                            array( 
                    '<font color="''</font>' ),
                            array( 
                    '<span style="color: ''</span>' ),
                            
                    $highlight 
                        
                    );
                        if( 
                    $return ) {
                            return 
                    $replace;
                        }
                        echo 
                    $replace;
                        return 
                    true;
                    }
                    function 
                    file_syntax_xhtml$path$return false ) {
                        return 
                    string_syntax_xhtmlfile_get_contents$path ), $return );
                    }
                    echo 
                    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head><title></title></head><body>';
                    string_syntax_xhtmlfile_get_contents'index.php' ) );
                    echo 
                    '</body></html>';
                    ?>
                    It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt.
                    ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ !
                    ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.
                    キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

                    Comment


                      #11
                      @metulj.

                      No difference? Your kidding right? So if one needs additional setup to work correctly (which I did mention in my post if you read it) the how are they not different? Seriously

                      Oh and btw. < ? Is used for xml and thats why short_open_tag is disabled by default.

                      So please PRO tel us 2 noobs how they are still exactly the same.
                      Last edited by phoenix90; 13.06.13, 16:15.

                      Comment


                        #12
                        dont know which system you have used, but for me short open tags were always enabled by default,
                        if you put xml in php file you can do it like this
                        PHP Code:
                        <? echo '<?xml version="1.0" ?>'; ?>
                        Advertise your mobile site for FREE with AdTwirl

                        Comment


                          #13
                          Originally posted by GumSlone View Post
                          dont know which system you have used, but for me short open tags were always enabled by default,
                          if you put xml in php file you can do it like this
                          PHP Code:
                          <? echo '<?xml version="1.0" ?>'; ?>
                          I honestly have always have that disabled from our local servers to hostgator.

                          But apparently those shortags will be deprecated in the next major release of php, but instead they suggest <?= ?> for the people that prefer shortags, as per the PSR-1 coding standards

                          Comment


                            #14
                            Originally posted by phoenix90 View Post
                            @metulj.
                            No difference? Your kidding right? So if one needs additional setup to work correctly (which I did mention in my post if you read it) the how are they not different? Seriously
                            Oh and btw. < ? Is used for xml and thats why short_open_tag is disabled by default.
                            So please PRO tel us 2 noobs how they are still exactly the same.
                            like i said...
                            PHP Code:
                            <? ...
                            is equal to
                            PHP Code:
                            <?php ...
                            and also
                            PHP Code:
                            <?= ...
                            is equal to
                            PHP Code:
                            <? echo ...

                            The problem with this whole discussion lies in the use of PHP as a templating language. No one is arguing that tags should be used in application source files.

                            However PHP's embeddable syntax allows it to be used as a powerful template language, and templates should be as simple and readable as possible. Many have found it easier to use a much slower, add-on templating engine like Smarty, but for those purists among us who demand fast rendering and a pure code base, PHP is the only way to write templates.

                            The ONLY valid argument AGAINST the use of short tags is that they aren't supported on all servers. Comments about conflicts with XML documents are ludicrous, because you probably shouldn't be mixing PHP and XML anyway; and if you are, you should be using PHP to output strings of text. Security should never be an issue, because if you're putting sensitive information like database access credentials inside of template files, well then, you've got bigger issues!

                            Now then, as to the issue of server support, admittedly one has to be aware of their target platform. If shared hosting is a likely target, then short tags should be avoided. But for many professional developers (such as myself), the client acknowledges (and indeed, depends on the fact) that we will be dictating the server requirements. Often I'm responsible for setting up the server myself.

                            And we NEVER work with a hosting provider that does not give us absolute control of the server configuration -- in such a case we could count on running to much more trouble than just losing short tag support. It just doesn't happen.

                            So yes -- I agree that the use of short tags should be carefully weighed. But I also firmly believe that it should ALWAYS be an option, and that a developer who is aware of his environment should feel free to use them.
                            source:
                            coding style - Are PHP short tags acceptable to use? - Stack Overflow
                            Im noob, but obviously i could teach PROs like you, things or two...
                            It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt.
                            ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ !
                            ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.
                            キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

                            Comment


                              #15
                              @metulj

                              You know what I give up!! I came here to teach beginners proper ways of going forward and to be future ready, NOT just to do it now and worry later on when it gets deprecated kind of attitude (not that I am saying you have that type of attitude), I am not here to argue with you or anyone else, information I posted here was straight from the developers of PHP.

                              After all, I started here 6 years ago as a complete "noob" as they call it, I went on to learn and study loads of different coding languages, so just trying to give back to the community..

                              But to each their own..

                              Anyways, lets get back on topic..


                              @wapdxoo

                              have you managed to fix your problem?

                              Comment

                              Working...
                              X