0

When I run this piece of code in an individual php file it works fine.

$ip = '*****';
$account_id = '*****';
$account_email = '*****';

//INITIALIZE MAXMIND
include_once 'src/maxmind/minfraud.phar';
use MaxMind\MinFraud;

//FORM THE MAXMIND REQUEST
$mf = new MinFraud(1234567, 'abcdefghijk');
$score_request = $mf->withDevice([
    'ip_address' => $ip,
])->withEvent([
    'type' => 'survey',
])->withAccount([
    'user_id' => $account_id,
])->withEmail([
    'address' => $account_email,
]);

//To get the minFraud Score response model, use ->score():
$score_response = $score_request->score();

//And then you'd grab $scoreResponse->ip_address->risk for the IP risk (if you're just passing the IP address), or $scoreResponse->riskScore if you are passing additional fields.
$risk_score = $score_response->riskScore;

echo $risk_score;

But if I place it in a larger segment of code I get 500 error?

I often find this when I am using libraries that this annoying problem happens and I can't see any logical reason why this is happening?

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
Amy Neville
  • 10,067
  • 13
  • 58
  • 94
  • anything relevant in logs? – Funk Forty Niner Apr 11 '17 at 21:23
  • 1
    No I added error_reporting(E_ALL); ini_set('display_errors', 1); and it didn't return any error just said 500 – Amy Neville Apr 11 '17 at 21:24
  • 3
    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [mcve]. – CollinD Apr 11 '17 at 21:24
  • Also maybe look at https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display?rq=1 – CollinD Apr 11 '17 at 21:24
  • 1
    its probably a syntax error. Make sure you've copied it without breaking brackets or another statement – Cfreak Apr 11 '17 at 21:25
  • @CollinD I think what I am asking is why is it that when I have "use" statements that I get odd behaviour where code doesn't play nicely with other code? – Amy Neville Apr 11 '17 at 21:25
  • have you checked the php eror log? 500 errors normally leave a hint in there – bumperbox Apr 11 '17 at 21:26
  • I've edited out your credentials at the top, I'm not sure if they provide access to anything, but they're not needed for the question. If they do actually provide access to anything, you'll want to change them immediately. – Alex Howansky Apr 11 '17 at 21:27
  • Check the `error.log` file on your system or server. That will tell you what the actual error is with the script. Most likely a syntax issue of some description. –  Apr 11 '17 at 21:27
  • 1
    I bet, there's an namespace declaration in the other code – Philipp Apr 11 '17 at 21:29
  • Ok, I guess I'll just keep trying to find whatever bug it is. But I often find this that I can't include libraries, even though it works fine in a simple php file test. – Amy Neville Apr 11 '17 at 21:29
  • 1
    @AmyNeville *Shot in the dark here* - I've sometimes seen namespacing going South - where the manual on that http://php.net/manual/en/language.namespaces.importing.php contains examples where there should be a starting slash, i.e.: `use \MaxMind\MinFraud;` - I could be wrong though. – Funk Forty Niner Apr 11 '17 at 21:29
  • @Fred-ii- that sounds like it might be it.....what does the starting slash mean? – Amy Neville Apr 11 '17 at 21:30
  • Is the file you are pasting that snippet into in a different path? Maybe this path `include_once 'src/maxmind/minfraud.phar';` has to be adapted to your other files location? – Yolo Apr 11 '17 at 21:30
  • @AmyNeville from the manual's example: `$obj = new \Another\thing; // instantiates object of class Another\thing` you'd need to read more inside that page. – Funk Forty Niner Apr 11 '17 at 21:31
  • @yes it is mapped to a different location with htaccess – Amy Neville Apr 11 '17 at 21:31

0 Answers0