i work with token (COM Object) , in java Script all things is okay . my problem is creating a object from it in php.
this is the code :
try {
// flag 1
$verifier = new COM("pkiactivex.Verifier") or die("Couldn't create the COM Component");
// flag 2
}
catch(com_exception $e)
{
//flag 3
}
first i should say this code work in another local system in wampp and i have xampp and i don't think it's because of xampp or wampp but i think maybe a module is missing. about code in my system code run until flag 1 and even its don't go to exception and flag 3 it's go no where , even i see a blank page with no error !!
i know it's not a php error and i put the code just for more detail!
Related
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.
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.
I am using phpseclib in my project. I have installed it and am testing it using the following piece of code which is similar to the example here.
Updated Code:
1 require("Net/SSH2.php");
2
3 if (!class_exists('Net_SSH2')) die("Class Net_SSH2 doesn't exist!");
4
5 $ssh = new Net_SSH2('***'); // the host IP address
6
7 if (!method_exists($ssh, 'Net_SSH2')) die("Net_SSH2 class doesn't have Net_SSH2 method!");
8
9 if (!$ssh->login('***', '***')) { // (verified) username and password
10 echo "LOG: " . $ssh->getLog() . "<br>";
11 exit('Login failed!');
12 }
Code Update 2:
1 require("Net/SSH2.php");
2
3 define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
4
5 if (!class_exists('Net_SSH2')) die("Class Net_SSH2 doesn't exist!");
6
7 $ssh = new Net_SSH2('***'); // the host IP address
8
9 if (!method_exists($ssh, 'Net_SSH2')) die("Net_SSH2 class doesn't have Net_SSH2 method!");
10
11 if (!$ssh->login('***', '***')) { // (verified) username and password
12 echo "LOG: " . $ssh->getLog() . "<br>";
13 echo "ALL ERRORS: ";
14 print_r($ssh->getErrors());
15 echo "<br>LAST ERROR: " . $ssh->getLastError() . "<br>";
16 exit('Login failed!');
17 }
It exits at line # 16. getLog() gives nothing so it is hard to know where the problem is. I had the login credentials tested using PuTTY. It is not able to login to other servers either. I am not able to understand what is causing the problem.
Any help would be highly appreciated!
Net_SSH2 is not a function, this is a class and constructor within this class.
So 3rd line should be
if (!class_exists('Net_SSH2')) die("Class Net_SSH2 doesn't exist!");
If you wanna check further if Net_SSH2 method exists in class Net_SSH2 after line 5 you can add this:
if (!method_exists($ssh, 'Net_SSH2')) die("Net_SSH2 class doesn't have Net_SSH2 method");
If you hit the "Enable Logging" button on the link you provided you'll see that the following is done right after Net/SSH2.php is included:
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
Try that.
Try doing this at the top of your PHP script:
error_reporting(E_USER_NOTICE);
Setting error_reporting to 0 suppresses user_error so it's quite possible your PHP setup is just suppressing the error. eg.
error_reporting(E_USER_NOTICE);
user_error('zzzz', E_USER_NOTICE);
vs.
error_reporting(0);
user_error('zzzz', E_USER_NOTICE);
Of course you could change your line 3 to:
if( !class_exists('Net_SSH2')...
But I would suggest you throw in some Exception handling. When using the PHPSecLib, I had nothing but issues, so I created this SSH2 Class which does require the PHP SSH2 Extension to be installed.
You should try calling: getLog() to find out why it's failing.
echo $ssh->getLog();
I ended up hosting my code on the server (server B) that I was trying to connect. The same code worked in the opposite direction (I could connect to the server A where my code previously was)! I ended up concluding that the server A has environmental issues.
I appreciate those were helping me here!
Given the latest comments, I assume your code exists at line 8 (where the Net_SSH2() object is instantiated)...
I just had a very similar issue where, once deployed, include() would work but check_exists() and instantiating a new Net_SSH2 object would fail... But parsing my php file (before deployment) with the php command line tool would work fine...
So the problem was on the server (Apache in my case): the directory where phpseclib was installed had permissions set so that I could not even cd to it.
As it happened, my hoem made deploying script was simply copying the files on the server and setting odd permissions so that the SSH2.php was not accessible.
Perhaps you have a similar problem here?
I am making a php/c# console app/c# soap service and I have created many functions within the web service, but I am unable to call one of them.
The function I am calling is a function which gets a string value from the database. The call works fine on Windows (using localhost) but when putting it onto a Linux server running under mono I get an exception stating the following:
Function ("getLastResetTime") is not a valid method for this service
The strange this is though, from the Linux server I can access the test form by going to asmx file and run the getLastResetTime function and it returns what is expected, it just seems to be the PHP that can't make the call.
Below is the code that I am using in PHP to call the script
function getLastResetTime()
{
include ("../../config.php");
include ("../../includes/get-settings.php");
include ("../../includes/general.php");
try
{
$client = new SoapClient("http://192.168.1.74/EmailServer/EmailSoapService/EmailSoapService.asmx?WSDL", array("trace" => 1, "exception" => 0));
$result = $client->__soapCall("getLastResetTime", array());
echo "Last Reset: " . $result->getLastResetTimeResult;
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
The screenshot below proves that the web method is working under Mono and what it returns
Below is the code of the web service function
[WebMethod(Description = "Gets the time the Email Server last reset")]
public string getLastResetTime()
{
SoapHandler soapHandler = new SoapHandler();
return soapHandler.getLastResetTime();
}
and below is the code that the web service calls
public string getLastResetTime()
{
try
{
using (ConnectDb db = new ConnectDb(appSettings))
{
string query = "SELECT * FROM settings";
using (MySqlCommand cmd = new MySqlCommand(query, db.conn))
{
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
if (reader.GetString("setting") == "app_lastRestart")
{
return reader.GetString("value");
}
}
}
}
}
return "N/A";
}
catch (MySqlException ex)
{
return ex.Message;
}
}
I don't understand why this isn't working, I'm guessing I've probably missing something really simple but can't find it.
Thanks for any help you can provide.
I've just found out the reason, but I don't understand why this doesn't affect the methods.
Basically, I was setting the WSDL to be the IP Address of the server (even though it was local to the server) so I was putting http://192.168.1.74/MySoapService.asmx but if I change it to http://localhost/MySoapService.asmx it works fine.
Why would I need to make it localhost instead of IP address for these services to work.
Is it because I am running several soap requests one after the other so the browser is stopping it, I did notice while I was trying to work out the problem, that Chrome was stating that it was throttling, if this is the issue then I would have thought the connection would time out, not say that the service is invalid.
UPDATE
I've now found out why changing the url from the IP to localhost fixed the issue, I realised as another function started having the same problem and later realised that php by default caches the wsdl, if this option is disabled in the php.ini file and restart the apache server, it then works fine. Probably quite useful in a production environment but a bit of a pain when development.
I'm trying to connect to an Oracle DB which is currently offline. When it's online it's not a problem, however, now that it's offline my program is getting hung up on the $connection = oci_connect() line and timing out. How do I simply check the connectio and bail out if it's not there?
Try this (fill in your ip and port):
if ( #fsockopen($db_ip,$db_port ) ) {
//connect to database
} else {
// didn't work
}
This gives you both a manual error, plus will return the actual error.
$connection = oci_connect() or die("Critical Error: Could not connect to database.\n\n". oci_error());
Make sure to test this as hopefully the Oracle error doesn't do something stupid like return the connection string (with your DB password) but I wouldn't assume until you see for yourself.
You could select null from dual.
OK, now I see what your asking, I think.
You want to know how to tell if a database is up before you connect to it?
You can use TNSPING to see if a database is up... ok, maybe that's not 100% accurate but it's a good indicator. go to a command prompt and type TNSPING and hit enter. So then you have to figure out how to call a command line tool from PHP.
Here is what I do in ASP.NET
Dim OracleConn As New OracleConnection(YOUR CONNECTION STRING HERE)
Try
OracleConn.Open()
OracleConn.Close()
Catch ex As Exception
Session("ErrorMessage") = "OracleConn: " & ex.Message
Response.Redirect("AccessDenied.aspx")
End Try
It doesnt necessarily say the DB is offline, but an exception will occur if the connection cannot be opened