Hello,

There is no problem.

        $url = "http://www.mydomain.com/run/file.php";     
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT,300);
$out = curl_exec($ch); $output = trim($out);
curl_close($ch); $mysqlibag->query("INSERT INTO table (id, column)values (NULL, '$output');

But I want to do this without full URL.
This cURL is for example. How can I run this $url = "/run/file.php"; without full URL? What can I run it with?

        $url = "/run/file.php";     
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT,300);
$out = curl_exec($ch); $output = trim($out);
curl_close($ch); $mysqlibag->query("INSERT INTO table (id, column)values (NULL, '$output');

Thank you in advance

    If you don't provide a fully qualified URL, how do you expect cURL (or, more generally, any function) to know what you want to do?

      Second cURL was for example.

      What can I run the code below with? (without full URL) How can I take output?

              $url = "/run/file.php";     
      
      
         $mysqlibag->query("INSERT INTO table (id, column)values (NULL, '$url');
      
        gecekule;11033207 wrote:

        What can I run the code below with? (without full URL)

        Absolutely nothing. How do you expect to connect to a webserver if you don't have the part of the URL that is used to do so (namely, the protocol and hostname)?

          bradgrafelman;11033209 wrote:

          Absolutely nothing. How do you expect to connect to a webserver if you don't have the part of the URL that is used to do so (namely, the protocol and hostname)?

          example:
          ajax like

          <script type="text/javascript">
              $.ajax({
                 url: "filename.php",
                 success: function(msg){
                 $('#msg').html(msg);
                 } 
               });        
          </script>

          But, not with ajax, with php

          I'm going to use it in the php code and to run in the background

            AJAX is a client-side language executed in a browser after a page loads; if you don't give it a full URL, it assumes you're giving it a relative URL based on the URL that was used to retrieve the original page.

            PHP, being a server-side language, isn't executing in a web browser. Thus, you're going to have to construct some sort of full URL if you want PHP to be able to do anything with it.

              bradgrafelman;11033213 wrote:

              AJAX is a client-side language executed in a browser after a page loads; if you don't give it a full URL, it assumes you're giving it a relative URL based on the URL that was used to retrieve the original page.

              PHP, being a server-side language, isn't executing in a web browser. Thus, you're going to have to construct some sort of full URL if you want PHP to be able to do anything with it.

              Thank you very much for the info, i got it

                bradgrafelman;11033213 wrote:

                AJAX is a client-side language executed in a browser after a page loads; if you don't give it a full URL, it assumes you're giving it a relative URL based on the URL that was used to retrieve the original page.

                PHP, being a server-side language, isn't executing in a web browser. Thus, you're going to have to construct some sort of full URL if you want PHP to be able to do anything with it.

                Also, consider this: if you wanted PHP to assume that you want to use the same domain that you're operating under (similar to how browsers resolve non-absolute URLs), then why would you be using cURL anyway (instead of filesystem functions)?

                  traq;11033225 wrote:

                  Also, consider this: if you wanted PHP to assume that you want to use the same domain that you're operating under (similar to how browsers resolve non-absolute URLs), then why would you be using cURL anyway (instead of filesystem functions)?

                  I am beginner. I don't know well. Can you give an example for filesystem?

                  Regards

                    If I understand what you're asking, then you can use [man]include[/man]. If not, please explain a little more.

                      traq;11033259 wrote:

                      If I understand what you're asking, then you can use [man]include[/man]. If not, please explain a little more.

                      Not include (I don't want it).
                      I will write to database after running the file below.

                      I said for an example.
                      What is there in exchange_rate.php ?
                      I will write the exchange rate after taking updated exchanged rates.
                      I will run it on background in determined times .

                              $output = "/run/exchange_rate.php";     
                      
                      
                         $mysqlibag->query("INSERT INTO table (id, column)values (NULL, '$output');
                      

                        You want to capture the output of the script and store it in a variable?

                        <?php
                        
                        ob_start();
                        include( "/filesystem/path/to/your/file" );
                        $contents = ob_get_contents();
                        ob_end_clean();
                          traq;11033285 wrote:

                          You want to capture the output of the script and store it in a variable?

                          <?php
                          
                          ob_start();
                          include( "/filesystem/path/to/your/file" );
                          $contents = ob_get_contents();
                          ob_end_clean();

                          Yes, but does not include, need to work in place xxx.php

                            I don't know what you mean by "work in place." The code I showed you uses output buffering - basically, all of the output that would normally go to the user's browser is "buffered" instead, and then stored in the variable [font=monospace]$contents[/font]. From your earlier posts, this seems like what you are asking for.

                            Did you try using the code above? What is it that does not work for your task? Please explain further.

                              Hello,
                              I run the code above, but it makes include, I don't want include.

                              Running file path and name will change.
                              Sample:
                              ..../public_html/run.php
                              url1 = "aaaaa/bbbb/1111.php"
                              url2 = "ccc/hhh/jjjj/2222.php"
                              url3 = "dddd/3333.php"

                              not standart like these.

                              There are includes in these running files, so the file needs to run in the place where it is on.

                              I will run these urls by run.php and the code, which I wanted, is for run.php

                              run.php

                                      $output = "aaaaa/bbbb/1111.php";     
                              
                              
                                 $mysqlibag->query("INSERT INTO table (id, column)values (NULL, '$output');
                              
                                gecekule;11033327 wrote:

                                I run the code above, but it makes include, I don't want include.

                                I realize there's a language barrier between us, but you're going to define what "makes include" means. Of course the file is included... that's what the [man]include[/man] construct does; it includes things - hence its name. However, the call to ob_end_clean() would at least destroy any output that the included file had generated. Is the issue with some other side effect, such as variables in the global scope being changed?

                                gecekule;11033327 wrote:

                                Running file path and name will change.
                                Sample:
                                ..../public_html/run.php
                                url1 = "aaaaa/bbbb/1111.php"
                                url2 = "ccc/hhh/jjjj/2222.php"
                                url3 = "dddd/3333.php"

                                Careful; URLs have no direct correlation to file system paths, so the two URL path components "/run.php" and "/foo/bar/foobar.php" do not necessarily imply that a file called "foobar.php" exists on the server's filesystem with a path relative to a file called "run.php" of "foo/bar/foobar.php" (although this may be the case).

                                Having said that, you can use [man]chdir/man to change the working directory to wherever these files are located before you include them.

                                  Write a Reply...