Announcement

Collapse
No announcement yet.

The official PHP integration thread!

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

    #31
    Re: The official PHP integration thread!

    Thanks for info regarding the module. However, it only works in Miva 5 and we use 4. My boss figures if we're going to do as much work as 5 requires, we might as well jump straight in to PHP.

    So anybody know of any modules that allow us to use PHP in Miva 4?

    Comment


      #32
      [Tip] Wrapping miva engine in dynamic design template

      I developed a pretty simple process for wrapping a design template/php scripted page around the miva engine:

      File:
      miva_template.php

      PHP Code:
      foreach($_REQUEST as $key=>$var)
      {
          
      $mvstr .= "&".urlencode($key)."=".urlencode($var);
      }
      $mvstr .= "&Session_ID=".$_COOKIE['htscallerid'];
      include(
      "http://www.domain.com/mm5/merchant.mvc?Store_Code=ST&fromphp=1".$mvstr); 

      You need to "touch" a Miva page prior to using this as the htscallerid cookie needs to be generated.

      If I can figure out how to generate the cookie before Miva handles it, I'll post an update. Otherwise, the way I took care of it was to create a new page in Miva and fill it with nothing then access it through a small iframe or something.

      It's what we're doing now on our site.
      Webmaster
      Hobby Products International______________
      hpi racing | hot bodies

      Comment


        #33
        Re: The official PHP integration thread!

        That's interesting. I didn't think you could pass an HTTP request via the include function. Did you have a unique php setup by chance?
        Also, how are you handling the "touch" of the Miva screen?

        Comment


          #34
          Re: The official PHP integration thread!

          It's fairly typical. Only minor tweaks I've done.

          The touch was tricky, but what I did was create a new Page in Miva that contained nothing. Then I set that page as the src of an invisible, out of the way iframe (yeah yeah yeah :P) that's written from a file included in every other file. So no matter where they enter the site, they'll always have a Miva cookie generated. Really just a way for the user to hit the Miva engine and get that cookie.
          Last edited by alexboyer; 02-12-08, 08:53 AM.
          Webmaster
          Hobby Products International______________
          hpi racing | hot bodies

          Comment


            #35
            Re: The official PHP integration thread!

            Originally posted by rich1000
            being able to include MVC within a PHP file... I just wonder why it can't the other way around.
            You can. Use the HTML object tag to insert PHP pages and into Miva templates.
            Steve Strickland
            972-227-2065

            Comment


              #36
              Re: The official PHP integration thread!

              Originally posted by alexboyer
              It's fairly typical. Only minor tweaks I've done.

              The touch was tricky, but what I did was create a new Page in Miva that contained nothing. Then I set that page as the src of an invisible, out of the way iframe (yeah yeah yeah :P) that's written from a file included in every other file. So no matter where they enter the site, they'll always have a Miva cookie generated. Really just a way for the user to hit the Miva engine and get that cookie.
              But wouldn't that iframe be loaded last (meaning all of the server side scripts would be processed without access to the MM5 cookie)? Another way to do it (without an iframe) would be to use file_get_contents(<your mm5 page>). This would "call the page", but wouldn't display the results. You can capture the results by saving it to a variable; which you can then manipulate and echo.

              Comment


                #37
                Re: The official PHP integration thread!

                Originally posted by Brandon MUS
                But wouldn't that iframe be loaded last (meaning all of the server side scripts would be processed without access to the MM5 cookie)? Another way to do it (without an iframe) would be to use file_get_contents(<your mm5 page>). This would "call the page", but wouldn't display the results. You can capture the results by saving it to a variable; which you can then manipulate and echo.
                The iframe is just to touch Miva and generate a cookie. The next page visit, refresh or other bit of activity will carry over the cookie info. So you're right in that their first page view will not have access to the cookie. I'm not too worried about that though as it would be a rare occurance for us to get product add requests on the first page view.

                My fear about doing it with file_get_contents is that PHP sends the request from the server, not the client's browser, which might result in shared htscallerid hashes. I'm sure you can imagine what would happen with that hehehe.

                The iframe sends the page request to Miva from the client's browser so there's no chance of a shared hash.
                Last edited by alexboyer; 02-14-08, 09:19 AM.
                Webmaster
                Hobby Products International______________
                hpi racing | hot bodies

                Comment


                  #38
                  Re: The official PHP integration thread!

                  Ah, you are correct. I guess technically your server would be receiving a cookie. The only thing I could think of better than an iframe would require JavaScript.

                  I like your idea though, much better than what I was doing :D

                  Comment


                    #39
                    Re: The official PHP integration thread!

                    Originally posted by Brandon MUS
                    That's interesting. I didn't think you could pass an HTTP request via the include function. Did you have a unique php setup by chance?
                    Also, how are you handling the "touch" of the Miva screen?
                    I found out what the difference with this was.

                    Requests cannot be sent that way if you're including a file.
                    include($_SERVER['DOCUMENT_ROOT']."/path/to/file.mvc?somevar=true"); //will not work: Gives file not found error.

                    Requests can be sent that way if you're including a url.
                    include("http://www.domain.com/path/to/file.mvc?somevar=true"); //will work

                    Who knew? :p
                    Webmaster
                    Hobby Products International______________
                    hpi racing | hot bodies

                    Comment


                      #40
                      Re: The official PHP integration thread!

                      Another cool tidbit to add on there is the same thing works with file_get_contents(), fopen(), and most other file handling functions in PHP. If you specify a HTTP wrapper in the file name, PHP will send a HTTP request including GET requests.

                      Comment


                        #41
                        Re: The official PHP integration thread!

                        Oh nice, I hadn't considered that. That way you could actually plug it into a variable, huh? Sheesh, that opens up all kinds of stuff, thanks!!!
                        Webmaster
                        Hobby Products International______________
                        hpi racing | hot bodies

                        Comment


                          #42
                          Re: The official PHP integration thread!

                          Yeah wow, that's way more powerful than my original concept.
                          Webmaster
                          Hobby Products International______________
                          hpi racing | hot bodies

                          Comment


                            #43
                            Re: The official PHP integration thread!

                            So the new method would be:
                            PHP Code:
                            foreach($_REQUEST as $key=>$var)
                            {
                                
                            $mvstr .= "&".urlencode($key)."=".urlencode($var);
                            }
                            $mvstr .= "&Session_ID=".$_COOKIE['htscallerid'];
                            $mivaSrc file_get_contents("http://www.domain.com/mm5/merchant.mvc?Store_Code=ST&fromphp=1".$mvstr); 
                            Then you could plug in the entire page into the template:
                            PHP Code:
                            $template = <<<EOT
                            <div>{$mivaSrc}</div>
                            EOT;

                            echo 
                            $template
                            Webmaster
                            Hobby Products International______________
                            hpi racing | hot bodies

                            Comment


                              #44
                              Re: The official PHP integration thread!

                              Another way to execute PHP (or any other system command for that matter) is to create your own builtin library in c or c++ and hook that into the VM, just like you do with extension for PHP.

                              There really isn't much documentation on this but you can get a good starting point reading through the documentation as well as referencing this post as a code example:

                              http://extranet.mivamerchant.com/for...=1071#post1071

                              I have already created a simple example of this (although c/c++ isn't my strong point) which you can check out here:

                              https://github.com/ghassani/miva-library-test

                              Using a c/c++ function like popen to execute a system command (like php's exec, or shell_exec, etc) you can call PHP to execute a script from CLI or even pass raw PHP to the spawned process. If you wish to test it out, there is a *nix compatible .so in the release folder. I have not tested this on windows, I know windows has some issues with _popen on non-console applications.

                              The Miva VM is suppose to be sandboxed as stated in the documentation which is why a command like this has not been implemented. Just be aware of that.

                              Comment

                              Working...
                              X