Why is my data forbidden when trying to display it on a web page? - http-status-code-403

I am in a group project with three other members where we are trying to connect to an API, store the data from that API into a shared database, and display it on a web page by accessing our code file through a server. For our project, we are connecting to four different music streaming API's, mine being Spotify. Individually, we wrote our own code in Python to connect to each of our API's and extract data to be stored in our own database. In my code, I searched the name of a particular musician, and when running the code, I connected to Spotify's API and received an output of that musician's top 20 tracks. Those 20 tracks were stored in a table in my own database in MySQL Workbench, with the columns 'tracks' and 'items'.
Now, each of my members and I have our data tables for our individual API's stored into one shared database in MySQLHosting.net. Currently, my group is struggling to print and display the data from each of our tables onto a web page. I have written a PHP file attempting to display my table for Spotify's data, and I saved the file on my server and ran chmod 755, but when I search for my PHP file in the browser, I am left with a
403 Error ("Forbidden: You don't have permission to access this
resource").
Can anyone help me figure out if it is an error in my code, or if I need to run a different chmod command? Below is the code I used to display my data.
<!DOCTYPE html>
<html>
<body>
<?php
$servername = "sql5.freemysqlhosting.net";
$username = "[removed for question]";
$password = "[removed for question]";
$dbname = "[removed for question]";
$port = "[removed for question]";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, $port);
$mysqli = mysqli_connect($servername, $username, $password, $dbname, $port);
if (!$mysqli)
{
echo 'Connection failed<br>';
echo 'Error number: ' . mysqli_connect_errno() . '<br>';
echo 'Error message: ' . mysqli_connect_error() . '<br>';
die();
}
echo 'Successfully connected!<br>';
$sql = "SELECT tracks, items FROM spotify";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
echo "tracks: " . $row["tracks"]. "<br>" . "items: " . $row["items"]. "<br>";
}
}
else
{
echo "0 results";
}
$conn->close();
?>
</body>
</html>

Related

PHP Stripe customers->search not finding accurate results

I'm having difficulty with STRIPE customer->search returning incorrect results sometimes.
If I search for a customer, and if it does not exist then add it, then repeat - I can find it adds the customer a second/third/fourth/etc times - for a while. Meanwhile on the stripe dashboard, I can see the customers appearing [multiple times].
If I waited a few minutes between initial refreshes - it seems ok.
Perhaps there's a cache, or a lag or something between adding a customer and the search finding it but this is not very helpful. Am I wrong - or is there something I'm not doing?
The relevant PHP code is here:
$stripe = new \Stripe\StripeClient($stripe_secretkey);
echo "<LI>Searching for $customerNm...</LI>";
$json = $stripe->customers->search(['query' => 'name:\'' . $customerNm . '\'']);
foreach ($json->data as $key) {
echo "<LI>Found id:[" . $key->id . "]";
if (strcmp($key->name, $customerNm) == 0) {
$customerId = $key->id;
$email = $key->email;
break;
}
}
echo "<hr>";
if (strcmp($customerId, "") == 0) {
echo "<LI>Result to search is <PRE style='margin-left:20px'>$json</PRE>";
$email = str_replace(" ", "", str_replace(" ", "", "abc#$customerNm.com"));
$json = $stripe->customers->create(
[
'email' => $email,
'name' => $customerNm,
]);
$customerId = $json->id;
echo "<UL>Created New STRIPE customer id: [$customerId]</UL>\n";
}
}
This code can be found running on a sandbox here** where if you were to run the page multiple times - it will keep creating customers [for a while].
(Note, this page will create a cookie "posterUID" which is used as the customer name; once it's created then it stays until expiry or manual deletion).
** The full source to this can be seen here
This is expected behavior per Stripe's Search documentation:
Don’t use search for read-after-write flows (for example, searching immediately after a charge is made) because the data won’t be immediately available to search. Under normal operating conditions, data is searchable in under 1 minute. Propagation of new or updated data could be more delayed during an outage.

Serial Number from custom table not appear in woocommerce_email_before_order_table action

I have a custom table with serial numbers in WordPress. I have successfully got the serial number to appear on both Order received page after testing with Stripe:
https://prnt.sc/9tz8i3BW7lJR
and it also appears on WooCommerce Admin Orders Page:
https://prnt.sc/jLyb5CQqSAH5
I am using the woocommerce_email_before_order_table action. (on customer_completed_order)
I have the code below and I have echoed the Order ID and the Custom TableName and they BOTH appear in the Thanks for shopping with us email.
It seems the $license query returns nothing and I just can't see why it won't appear.
If I exchange the $woo_order_id for the previous order no, like EMS-0051 the serial number appears.
Is this query too early and it hasn't been populated in the custom table before the query is run?
I cannot get it to work..can anyone see what I have done wrong, please?
The Thanks email and CODE are below.
https://prnt.sc/38wa50jTyr3U
<?php
add_action( 'woocommerce_email_before_order_table', 'add_serial_to_email', 25, 4 );
function add_serial_to_email( $order, $sent_to_admin, $plain_text, $email ) {
global $wpdb;
$ipn_tables = $wpdb->prefix ."ipn_data_tbl";
///////BELOW is using 'seq Order No' plugin..this checks if WOO O/N or plugins O/N.
if (empty($order->get_id)) {
$woo_order_id = $order->get_order_number();
}
elseif (empty($order->get_order_number)) {
$woo_order_id = $order->get_id();
}
///check order ID and Table name are there:
if (!empty($woo_order_id && $ipn_tables )) {
echo '<b>ORDER ID:</b> '.$woo_order_id.'<br>'; // echos the Order ID - appears on "Thanks for shopping with us" email
echo '<b>TABLE NAME:</b> '.$ipn_tables.'<br>'; // echo my Custom table name - appears on "Thanks for shopping with us" email
////But the below $license variable doesn't. I think it's a timing thing.
//$license = $wpdb->get_var(" SELECT serial_no FROM $ipn_tables WHERE woo_order_id = $woo_order_id " );
$license = $wpdb->get_var( $wpdb->prepare( "SELECT * FROM {$ipn_tables} WHERE woo_order_id = %s", $woo_order_id ) );
}
if ( $email->id == 'customer_completed_order' ){
printf( '<p class="custom-text">' .__( 'Your Software Serial Number: '.'<span style="color:red;font-weight:bold;font-size:15px">'.$license ));
}
}//function-END
?>
Forgot to show the MyPHPAdmin table:
https://prnt.sc/A4DH1v2STWrL
edit:
I should have mentioned that I put that license check for orderID and table just to see if it was being checked..it appears my get_var query isn't working (empty?) but that same query is used in the other PHP pages I edited.
Looks like I found the issue. It was the fact that 'woocommerce_payment_complete' hook
was too early BUT the hook 'woocommerce_pre_payment_complete' is called first after payment is made but before order status change and before the email is sent. :)
So all I changed in the add_action was change:
woocommerce_payment_complete' TO woocommerce_pre_payment_complete that's it.
And it worked.
part of the add_action updated code

MySQL: “Too many connections” in opencart 2.0.3.1

I recently installed opencart 2.0.3.1. Since I have installed opencart I get the below error
Warning: mysqli::mysqli() [mysqli.mysqli]: (08004/1040): Too many connections in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 7
Notice: Error: Could not make a database link (1040) Too many connections in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 10
Warning: mysqli::close() [mysqli.close]: Couldn't fetch mysqli in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 58
Below is the opencart code from file mysqli.php
public function __construct($hostname, $username, $password, $database, $port = '3306') {
$this->link = new \mysqli($hostname, $username, $password, $database, $port);
if ($this->link->connect_error) {
trigger_error('Error: Could not make a database link (' . $this->link->connect_errno . ') ' . $this->link->connect_error);
exit();
}
$this->link->set_charset("utf8");
$this->link->query("SET SQL_MODE = ''");
}
Below is the screen shot of phpmyadmin advisor. which states opencart is using too many connection. This seems to be a bug

Fatal error with Stripe Checkout: Class 'Stripe' not found

I'm trying to implement Stripe Checkout into my website. I am using Composer, everything seems to go right, but when I add my private key into init.php line 17:
Stripe::setApiKey($stripe['private']);
PHP shows me the following error:
Fatal error: Class 'Stripe' not found in/Applications/MAMP/htdocs/stripe_payment/app/init.php on line 17
Here is the full file:
<?php
session_start();
//composer auto load
require_once 'vendor/autoload.php';
$_SESSION['user_id'] = 3;
$stripe = [
'publishable' => '..... my test key.....',
'private' => '..... my test key.....'
];
//when added brakes the code
Stripe::setApiKey($stripe['private']);
$db = new PDO('mysql:host=localhost;dbname=stripe_custom;','root','root');
$userQuery = $db->prepare("
SELECT id, username, email, premium
FROM users
WHERE id = :user_id
");
$userQuery->execute(['user_id' => $_SESSION['user_id']]);
$user = $userQuery->fetchObject();
?>
I presume that this is something small, but I'm a beginner and I can't figure it out. What am I doing wrong?
The latest releases of Stripe's PHP bindings (2.*) are now using Namespaces. This means that most of the API calls have now changed and for example:
Stripe::setApiKey("sk_test_XXX");
Stripe_Customer::create();
would become:
\Stripe\Stripe::setApiKey("sk_test_XXX");
\Stripe\Customer::create();
Otherwise, if you don't want to have to update your code you need to make sure that you download the legacy version (1.18.0).

Get user details from SharePoint with PowerShell

I'm using this PowerShell script to get site owners:
$siteUrl = Read-Host "enter site url here:"
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$spWebApp = $rootSite.WebApplication
foreach($site in $spWebApp.Sites)
{
foreach($siteAdmin in $site.RootWeb.SiteAdministrators)
{
Write-Host "$($siteAdmin.ParentWeb.Url) - $($siteAdmin.DisplayName)"
}
$site.Dispose()
}
$rootSite.Dispose()
I want that it will print some details of the site owner like phone number and email. How can I achieve that?
You have two choices I think. Access the SPUser properties or get information from active directory.
In the first case, are you not able to access the properties as you did for DisplayName? I mean if you have a SPUser object to get the email just use:
write-output "$($siteAdmin.Email)"
For information about to get the user properties from active directory, you can easily implement the solution provided in the following question. It worked fine for me.
Hope this helps
EDIT with improvement
Standing from MS Documentation you have some properties avaialble, see SPUSer Members. FOr example you have not phone.
To get something from the active directory try to change the following function so that it returns the attributes you need (tested on windows 2k8 server):
function Get-AD-Data {
$strFilter = "(&(objectCategory=User))"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$objSearcher.FindAll() | select #{L="User";E={$_.properties.displayname}},
#{L="Department";E={$_.properties.department}},
#{L="MemberOf";E={$_.properties.memberof}}
}
This function returns all users from AD along with the selected attributes. To get information from a specific user you would use (I guess):
$ad_userdetails = Get-AD-Data | ? {$_.user -eq $siteAdmin.Name}
Cheers

Resources