How do I access my script from another site ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeddiki
    Contributor
    • Jan 2009
    • 290

    How do I access my script from another site ?

    Hi,
    I have my image generator on one website and I want to use
    the script on my second website. This scripts tracks the image
    downloads to a database so I want to keep the scripts on that server.

    Now I don't want to directly refer to the script of the other site in the HTML, so I am trying to access it via an intermediate php page,
    so I tried this:

    On my second website:

    Code:
    echo "<img src=\"http://www.second_site.com/sys/image_gen.php?url_id=$Db_prod\" 
    width='300px' height='200px' 
    alt='Thumbnail for $title_sht'  border='2'>";
    And then, still on second website, in the image_gen.php

    I just have :

    Code:
    if(isset($_GET['url_cd'])){ 
      $prod  = $_GET['url_cd'];
    	<img src=\"http://first_web_site.com/gen_the_image.php?id=$prod\">
    	}
    ?>
    But this "image redirect" doesn't work

    Probably because I am doubling up on the <img src> tags but I don't
    know how to do this.

    Any ideas on how to make it work ?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Try

    Code:
    echo file_get_contents('http://firstsite');

    Comment

    • jeddiki
      Contributor
      • Jan 2009
      • 290

      #3
      That's pretty good, but can I pass the url_cd variable over
      with that method ?

      I need to pass the ?id=$prod so that the
      correct image gets generated.

      ( the prod code is the url_cd so it is the
      same as the ?url_id=$Db_pro d

      sorry for mixing up the names a bit ! )

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        Well, if you know that the other page outputs an <img> tag, then why are you wrapping it in an <img> tag? The tag is already made for you. Either only use that tag, or change the script to only output the "src" attribute.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          file_get_conten ts('http://secondsite/?var=1&var2=2')

          Edit: Would a header() redirect work?

          Code:
          header("Location: http://secondsite/?var=1&var2=2");

          Comment

          • jeddiki
            Contributor
            • Jan 2009
            • 290

            #6
            Well, if you know that the other page outputs an <img> tag, then why are you wrapping it in an <img> tag? The tag is already made for you. Either only use that tag, or change the script to only output the "src" attribute.
            Yes ... but How ?

            I tried the following:

            Code:
            <img src=\"http://www.SECOND-SITE.com/sys/webthumb.php?prod_id=$Db_prod\" 
            width='300px' height='200px' alt='Thumbnail for $title_sht'>
            AND

            Code:
            if(isset($_GET['prod_id'])){ 
              $$Db_prod  = $_GET['prod_id'];
            	file_get_contents('http://www.FIRST-SITE.com/image-gen.php?id=$Db_prod');
            	}
            ALSO

            Code:
            if(isset($_GET['prod_id'])){ 
              $$Db_prod  = $_GET['prod_id'];
            	file_get_contents('http://www.FIRST-SITE.com/image-gen.php?id=$Db_prod', FILE_BINARY);
            	}
            But none of them work :(

            Any other suggestions ?



            .

            Comment

            • kovik
              Recognized Expert Top Contributor
              • Jun 2007
              • 1044

              #7
              file_get_conten ts returns a string.. You have to echo it. Also, if you are going to inject a variable directly into a string, you need to use double-quotation marks ("), not single-quotation marks ('). Single quotation marks don't parse variables.

              Comment

              • jeddiki
                Contributor
                • Jan 2009
                • 290

                #8
                Thanks for your input,

                So I tried this:


                Code:
                if(isset($_GET['prod_id'])){ 
                   $$Db_prod  = $_GET['prod_id'];
                   echo "file_get_contents(\"http://www.FIRST-SITE.com/image-gen.php?id=$Db_prod\", FILE_BINARY)";
                    }
                and this:

                Code:
                if(isset($_GET['prod_id'])){ 
                   $$Db_prod  = $_GET['prod_id'];
                   echo "file_get_contents(\"http://www.FIRST-SITE.com/image-gen.php?id=$Db_prod\")";
                    }
                But unfortunately neither worked.

                Comment

                • kovik
                  Recognized Expert Top Contributor
                  • Jun 2007
                  • 1044

                  #9
                  ...

                  Code:
                  echo file_get_contents("http://www.FIRST-SITE.com/image-gen.php?id=$Db_prod");

                  Comment

                  • jeddiki
                    Contributor
                    • Jan 2009
                    • 290

                    #10
                    Ahh -
                    now that is more interesting !

                    OK - I got it to work - thanks

                    Comment

                    • kovik
                      Recognized Expert Top Contributor
                      • Jun 2007
                      • 1044

                      #11
                      Change this line:
                      Code:
                      $$Db_prod  = $_GET['prod_id'];
                      To this:
                      Code:
                      $Db_prod = $_GET['prod_id'];
                      Even if it doesn't help, it's likely what you meant to do. Using 2 dollar signs is very different than 1.

                      Comment

                      • realin
                        Contributor
                        • Feb 2007
                        • 254

                        #12
                        That should work for you .

                        We're your go-to experts for mobile app and web development. As a global software development company, we deliver innovative solutions tailored to your needs.


                        You can pass the query string in the URL as well.

                        Thanks
                        Realin !

                        Comment

                        Working...