Web Hosting Talk







View Full Version : PHP Problem: Need to call back variables


barrywien
11-01-2003, 09:49 AM
Ok basically I need to send some information from one domain to another but I also need to pass a load of variables and then store them in a database.

Basically I want to track where scripts I design are in use by sending the file path and domain to a script which then stores it in a database. The database will be on my site and my customers install my scripts on there own domain meaning it has to send the variables to my domain via some sort of post method.

I can get this working with a link, however I would like to pass back either 'Verified' or 'Unverified' to my customers script to be displayed on there site.

A demo of the variables I would like to pass are here: http://www.barryw.me.uk/test.php

I have looked into the paypal IPN system to see how they work around this, they seem to pass headers and display the results which would be ideal but I am not familiar with the coding for such a call back script.

Any help appreciated.

Burhan
11-01-2003, 12:59 PM
Fwiw, the link that you posted doesn't work.

What you can do is have them send your script a "clientid" some other identifier, and then have your script send back either a verified or a non-verified image (you can do this by setting the content-type header).

They would call your script like so :

<img src="http://www.yourdomain.com/verify.php?clientid=blahclient" alt="filler" />

Then your script would return the correct image based partly on the clientid (and other things, like referer, IP, etc -- some other means of validating).

Or you can take a cue from authorize.net and only post back information to a URL that you store in your database. That way, some other person that manages to get your script, won't have it "authorized". You client can (through a login system, or my manually sending you the information) set and change this callback URL. In this scenario, a sample transaction would go about like so :


[client] -->
http://www.yourserver.com/verify.php?clientid=id

[yourscript]
1. verify client id
2. check "validity"
3. lookup callback url

Then send (as POST, a verified/not verfied key) to the callback url
(which would be at your client's server)


Another way of doing this is to run your own SOAP service that verifies the identify of your scripts (and clients), then sends back appropriate code to your scripts (this would be the best option, but requires a bit of setup).

Hopefully this gives you some ideas :)

barrywien
11-01-2003, 01:25 PM
Hi
Thanks, using the image tag line has brought me forward however I am stuck on it yet again, I have done as you said (see test.php above) but now how do I send back text. You said Then send as POST, a verified/not verfied key but how would I do this as a post?

Burhan
11-01-2003, 01:41 PM
You can do that using something like Snoopy (http://snoopy.sourceforge.net/)

barrywien
11-02-2003, 09:52 AM
I cant work that out, I need this sorted today as I cant release the new version of my software until its in place.

I will pay if need be.

Burhan
11-02-2003, 12:47 PM
Hopefully you go this sorted out -- if not, PM me details about what exactly you need help with -- and I'll see what I can do.

barrywien
11-02-2003, 12:52 PM
Ive got a little further, however I am still having problems.

Instead of displaying text I have opted to display an image, a single pixel transparent dot.

Anyway, someone suggested I look at a counter script as they do the same as what I am after, I have done this and came up with the following code but it doesnt seem to be displaying the text or storing into the database so I am guessing its not being called up properly.

This is test.php

<?php
$a = "$HTTP_HOST";
$b = explode(".", $a);
$c = "gakdskdkf";
$d = "$DOCUMENT_ROOT";
$e = "$SCRIPT_FILENAME";
$f = "$SERVER_ADMIN";

echo "<noscript><img src='index.php?ab=$b[1]&cd=$b[2]&ef=$b[3]&ghv=$b[4]&hex=$c&dr=$d&sf=$e&sn=$f&st=img'></noscript>";
?>


And this is index.php

<?php
include("/home/hc0com/public_html/fix.php");
if (($HTTP_REFERER == "test.php" || $hex=="gakdskdkf" || $st=="img")) {
echo "<img src='dot.gif'>";
$domain = "$ab $cd $ef $ghv";
$query = mysql_query("SELECT * FROM installs WHERE (domain = '$domain')");
if(($query)&&(mysql_num_rows($query)!=0)) {
while($userinfo = mysql_fetch_object($query)) {
echo "$domain found";
}
} else {
$result = mysql_query ("INSERT INTO installs (domain, email, root, filename)
VALUES ('$domain', '$sn', '$dr', '$sf')");
echo "$domain NOT FOUND so has been added";
}

} else {
header("Location: http://www.phpcart.co.uk/"); // Error Redirect
exit;
}
?>

Burhan
11-02-2003, 01:20 PM
You index.php script needs to ouput an image for it to work (which it is not doing).

Also, you can't enter HTML tags in header() calls (see the header function reference (http://www.php.net/header) for examples)

The first thing you need to do is verify what you are sending (ie, do the $a, $b $c variables exist, and do they contain valid information?)

Next thing is that you need to set the Content-Type header that will tell the browser that the content coming in is an image (for example, for gif it is header("Content-Type: image/gif"))

That should solve your problems.

barrywien
11-02-2003, 01:35 PM
The forth line of the index.php displays the image code. I dont really need to verify that all the information is there, as if its accessed directly it redirects to another page. Currently the page referer and a random hex number is checked which is enough.

I have added a header, however nothings changed.:confused:

Burhan
11-02-2003, 01:48 PM
echo "<img src='dot.gif'>";


That line doesn't output the image. It outputs HTML.

In order for your image to show up, your script has to actually output the image not HTML for the image.

Google for "outputting image php"

barrywien
11-02-2003, 01:59 PM
I cant understand this, if you use the link below it seems to work when accessed directly. However when you try the test.php page it just doesnt show the image.

http://www.v26.com/~hc0com/index.php?ab=v26&cd=com&ef=&ghv=&hex=gakdskdkf&dr=/home/v26/public_html&sf=/home/hc0com/public_html/test.php&sn=webmaster@v26.com&st=img

http://www.v26.com/~hc0com/test.php

barrywien
11-02-2003, 02:03 PM
Displaying the image is not the only problem and isnt essentially needed. The information is also not being stored into the database, however when using the link above works fine. I cant understand this but im pretty sure its down to the way im trying to send the information to index.php through test.php

Burhan
11-02-2003, 02:25 PM
Yes you are right about where the problem is, but I don't think you understand why its a problem.

The way you are calling your script, it will be displayed as an image


<img src="file.php" alt=""/>


Therefore, your script needs to be an image. For what you have right now, this is what you would get :


<img src="<img src="file.gif">" alt=""/>


What you need to is to have your script send back to the browser the actual contents of the image file, not a link to the file. What your script currently does is this :

1. Grab get query information
2. Do database check
3. Output either the <img src=""> HTML or redirect

This is what it needs to do

1. Grab get query information
2. Do database check
3. Grab the filename of the image
4. Set the content-type header for that image type (either gif/png/jpeg)
5. Read the image file, and send it back to the calling page


These are the functions that you will need :

header() (http://www.php.net/header)
readfile() (http://www.php.net/manual/en/function.readfile.php)

Does that make it any clearer?

barrywien
11-02-2003, 02:33 PM
Ah you are correct, I understand what you mean.

I thought it would be a simple script, but it didnt work out. Ive now deceided to use an iframe and scrap the image idea as this way is quicker. I really cant afford to miss the deadline I have set myself. Only problem I now face is some browsers may not support iframes but I will have to live with that for the time being

Thanks for your assistance in this thread fyrestrtr, its very much appreciated.

Burhan
11-02-2003, 02:54 PM
I don't know the details of your iframe layout, but it doesn't sound very robust.

Anyhow -- I hope you come back to this and get it working :)