1

I have very weird problem: I've created simple Wordpress based store. I sell e-books and send them via email. I use online payments and have plugin to work with them. It have build-in gateway in php file. I want to inject my code to this script to automatize selling. It looks like this:

<?php
//1. Get payment info from payment service via $_POST
//2. Chceck all hashes etc.
//3. Get status to variable e.g. $status
if ($status == 99)//everything is ok
{
    $order_id = $_POST["no_of_transaction"];
    log_to_file("Yeah i am workig. id =".$order_id."with status ".$status);
    include $_SERVER["DOCUMENT_ROOT"]."/sell_stuff.php";
    log_to_file("Yeah i am still workig");
}
?>

sell_stuff.php:

<?php
log_to_file("Hello i am in sending script!");
//i assume that $order_id is still visible
$order = mysql_fetch_assoc(mysql_query("SELECT * FROM order where id=".$order_id));
$mail->to = $order['email'];
$mail->attachment = "/upload/pdf/".$order['book'].'.pdf';
$mail->send();
?>

And this method not working at all :( I've tried to change include to require and use ABSPATH instead of $_SERVER["DOCUMENT_ROOT"] but it still fails. Last thing logged in log file is ""Yeah i am workig. id= xxx with status = 99". I've created test.php file like this:

<?php
echo "Yeah i am workig";
$oder_id = 100; //my own order
include $_SERVER["DOCUMENT_ROOT"]."/sell_stuff.php";
echo "Yeah i am still workig";
?>

... and when I run this via www.mystore.com/test.php it's work perfectly. It logging to file "Hello i am in sending script!" and all other stuff. I dont know where i make mistake :(

Tadeck
  • 132,510
  • 28
  • 152
  • 198
Maleficus
  • 65
  • 8
  • Before the include try (for debugging purposes) `ini_set('display_errors', true); error_reporting(E_ALL);`. Anything pops up? – VolkerK Jul 21 '15 at 08:09
  • You should not rely on $_SERVER variable but instead on the location of the calling script. Something like this : `include __DIR__ . '/../inc/sell_stuff.php' ` – jmleroux Jul 21 '15 at 08:15

1 Answers1

0

Try to drop "/", and use it like:

$_SERVER["DOCUMENT_ROOT"]."sell_stuff.php";

Also $_SERVER["DOCUMENT_ROOT"] is genereating path to you www root folder, like

www.serwer.com/www/

If u have your site in:

www.serwer.com/www/www2/

it will not get included. If u will use:

__DIR__."/sell_stuff.php";

it will get the path to place where your file is.

www.serwer.com/www/www2/

You can always:

var_dump($_SERVER["DOCUMENT_ROOT"]);
var_dump(__DIR__);

to see the difference and the path that you are getting.

fsn
  • 549
  • 3
  • 11
  • `var_dump($_SERVER["DOCUMENT_ROOT"]); var_dump(__DIR__);` are the same – Maleficus Jul 21 '15 at 08:38
  • Try to move your file lever deeper. If your main root is www.site.www/www/, then move it to www.site.www/www/www2/ and then check with above. – fsn Jul 21 '15 at 08:39
  • Yep __dir__ shows current folder and $_SERVER["DOCUMENT_ROOT"] still main folder but in my case is irrevelant becaouse sell_stuff.php is in main folder :/ – Maleficus Jul 21 '15 at 09:06