Phpgraphlib: internal server error - internal-server-error

I'm trying to visualize a graph on my web page using Phpgraphlib.
I use the following code:
PHP Script (graph.php):
<?php
include("phpgraphlib.php");
error_reporting(E_ALL ^ E_DEPRECATED ^ E_NOTICE);
$graph=new PHPGraphLib(550,350);
$link = mysql_connect('127.0.0.1', 'xxxx', 'xxxx') or die('Could not connect: ' . mysql_error());
mysql_select_db('quality') or die('Could not select database');
$dataArray=array();
//get data from database
$sql="SELECT country, tot_reg FROM ntr_perf_no_net WHERE data = '2016-09-05'";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
$country=$row["country"];
$reg=$row["tot_reg"];
//add to data areray
$dataArray[$country]=$reg;
}
}
//configure graph
$graph->addData($dataArray);
$graph->setTitle("Tot registration per Country");
$graph->setGradient("lime", "green");
$graph->setBarOutlineColor("black");
$graph->createGraph();
?>
Web page (graph.html):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Graph</title>
</head>
<body>
<h3>This is where I want to display my graph</h3>
<img src="graph.php" />
</body>
</html>
It is very simple but I get a 500 Internal Server Error.
I know that the PHP script is read by the server (if I put a semantic error on the PHP script I see it on the apache log), so I can't understand what is wrong.
The SQL query is ok, the files (Phpgraphlib.php, graph.html and graph.php) are in the same directory with 777 permission (files and directory).
Can you help me?
thanks
giorgio

I forgot to install GD. After I installed it, it started working.

Related

Google App Script include css from another file

I'm trying out Google app scripts for the first time and I'm having a nightmare trying to get it to read my Stylesheet.
I've read dozens of pages and they all say the same thing, but it just doesn't work.
This is my code.gs :-
return HtmlService.createHtmlOutputFromFile('index');
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
This is my index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<?!= include('Stylesheet'); ?>
</head>
<body>
Hello!!!!<br>
This is a test to see how Google scripts work<br>
</body>
</html>
This is my Stylesheet
<style>
html{
min-height:100%;
background-color:blue;
}
</style>
If I put the style tags inside the index file, it works fine, but when I try to include it, the include script just gets added to my page. I've tried using createTemplateFromFile as well, but it has the same result. It seems like index.html is ignoring the script identifier <?!
Please could someone tell me what I'm doing wrong as every page I've looked at says to do it this way!!!!!
Thanks
I assume it could be because your are not calling .evaluate()
return HtmlService.createTemplateFromFile('index').evaluate();
https://developers.google.com/apps-script/guides/html/best-practices#code.gs
Seems like it's been missed to add evaluate() function.
As per the HTML Service: Templated HTML , one should be using particular scriptlet as per the requirement.
I'd recommend a generalized solution like below:
function include(fileName, params) {
return render(fileName, params).getContent();
}
function render(path, params) {
let htmlBody = HtmlService.createTemplateFromFile(path);
// for prop drilling
htmlBody.allParams = {};
if (params) {
htmlBody.allParams = params;
Object.keys(params).forEach(key => {
htmlBody[key] = params[key];
});
}
return htmlBody.evaluate();
}

CSS Issue with Node.JS / EJS

I know similar questions have been asked before, but I've had a good look through & unfortunately none of the answers are helping me.
My CSS file is being ignored in certain circumstances.
So in my app.js file I have this code, defining my view engine setup
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
In my index.js file I have the following the code for UserList page
/* GET Userlist page. */
router.get('/userlist', function(req, res) {
var db = req.db; // (1) Extract the db object we passed to our HTTP request
var collection = db.get('usercollection'); // (2) Tell our app which collection we want to use
// (3) Find (query) results are returned to the docs variable
collection.find({},{},function(e,docs){
res.render('userlist', { "userlist" : docs }); // (4) Render userlist by passing returend results to said variable
});
});
Finally, my userlist.ejs page looks like this:
<!DOCTYPE html>
<html>
<head>
<title>User List</title>
<link rel='stylesheet' href='/stylesheets/style.css' type="text/css" />
</head>
<body>
<h1>User List</h1>
<ul>
<%
var list = '';
for (i = 0; i < userlist.length; i++) {
list += '<li>' + userlist[i].username + '</li>';
}
return list;
%>
</ul>
</body>
</html>
But when I run my page the CSS file is not loaded. However if I exclude this code:
<%
var list = '';
for (i = 0; i < userlist.length; i++) {
list += '<li>' + userlist[i].username + '</li>';
}
return list;
%>
The CSS file is loaded and applied without issue. Can anyone tell me why this is please? Apologies for the newbie question, but I've been trying to figure this out for ages.
I should mention the 'h1' tags are ignored too. The only thing rendered is the list items.
Not sure if its relevant, but my app is connecting to MongoDB to return the user data.
Any assistance would be very much appreciated!
Thank you!
Make sure that your CSS file is either defined as an endpoint in your index.js file or make sure that public/stylesheets/style.css exists so it can be loaded through the app.use(express.static(path.join(__dirname, 'public'))); command.

WordPress fallback for Bootstrap's CDN without relying on JavaScript?

Developing a theme for WordPress using Bootstrap 4 I'm familiar with the suggested approach of coding a <div>:
<div id="bootstrapCssTest" class="hidden"></div>
and checking it with JavaScript:
<script type="text/javascript">
if ($('#bootstrapCssTest').is(':visible') === true) {
$('<link href="/localcopy/css/bootstrap.css" rel="stylesheet" type="text/css" />').appendTo('head');
}
</script>
reference: "How to load local copy of bootstrap css when the cdn server is down?" but I would like a way to test the CSS without JavaScript and enqueue Bootstrap's CSS depending on if the CDN is found. Upon research I read that fopen may not be allowed always on the server level so I opted for get_headers, the code:
function bootstrap_css() {
$bootstrap_cdn = 'https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css';
$cdn_check = #get_headers($bootstrap_cdn);
if ($cdn_check[0] === "HTTP/1.1 200 OK") :
wp_enqueue_style('bootstrap',$bootstrap_cdn,array(),'4.2.1');
function add_cross_origin($html,$handle) {
if ('bootstrap' === $handle) {
return str_replace("media='all'","media='all' integrity='sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS' crossorigin='anonymous'",$html);
}
return $html;
}
add_filter('style_loader_tag','add_cross_origin',10,2);
else :
wp_enqueue_style('bootstrap',get_site_url() . '/css/bootstrap.min.css',false,'4.2.1');
endif;
}
add_action('wp_enqueue_scripts','bootstrap_css');
Is there a better approach to checking wether the Bootstrap CSS CDN is available that doesn't use JavaScript to test? Should I be checking anything beyond the "HTTP/1.1 200 OK"? Would cURL be better to use then get_headers?
After the first time the php script tries accessing the CSS file, the server returns a status code 304. The easiest implementation to check for this would be the following:
function bootstrap_css() {
$bootstrap_cdn = 'https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css';
$cdn_check = #get_headers($bootstrap_cdn);
if (strpos($cdn_check[0], "200") !== false || strpos($cdn_check[0], "304") !== false) :
wp_enqueue_style('bootstrap',$bootstrap_cdn,array(),'4.2.1');
function add_cross_origin($html,$handle) {
if ('bootstrap' === $handle) {
return str_replace("media='all'","media='all' integrity='sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS' crossorigin='anonymous'",$html);
}
return $html;
}
add_filter('style_loader_tag','add_cross_origin',10,2);
else :
wp_enqueue_style('bootstrap',get_site_url() . '/css/bootstrap.min.css',false,'4.2.1');
endif;
}
add_action('wp_enqueue_scripts','bootstrap_css');

Error when loading an external URL in an iframe with Electron

I am trying to create a desktop application using Electron but I am unable to load an external URL like google.com in an iframe.
The code below, inside index.html, triggers an error.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<!-- All of the Node.js APIs are available in this renderer process. -->
<iframe src="http://www.w3schools.com"></iframe>
<script>
// You can also require other files to run in this process
require('./renderer.js')
</script>
</body>
</html>
The error :
index.html:1 Refused to display 'https://www.w3schools.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
www.w3schools.com/ Failed to load resource: net::ERR_BLOCKED_BY_RESPONSE
What is causing this issue and how can I resolve it?
Adding to what has already been answered by Sjoerd Dal.
Adding External URL using IFRAME : Sites block adding their web pages to any other web page, for avoiding click-jacking. This is usually done by :
a. Adding a response in the header. This stops pages which are not whitelisted/not from same-origin to be included in iframes
b. Checking if top window is same as current window.
Now to answer your question, there is actually a very easy way to do that:
const urls = [
"https://www.google.com"
]
const createWindow = () =>{
win = new BrowserWindow({
center: true,
resizable: true,
webPreferences:{
nodeIntegration: false,
show: false
}
});
win.maximize();
win.webContents.openDevTools();
//win.webContents.
console.log(urls[0]);
win.loadURL(urls[0]);
// win.loadURL(url.format({
// pathname: path.join(__dirname,"index.html"),
// protocol: 'file',
// slashes: true
// }));
win.once('ready-to-show',()=>{
win.show()
});
win.on('closed',()=>{
win = null;
});
}
app.on('ready', createWindow);
Most sites these days block other people from iframing them. As you can see with this error, the site only allows iframes coming from the same domain. As an alternative you can use Electron's webview tag which starts the website on a separate thread, sandboxed in its own BrowserWindow. https://electronjs.org/docs/api/webview-tag

Trouble with PHP SDK 3 and access token

I've developed a set of pages to get permission and authenticate the user with the new PHP SDK, but even if I've read many posts and suggestions and solutions, I can't figure how to solve my trouble.
Generally I have two or more php scripts. The first one, index.php, is the one in which authorization are asked and where i get login url using sdk.
The other pages generally include a file in which I initialize facebook SDK and use some methods (like facebook->api("/me"))
Everything works fine in 90% of use, but sometimes I get errors like "An active access token must be used" (usually when i log out from facebook and then i log in trying to access the application with a different user on the same browser; however this situation is not always reproducible, even if i tried changing my user password - I know that change password is one of the way to invalidate a token).
I'll show you my code in the next lines.
Every help will be appreciated, thank you very much.
CONFIG.PHP
define('FB_APP_ID', 'my app id');
define('FB_SECRET', 'my secret');
define('FB_SCOPE', 'my scope');
define('FB_REDIRECT_URI','http://<my_base_url>/index.php');
define('FB_APP_URL','http://apps.facebook.com/<my_app_name>');
define('FB_REDIRECT_PAGE','page.php');
INDEX.PHP
<?php
include('config.php');
require 'libs/facebook.php';
$facebook = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_SECRET,
));
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
$user = $facebook->getUser();
$scope = FB_SCOPE;
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array('scope' => $scope, 'redirect_uri' => FB_REDIRECT_URI));
}
if(isset($loginUrl)) { ?>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
<script type='text/javascript'>
function doRedirect() {
top.location.href = '<?= $loginUrl; ?>';
}
window.setTimeout("doRedirect()", 1000);
</script>
</head>
<body>
Wait Please ...
</body>
</html>
<?
die();
} else {
?>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
<script type='text/javascript'>
function doRedirect() {
if (window.top === window.self) {
top.location.href = '<?=FB_APP_URL?>';
}
else {
location.href = '<?=FB_REDIRECT_PAGE?>';
}
}
window.setTimeout("doRedirect()", 1000);
</script>
</head>
<body>
Wait Please ...
</body>
</html>
<?
die();
}
?>
PAGE.PHP
include('config.php');
require 'libs/facebook.php';
$facebook = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_SECRET,
));
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
$user = $facebook->getUser();
try {
$me = $facebook->api('/me');
} catch (Exception $e) {
//header("Location: index.php");
//die();
}
this "page.php" is the one in which i usually get the Oauth exception. I can even catch the Oauth exception, but if i try to redirect to the index.php (in which I think the code I wrote can reissue the access token) an endless loop starts in the index.page (and page.php is never reached).
I read a post about token expiration handling, but currently i have some difficulty in understand where and how edit my codebase.
Thank you in advance
Emanuele

Resources