Connect with Expertise | Find Experts, Get Answers, Share Insights

How do I access my script from another site ?

C
 
Join Date: Jan 2009
Posts: 278
#1: Jan 28 '10
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:

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

I just have :

Expand|Select|Wrap|Line Numbers
  1. if(isset($_GET['url_cd'])){ 
  2.   $prod  = $_GET['url_cd'];
  3.     <img src=\"http://first_web_site.com/gen_the_image.php?id=$prod\">
  4.     }
  5. ?>
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's Avatar
E
C
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 5,530
#2: Jan 28 '10

re: How do I access my script from another site ?


Try

Expand|Select|Wrap|Line Numbers
  1. echo file_get_contents('http://firstsite');
  2.  
C
 
Join Date: Jan 2009
Posts: 278
#3: Jan 28 '10

re: How do I access my script from another site ?


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_prod

sorry for mixing up the names a bit ! )
kovik's Avatar
E
C
 
Join Date: Jun 2007
Location: Baltimore
Posts: 870
#4: Jan 28 '10

re: How do I access my script from another site ?


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.
Markus's Avatar
E
C
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 5,530
#5: Jan 28 '10

re: How do I access my script from another site ?


file_get_contents('http://secondsite/?var=1&var2=2')

Edit: Would a header() redirect work?

Expand|Select|Wrap|Line Numbers
  1. header("Location: http://secondsite/?var=1&var2=2");
C
 
Join Date: Jan 2009
Posts: 278
#6: Jan 29 '10

re: How do I access my script from another site ?


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:

Expand|Select|Wrap|Line Numbers
  1. <img src=\"http://www.SECOND-SITE.com/sys/webthumb.php?prod_id=$Db_prod\" 
  2. width='300px' height='200px' alt='Thumbnail for $title_sht'>
AND

Expand|Select|Wrap|Line Numbers
  1. if(isset($_GET['prod_id'])){ 
  2.   $$Db_prod  = $_GET['prod_id'];
  3.     file_get_contents('http://www.FIRST-SITE.com/image-gen.php?id=$Db_prod');
  4.     }
ALSO

Expand|Select|Wrap|Line Numbers
  1. if(isset($_GET['prod_id'])){ 
  2.   $$Db_prod  = $_GET['prod_id'];
  3.     file_get_contents('http://www.FIRST-SITE.com/image-gen.php?id=$Db_prod', FILE_BINARY);
  4.     }
But none of them work :(

Any other suggestions ?



.
kovik's Avatar
E
C
 
Join Date: Jun 2007
Location: Baltimore
Posts: 870
#7: Jan 29 '10

re: How do I access my script from another site ?


file_get_contents 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.
C
 
Join Date: Jan 2009
Posts: 278
#8: Jan 30 '10

re: How do I access my script from another site ?


Thanks for your input,

So I tried this:


Expand|Select|Wrap|Line Numbers
  1. if(isset($_GET['prod_id'])){ 
  2.    $$Db_prod  = $_GET['prod_id'];
  3.    echo "file_get_contents(\"http://www.FIRST-SITE.com/image-gen.php?id=$Db_prod\", FILE_BINARY)";
  4.     }
and this:

Expand|Select|Wrap|Line Numbers
  1. if(isset($_GET['prod_id'])){ 
  2.    $$Db_prod  = $_GET['prod_id'];
  3.    echo "file_get_contents(\"http://www.FIRST-SITE.com/image-gen.php?id=$Db_prod\")";
  4.     }
But unfortunately neither worked.
kovik's Avatar
E
C
 
Join Date: Jun 2007
Location: Baltimore
Posts: 870
#9: Jan 30 '10

re: How do I access my script from another site ?


...

Expand|Select|Wrap|Line Numbers
  1. echo file_get_contents("http://www.FIRST-SITE.com/image-gen.php?id=$Db_prod");
C
 
Join Date: Jan 2009
Posts: 278
#10: Jan 30 '10

re: How do I access my script from another site ?


Ahh -
now that is more interesting !

OK - I got it to work - thanks
kovik's Avatar
E
C
 
Join Date: Jun 2007
Location: Baltimore
Posts: 870
#11: Jan 30 '10

re: How do I access my script from another site ?


Change this line:
Expand|Select|Wrap|Line Numbers
  1. $$Db_prod  = $_GET['prod_id'];
To this:
Expand|Select|Wrap|Line Numbers
  1. $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.
realin's Avatar
C
 
Join Date: Feb 2007
Location: India
Posts: 254
#12: Jan 31 '10

re: How do I access my script from another site ?


That should work for you .

http://www.digimantra.com/technology...sing-curl-php/

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

Thanks
Realin !
Reply