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 :(
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.
Related
I am trying to setup a PHP document but I currently am looking for a way to use the die() function and display some content on every page using my global configuration file. The way I am think how it should work is that IF the requested URL (e.g. domain.com/services/disabledservice) would have /services/disabled service and a value of 1 to make the value true in a MYSQL DB.
The plan is to have the URL be collected and checked with a table than if the row has a value of 1 for status it will display a disabled page message but if it’s 0 it will load normally.
Some research I have conducted may lead be to think that using the SQL query and the if function could work for this.
The idea I have is this but it may not be correct.
<?php $pageurl = [requested URL content here]
$checkstatus = "SELECT * FROM servicestatus WHERE page =" . $pageurl . "AND status = 1";
if ($status = mysqli_query($conn, $servicestatus)) {
if (mysqli_num_rows($status) = 1) { ?> html content here
<?php }
} else { ?>
page as normal
<?php } ?>
Edit:
To explain what I am trying to do.. I am trying to fetch the URL without everything past “?” Than I am trying to use that in a DB query to check with the database if that has a value of “m” or “d” and if it has one of those values next to the URL which is being fetched it will display the appropriate error page. This is being included as part of my core configuration file which includes my “$conn” and the core values for most stuff. The problem I am facing is that when I send my URL without everything past the “?” I am not receiving my error page and everything is loading like normal.
Use any one the following php functions:
include 'path_to_the_page.php' (or) require 'path_to_the_page.php';
The difference between include and require arises when the file being included cannot be found: include will emit a warning ( E_WARNING ) and the script will continue, whereas require will emit a fatal error ( E_COMPILE_ERROR ) and halt the script.
I'm building a website with a very basic blog-like "News" functionality. Basically, you enter the title, author, author's picture, date, and message of the news update to on a password-protected form, and then the magic of PHP grabs that stuff and sticks it in a MySQL database. Then, using more PHP, these little articles are dynamically loaded on a "News" page. The script that uploads the data to the MySQL database works fine. So does the script that displays the news on the webpage. Here's the problem: if I edit the "display" PHP script and upload the edited script onto the hosting server, those edits aren't reflected in the website. Here's my code:
<?php
include('dbconnect.php'); //connects to database
//select the table
$result = mysql_query("select * from newscms order by id desc limit 5");
//grab all the content from the table
while($r = mysql_fetch_array($result))
{
$id = $r['id'];
$title = $r['title'];
$date = $r['date'];
$user = $r['user'];
$icon = $r['icon'];
$message = $r['message'];
//displays the rows
echo "<img src='$icon' align='left'/><strong>$title</strong> <br/>
Posted on $date
Posted by: <strong>$user</strong><br />
$message <br />";
}
?>
Now if I changed the "echo" function to instead show something like:
echo "<img src='$icon' align='right' width='12' height='24'/><em>$title</em> <br/>
Posted on $date
Posted by: <strong>$user</strong><br />
$message <br /> I like turtles";
(Notice I have changed the alignment and size of the icon, changed <strong> to <em> for the title, and added the text "I like turtles" to the end)
with all these changes, absolutely nothing changes on the webpage!
Why? It's driving me insane! Is there some flaw in my script I can't see? Is it a server-side problem that I should contact my web host about? (And before you ask, yes, I cleared my browser cache.) Help please!
Step 1 create a new folder to your desktop called any name then download the updated file from your ftp folder to your local folder . then open that file you downloaded and see if really those changes you made exists . from there you might be able to trace what might be the cause of that problem . Also if I were you I would have deleted the that file in the ftp and I upload the current one so that I can be sure.
So.
It was a pathname problem. Sort of.
At first, I was implementing the display functionality by using a PHP include function to include a "display.php" file. Then, for reasons now forgotten, I commented out that function and instead copy-pasted the contents of the display.php file into the webpage file. Of course, I forgot that I did that, and have been editing the display.php file. Solution: stop being an idiot, uncomment that include, and delete the rest. All fixed. Thank you to everyone who tried to help.
I am only just starting to get to grips with PHP, so please forgive me if I have missed something obvious. My problem is this:
I have a script that validates when a payment has been made, when a payment has been made it includes the following:
include 'newtest/generate.php';
"generate.php" creates a random single use URL, finds the user that is logged in and emails the link to them. It finds the users email like this:
include 'includes/common.inc.php';
$query = "SELECT * FROM " . $DBPrefix . "users WHERE id = " . $user->user_data['id'];
$result = mysql_query($query);
$USER = mysql_fetch_assoc($result);
$usermail = $USER['email'];
If I run generate.php via my browser, everything works fine.. it picks up the logged in user details and sends the link.
However, when a paypal payment is made it won't. I thought this might be something wrong with paypal validation. But its not, if I set
$usermail = 'me#mydomain.com';
and then make a test payment, everything works fine. So basically, why won't my script pick up on the users email when paypal sends the request?
Maybe you need to put an absolute path on the include file. If that file contents some data like $DBPrefix, the query couldn't be completed. You can call PHP's function error_log to see the query.
I'm creating a language file - content modifying file - for my website so that I can change text over multiple websites in my admin panel. I have everything working except one thing. When I use a standard lang.php file with the contents like this:
$error_page_title = "$sitename | PAGE ERROR";
and use
<? echo $error_page_title ?>
I get:
example.com | PAGE ERROR to appear on my website. Perfect, exactly what I want. Reflects the $sitename in my config file and outputs the correct website name.
When I do it as a function:
function langString($lang_id) {
$lang_result = mysql_query("SELECT lang_string as phrase FROM lang WHERE lang_id='$lang_id'");
$lang_row = mysql_fetch_array($lang_result);
return $lang_row[phrase];
}
and use
<? echo langString(3); ?>
I get:
$sitename | PAGE ERROR appearing on my website. Not what I want... Arrr!
How can I get it so that my output is recognized as PHP instead of text?
echo str_replace('$sitename', $sitename, langString(3));
when using your function langString() instead of
return $lang_row[phrase];
use
return $lang_row['phrase'];
Also use <?php instead of <?, some servers cannot parse it correctly if you only use <?. probably not the problem, but never know
I have somewhat of a knowledge of the PHP coding language and I would like to connect the Campaign Monitor API(Link) with my website, so that when the user enters something into the form on my site it will add it to the database on the Campaign Monitor servers. I found the PHP code example zip file, but it contains like 30 files, and I have no idea where to begin.
Does anyone know of a tutorial anywhere that explains how to connect to the API in a step-by-step manner? The code files by themselves include to much code that I may not need for simply connecting to the database and adding and deleting users, since I only want to give the user the power to add and delete users from the Mailing List.
This actually looks pretty straightforward. In order to use the API, you simply need to include() the CMBase.php file that is in that zip file.
Once you've included that file, you can create a CampaignMonitor object, and use it to access the API functions. I took this example out of one of the code files in there:
require_once('CMBase.php');
$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$client_id = null;
$campaign_id = null;
$list_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$cm = new CampaignMonitor( $api_key, $client_id, $campaign_id, $list_id );
//This is the actual call to the method, passing email address, name.
$result = $cm->subscriberAdd('joe#notarealdomain.com', 'Joe Smith');
You can check the result of the call like this (again taken from their code examples):
if($result['Result']['Code'] == 0)
echo 'Success';
else
echo 'Error : ' . $result['Result']['Message'];
Since you're only interested in adding a deleting users from a mailing list, I think the only two API calls you need to worry about are subscriberAdd() and subscriberUnsubscribe():
$result = $cm->subscriberAdd('joe#notarealdomain.com', 'Joe Smith');
$result = $cm->subscriberUnsubscribe('joe#notarealdomain.com');
Hope that helps. The example files that are included in that download are all singular examples of an individual API method call, and the files are named in a decent manner, so you should be able to look at any file for an example of the corresponding API method.