Danny and Knight are right, there is no sure way to do this, since there can be multiple input addresses that sent you the funds.
However there is a way to get the 1st input sending address of the most recent transaction to a particular address.
I did a video tutorial on how to do this a few months back with blockchain.info.
https://youtu.be/_K270ufQ6ho?t=1mGo here ->
https://blockchain.info/api/blockchain_apiScroll down to the single address area:
Then you'll take your $input_address and plug it in:
https://blockchain.info/address/$bitcoin_address?format=json
Replace $bitcoin_address with the input_address that received the funds.
and then you can pull out the most recent transaction and then pull out the address from the inputs array.
Again watch the video ^^
Your code will look something like:
<?php
$input_address = "1someBitcoinAddress";
$url = "https://blockchain.info/address/$input_address?format=json";
$jsonData = json_decode(file_get_contents($url), true);
$sendingAddress = $jsonData["txs"][0]["inputs"][0]["prev_out"]["addr"];
echo "This address ".$sendingAddress." sent the most recent transaction";
//or you can enter the $sendingAddress to a DB
?>
If you want to get all the input addresses that sent for the most recent transaction you will just create a loop that counts the number of inputs
something like:
$n_inputs = count($jsonData["txs"][0]["inputs"]);
for($ii = 0; $ii < $n_inputs; $ii++){
$inValue = $jsonData["txs"][0]["inputs"][$ii]["prev_out"]["addr"];
}
I also did a video on making the loops but with chain.com API
https://youtu.be/OUdGJK-sJ2k?t=2m33s start video at 2:33