We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25044
    • 11 Posts
    I am a ColdFusion Developer and I do not know much about PHP. I am now using MODx to run some of my sites but I ran into an issue when trying to include a cfm page into a php page. I already have some dynamic pages built in ColdFusion so I just want to utilize some of the code I already have.

    I would like to know if there is a way that I can:

    1. Include a page from a different language like .cfm, .jsp, .asp, etc. within PHP and pass the current page’s query parameters to it by a relative path on the same web root? If so, how?
    2. Get a page’s content through a url like a PHP http tag? If so, how?

    Thanks.
      • 10449
      • 956 Posts
      Well, every server scripting language requires its own parser. Is ColdFusion installed on your server? If not, all you’ll see when using PHPs include() or require() is the raw CF code.

      If the so-called fopen wrappers are enabled to open remote pages (usually defined in the php.ini config file), you can include the parsed output of your .cfm pages in PHP. But that will only contain the HTML that CF outputs (the thing that every browser sees).

      For more infos on the relevant functions, check out the manual for:
      fopen()
      file_get_contents()
      include()
      require()
      readfile()

      http://ch2.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen
        • 25044
        • 11 Posts
        @ ganeshXL

        You Were On Point!!

        I am able to do it with the include() & require(). When I try to do it with a relative path, it will not give me the executed .cfm output but when I use the URL, it gives me the executed output which is what I needed. I think a change in the php.ini also allowed me to get it by URL as well.

        Now that I have that working, I also needed to find out how to get query string parameters and submitted form field parameters:

        1) For example: http://www.example.com/index.php?color=blue&contact_id=92347&catid=24&title=whatever+it+is
        How do I reference these query strings? My main goal for this is to dynamically pass one or more of the parameters to another link in the same page but it will be passed to a CFM url like this:

        <a href="http://www.example.com/contactdetails.CFM?contact_id= <--- in ColdFusion I would just reference it as #url.contact_id#... What php code do I put here based on the query string above?


        2) If I passed a contact_id and contact_name field from a form to php, how do I reference it in a link again
        <a href="http://www.example.com/contactdetails.CFM?contact_id=???&contact_name=???


        Thanks!



          • 28042 ☆ A M B ☆
          • 24,524 Posts
          If it’s in a form use $_POST[’fieldname’] to access them. If it’s from the URL query string, use $_GET[’key’] to access them. $_REQUEST[’name’] will get POST, GET and COOKIE into one array, but that’s a bit less secure since it jumbles them all up together. You should only use $_REQUEST when you aren’t sure where it’s coming from; I’ve only used it with some AJAX libraries that are inconsistent how they pass the values.

          Make sure to validate and "sanitize" any and all incoming data, no matter where it comes from (for example, if you use a hidden field in a form to pass on a value via the POST). Especially if you’re going to use the values in email or to query the database. Even if it’s only going to be used as a search filter in the database.

          If you’re new to PHP here’s a couple of good articles:

          http://www.devshed.com/c/a/PHP/PHP-Security-Mistakes/
          http://www.onlamp.com/pub/a/php/2003/07/31/php_foundations.html
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 25044
            • 11 Posts
            @sottwell

            It Worked!!!

            Much appreciated...

            I am going to start a new thread requesting other good online PHP tutorials so that I can get up to speed with this language that I am beginning to like.

            Thanks again.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Ah, the enthusiasm of youth! Would that I could recover that energy grin grin
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 7231
                • 4,205 Posts
                Just curious, why are you not doing this 100% in CF? Is this a result from the CF community (specially the open source community) being very limited or are you making a conscious decision to move to php?
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]