remote server does not like whatsapi script line - php

I have just resolved one whatsapi issue on this forum and now am confronted with another one.
I am running scripts by calling the classes in whatsprot.class.php. I can run all scripts on my local machine like a charm. But remote server doesn't like the a certain line in my script and refuses to go beyond that;
My script is;
require "src\whatsprot.class.php";
$username = "91xxxxxxxxxxx"; //Mobile Phone prefixed with country code so for india it will be 91xxxxxxxx
$password = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$identity = strtolower(urlencode(sha1($username, true)));
$w = new WhatsProt($username, $identity, 'WhatsApp Messaging', true);
The line that my remote server doesn't cross is;
$w = new WhatsProt($username, $identity, 'WhatsApp Messaging', true);
I definitely am an amateur. So do let me know what other info would be required to demystify this issue...

Finally the error logs told me that there was some path issue in the libraries. When I moved my executing file into the "src' directory where whatsprot.class.php was located, voilĂ  the script started working !

Related

PHP 7 - SFTP keeps interrupting page to load

I'm currently trying to get a file from a server by php sftp. I managed to authenticate and connect to the server. The problem is, that if I want to open a dir on said server, the page just keeps loading until my browser tells me the loading of the page has been interrupted. This only happens, if I try open a dir that EXISTS. If I open a dir that doesn't exist, I get a normal error message.
Therefor I'm not quite sure, wether this is a mistake in my code or a problem with the ftp server.
My Code:
ini_set("display_errors", "1");
$host = "<host>";
$port = 22;
$conn = ssh2_connect($host);
$username = "<user>";
$pub_key = "/home/<user>/.ssh/id_rsa.pub";
$pri_key = "/home/<user>/.ssh/id_rsa";
if (ssh2_auth_pubkey_file(
$conn,
$username,
$pub_key,
$pri_key
)) {
if(!$sftp = ssh2_sftp($conn)){
die("SFTP Connection failed");
};
opendir("ssh2.sftp://".intval($sftp)."/./");
};
Has anyone ever experienced something similar?
I'd be glad for any help :)
~François
It is the expected way.
Opendir return a handle. Your function is working, it's just that you do nothing with the data, and your php script do nothing. It's just waiting with the information
Just handle data, or at least write an echo and it should be ok.
check the manual, there is a working example http://php.net/manual/en/function.opendir.php

Apache2 configuration only execute PHP partially

I am experiencing trouble while installing Apache2 on my Debian 8 VPS (jessie).
I installed the website correctly on Hostinger, it works perfectly, but knowing Hostinger was a free plan, I moved to a sufficient VPS so I could get my hands dirty and do the job my myself. I now can handle everything, but the truth is, it's been a long time since I didn't use a debian server, and installing Apache seems harder than I thought.
So, I secured my VPS as I wanted, that's not the problem, the site works correctly, but partially.
I mean, on somes pages, the PHP code executes very well, it works with my database without any problem. I have a utils.php file that contains a getBDD() function like this one :
return new PDO("mysql:host=localhost;dbname=name;charset=utf8", "user", "password");
And it works on my main pages, I can request everything. You can see it here : http://mdjfeelzor.ovh/petiteancienne.php (the website is french).
But I also have an ajax chat that needs a bit of PHP to work properly. Aaaand I don't understand why, but when I initialize my $conn with getBDD(), I am experiencing an issue further in the code.
Look at that code :
include '../utils.php';
session_start();
if(isset($_POST['enter'])){
if($_POST['name'] != ""){
$_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
try {
$conn = getBDD();
$answer = $conn->prepare('SELECT * FROM openchats WHERE ip=? AND name=?');
$answer->execute(array(stripslashes(htmlspecialchars($_SERVER['REMOTE_ADDR'])),
stripslashes(htmlspecialchars($_SESSION['name']))));
if (!($data = $answer->fetch())) {
$req = $conn->prepare('INSERT INTO openchats (ip, name) VALUES (:ip, :name)');
$req->execute(array(
'ip' => stripslashes(htmlspecialchars($_SERVER['REMOTE_ADDR'])),
'name' => stripslashes(htmlspecialchars($_SESSION['name']))));
}
}
catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
}
}
It works correctly, right ? (it's supposed to work correctly on your machine) But the thing is, the code starts showing on my web page on the first call of prepare() as you can see here : http://mdjfeelzor.ovh/chat
So, I was wondering, what do you think is the problem ? Is it my way of programming that isn't working ? By the way, I'm using PHP5. I also tried the code <?php phpinfo(); ?> it works perfectly.
Thanks for your help !
EDIT : By the way, the code is shown but it is not supposed to enter in the condition, as $_POST['enter'] doesn't exist on the first load, the code really works on my computer and on Hostinger so I think that the problem comes from Apache configuration ^^' and the AJAX code is not running at that point.

PHP session variables not available when emulating Cordova App

This is killing me.
I am building a mobile app using apache cordova where jQuery AJAX and PHP are being used to communicate with the server and database. I first discovered this issue when I was encountering errors that my teammates were not, and we were using the same code. In some of our PHP code, we were using $_SESSION variables to store data but it is not being stored properly when running the app on my machine. Here is an example of the code that is not working:
<?php
header('Access-Control-Allow-Origin : *');
include 'connection.php';
$userId = $_SESSION["userId"];
$query = "SELECT * ".
"FROM `db`.`users` ".
"WHERE `userId` = $userId;";
$result = $conn->query($query);
$result_array = array();
while($row = mysqli_fetch_assoc($result))
{
$result_array[] = $row;
}
echo json_encode($result_array);
In a page that runs prior to this, a different php file is called containing this line:
$_SESSION["userId"] = $userId;
include connection.php contains all our user/login info as well as session_start(); before anything. The workaround was this: This error does not happen when I build the app and test it on a device. It only occurs on my machine when debugging the app through the ripple emulator in a chrome browser window. Because I did not want to create a new build so frequently, I changed our code to store the data on the front end, using sessionStorage, and had to disable the Cross Domain Proxy setting on the emulator.
This is where I believe the error is: None of my AJAX calls are successful unless I set the Cross Domain Proxy to "Disabled", but if I do that, PHP $_SESSION no longer works (I discovered the session id just resets every new call). My teammate can debug on the emulator just fine and his Cross Domain Proxy is set to "Local". When I try it this way, all of my AJAX calls error out once again.
Also - one last thing to note: When I run the app in just a web browser, not using the ripple emulator or anything, everything runs just fine. Which would narrow the issue down to something specifically with the ripple emulator.
I am relatively new to this stuff - CORS and AJAX requests, but I did some serious research before posting on here - this is my last resort. I will be monitoring this question frequently in case you need anything else from me to help me solve this issue. Thanks!
EDIT: Below is the error I get when I run ripple emulate from the command line after making some of the suggested changes, it's the same error I was getting before:
C:\Users\Brian\Documents\HoH Docs\Source Code\gitDev\HoH\www>ripple emulate
INFO: Server instance running on: http://localhost:4400
INFO: CORS XHR proxy service on: http://localhost:4400/ripple/xhr_proxy
INFO: JSONP XHR proxy service on: http://localhost:4400/ripple/jsonp_xhr_proxy
INFO: Could not find cordova as a local module. Expecting to find it installed g
lobally.
INFO: Using Browser User Agent (String)
INFO: Proxying cross origin XMLHttpRequest - http://www.server.com/php/
signIn.php?email=b_dz#gmail.com&password=test
_http_outgoing.js:347
throw new TypeError(
^
TypeError: Trailer name must be a valid HTTP Token ["access-control-allow-origin
"]
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:347:13)
at ServerResponse.res.setHeader (C:\Users\Brian\AppData\Roaming\npm\node_mod
ules\ripple-emulator\node_modules\express\node_modules\connect\lib\patch.js:59:2
2)
at Request.pipeDest (C:\Users\Brian\AppData\Roaming\npm\node_modules\ripple-
emulator\node_modules\request\main.js:723:12)
at C:\Users\Brian\AppData\Roaming\npm\node_modules\ripple-emulator\node_modu
les\request\main.js:614:14
at Array.forEach (native)
at ClientRequest.<anonymous> (C:\Users\Brian\AppData\Roaming\npm\node_module
s\ripple-emulator\node_modules\request\main.js:613:18)
at ClientRequest.g (events.js:260:16)
at emitOne (events.js:77:13)
at ClientRequest.emit (events.js:169:7)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:433:21
)
And get this from the Fiddler Web Debugger when the request is made:
The connection to 'localhost' failed. <br />Error: ConnectionRefused (0x274d). <br />System.Net.Sockets.SocketException No connection could be made because the target machine actively refused it 127.0.0.1:4400
This is most likely your problem:
header('Access-Control-Allow-Origin : *');
include 'connection.php';
You are sending headers to the browser before you include the connection file where you start the session.
On some testing environments, output buffering might be turned on so this would work. However, on your environment it seems it is not so your session_start() in connection.php will fail.
You should not output anything to the browser before the call to session_start() so in this case you should move the header() call to below the include:
include 'connection.php';
header('Access-Control-Allow-Origin : *');
You can probably verify that this is the problem in the server error log.
You might be have to set header in your ajax request
if your are using jQuery ajax method then add below option
xhrFields: {
withCredentials: true
}
Or if you send ajax request using XMLHttpRequest object then it should be something like belwo
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://example.com/', true);
xhr.withCredentials = true;
xhr.send(null);
XmlHttpRequest responses from a different domain cannot set cookie
values for their own domain unless withCredentials is set to true
before making the request, regardless of Access-Control- header
values.

Amazon Web Services (AWS) SDK 1.6 - PHP - Returns absolutely nothing

Just trying to get past the first hurdle with AWS.
We've had to use the older verion of the SDK - 1.6.2 because our servers all run PHP 5.2 which doesn't have namespace support.
I have created my config file and popped my deets in, I am including the sdk.class.php etc like so:
$file = $_SERVER['DOCUMENT_ROOT']."/lib/aws-sdk-1.6.2/sdk.class.php";
if (file_exists($file)) {
require_once ($file);
$ec2 = new AmazonEC2();
$response = $ec2->describe_availability_zones();
print_r($response);
} else {
die('No file');
}
In here I am also dumping the response but for every call I do to whichever service I just get a completely blank response. Not a zero, no blank array, not even the word null.
Without any output to view I am completely stumped. Any ideas on how to even get it to tell me where the problem could be would be amazing.
Thanks!

Can 32-Bit PHP run a .vbs script on a 64-Bit IIS Server?

There is a vbscript that we must run to consolidate information gathered in a custom web application into our management software. The .vbs is in the same folder as the web application which is built in CodeIgniter 2.
Here is the controller code:
public function saveToPM( $budgetType ){
// run it
$obj = new COM( 'WScript.Shell' );
if ( is_object ( $obj ) ) {
$obj->Run( 'cmd /C wscript.exe D:\pamtest\myload.vbs', 0, true );
var_dump($obj->Run);
} else {
echo 'can not create wshell object';
} // end if
$obj = null;
//$this->load->view('goodPush');
} // end saveToPM function
We have enabled DCon in the php.ini file and used dcomcnfg to enable permissions for the user.
I borrowed the code from http://www.sitepoint.com/forums/showthread.php?505709-run-a-vbs-from-php.
The screen echos "Code executed" but the vbscript does not run.
We have been fighting with this for a while so any help is GREATLY appreciated.
It's a bit messy. PHP calls WScript.Shell.Run which will call cmd (with /c - i.e terminate cmd.exe when it's done its thing) which will call cscript.exe to run and interpret a .vbs. As you can see quite a few things that have to go right! :)
What if you 'wait' for the WScript.Shell.Run call to end (your $wait variable) before continuing execution of the wsh script which will in turn allow PHP to continue execution etc?
Since you're not waiting for the call to finish, PHP thinks its all good and continues onto the next line (interpreted language).
Also, maybe have the .vbs create an empty text file? Just so you have an indication that it has actually run.
Just take a step back, have a beer and it'll come to you! Gogo troubleshoot!
And - http://ss64.com/vb/run.html
If bWaitOnReturn is set to TRUE, the Run method returns any error code returned by the application.
I've tested your code with a stand-alone PHP script (without Codeigniter) on a Windows XP machine, with the PHP 5.4.4 built-in web server, and I've noticed that the vbscript gets executed, but PHP dies (the event viewer shows a generic "Application Error" with ID 1000).
However I've also discovered that removing the "cmd /C" from the command string solves the problem.
Here is the simple script that I've used for my test:
<?php
$obj = new COM('WScript.Shell');
if (is_object($obj)) {
//$obj->Run('cmd /C wscript.exe test.vbs', 0, true); // This does'nt work
$obj->Run('wscript.exe test.vbs', 0, true); // This works
var_dump($obj->Run);
} else {
echo 'can not create wshell object';
}
$obj = null;
?>
And this is my simple "test.vbs" script:
WScript.Echo "vbscript is running"
Another solution that seems to be working (at least on my platform) is the "system" call:
system('wscript.exe test.vbs');
Unfortunately I don't have a 64-bit IIS system to test with, so I can't really say if there are specific problems on this platform, but I hope this helps.

Categories