tigomark Posted January 22, 2008 Share Posted January 22, 2008 Hello all, I am having problems getting a string comparison to work in my wrapper script <?php $customer = $_REQUEST['customer']; $username = $_REQUEST['username']; $password = $_REQUEST['password']; $mystring = strstr("<error ver=\"1.0\">", "</error>" ); $url = "https://$customer.mysite.net/interface.php?action=showopen&operation=showassets&format=xml&opstatus=crit&username=$username&password=$password"; function auth_curl($url){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $html = curl_exec($curl); // execute the curl command if (false == strpos($mystring, "error")){ $html = "<loginsuccess>Yes</loginsuccess>"; }else{ $html = "<loginsuccess>No</loginsuccess>"; } curl_close($curl); // close the connection return $html; // and finally, return $html } // uses the function and displays the text off the website $text = auth_curl($url); echo $text; ?> Now the output of the xml is as follows <error ver="1.0"> <action>showopen</action> <code>109</code> <message>Failed to authenticate user 'user'</message> </error> so what I am trying to do is grab everything between the error tag and if I get the error tag I want to show the <loginsuccess>No</loginsuccess> else give them access to the app. Any help would be great Link to comment https://forums.phpfreaks.com/topic/87139-solved-php-wrapper-problems/ Share on other sites More sharing options...
Nhoj Posted January 22, 2008 Share Posted January 22, 2008 With strpos comparison i'm 99.999% sure you need to check it against false with an identical comparison (===) as opposed to an equal comparison (==).. Give that a whirl and see what happens. Link to comment https://forums.phpfreaks.com/topic/87139-solved-php-wrapper-problems/#findComment-445692 Share on other sites More sharing options...
tigomark Posted January 22, 2008 Author Share Posted January 22, 2008 Thanks, I have tried it both ways and either way it does not work. doing a printf($mystring) produces no results so I am thinking that the string has been created incorrectly but I'm not sure what the right way would be. Link to comment https://forums.phpfreaks.com/topic/87139-solved-php-wrapper-problems/#findComment-445700 Share on other sites More sharing options...
tigomark Posted January 22, 2008 Author Share Posted January 22, 2008 Would it just be better to change $mysting to = the string that I want? Link to comment https://forums.phpfreaks.com/topic/87139-solved-php-wrapper-problems/#findComment-446213 Share on other sites More sharing options...
tigomark Posted January 22, 2008 Author Share Posted January 22, 2008 nope no dif other than now the printf has a value of the code change. Link to comment https://forums.phpfreaks.com/topic/87139-solved-php-wrapper-problems/#findComment-446221 Share on other sites More sharing options...
tigomark Posted January 22, 2008 Author Share Posted January 22, 2008 duh I should have been doing var_dump. $mystring is coming out as always false. Link to comment https://forums.phpfreaks.com/topic/87139-solved-php-wrapper-problems/#findComment-446230 Share on other sites More sharing options...
tigomark Posted January 22, 2008 Author Share Posted January 22, 2008 I needed to add the curl option curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); and then compare to $html instead of $mystring. Link to comment https://forums.phpfreaks.com/topic/87139-solved-php-wrapper-problems/#findComment-446250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.