Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 2nd, 2008, 8:07 PM   #1
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 403
Rep Power: 3 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Soap

The site I use has url wrappers and functions like fsockopen all disabled. However, the headers function is allowed. What I'd like to do is use SOAP in order to send information to the site so that I can do certain things from other sites. My confusion however lies in that is the message contained in the XML structure of SOAP part of the header, or is it the html page itself? I've been reading examples and such and went to the w3 page but this concept eludes me, so I'm asking here in the hope someone knows. If it is part of the header, could someone show me a brief php example of a simple SOAP request or perhaps a link to a tutorial they've used which they found helpful. I'd like to do so without implementing an external library.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Jan 2nd, 2008, 8:34 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: Soap

Sorry. I don't quite understand what you mean by one of the first things you said:

Quote:
However, the headers function is allowed.
How do you plan on using the header function to send information to another site?

Or are you just talking about the class "SoapHeader" in the SOAP extention? And is that the only class available for use with PHP on the server?
Sane is offline   Reply With Quote
Old Jan 2nd, 2008, 8:42 PM   #3
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 403
Rep Power: 3 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Re: Soap

Sorry about that Sane, it's a typo I meant to say the header function. And yes I would like to retrieve info from another site by sending the request via the header function and then using the get_headers to retrieve the results. Assuming that is possible of course, that's why I'm saying I don't fully understand SOAP. Doesn't it solely involve HTTP headers?
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Jan 2nd, 2008, 9:43 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: Soap

You can't use the header function to send data. The header function changes the header that the client gets from the request. But if you had two servers that you both had control over, you might be able to fake communication by using get_headers to send a request, and header to send a reply. This is just a thought of mine.

http://website_client.com/client.php
php Syntax (Toggle Plain Text)
  1. // Make A Request With get_headers to http://website_server.com
  2. $response = get_headers('http://website_server.com/server.php', 1);
  3.  
  4. // Show Result
  5. echo $response['Result'];

http://website_server.com/server.php
php Syntax (Toggle Plain Text)
  1. // Fake A Response With header Back To The Client
  2. header('Result: Hello World');
  3.  
  4. // The message that will be seen if viewed by a web browser.
  5. echo 'This Page Is Not To Be Accessed Directly. Bye.';

I'm not entirely sure if that would work, but it looks like it should...

And of course, none of this has anything to do with SOAP...

Edit: Okay. I just tried it out for fun. It works perfectly. So you could use that for a cheap way to get around the lack of the socket function. If your hosting actually allows you to use "get_headers". Here it is if you want to see: Client Page | Server Page. And I apologize in advance if I've gone off on a wild tangent that's completely irrelevant to your requirements...

Last edited by Sane; Jan 2nd, 2008 at 10:02 PM.
Sane is offline   Reply With Quote
Old Jan 3rd, 2008, 10:55 AM   #5
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 403
Rep Power: 3 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Re: Soap

Nope, that's actually perfect. I just thought that what you just did was actually what SOAP did, but I guess not lol. Are there any special rules regarding characters that I should omit from headers and such? Like no asterisks or something to that effect?
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Jan 3rd, 2008, 11:00 AM   #6
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: Soap

SOAP probably does something different, but I think a simple hack like this is easier than concerning yourself with creating a SOAP client and server. I've never heard of SOAP before, but it seems like a hassle if you only need to do something really simple like transfer a few values back and forth.

You have a good question about the header. All I'd recommend is that you should experiment. I will hypothesize that you can put as much information as you want in the header, as long as the information does not contain CRLF ("\r\n"), which ends the current header attribute. Experiment and see.
Sane is offline   Reply With Quote
Old Jan 3rd, 2008, 4:35 PM   #7
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 403
Rep Power: 3 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Re: Soap

Well this is what I ended up doing:
client.php (running wherever)
<?php
echo '<pre>';
print_r(parsePILgrim('http://redpando.110mb.com/remote.php'));
print_r(parsePILgrim('http://redpando.110mb.com/remote.php?procedure=geoLocate'));
print_r(parsePILgrim('http://redpando.110mb.com/remote.php?procedure=geoLoce'));
print_r(parsePILgrim('http://redpando.110mb.com/remote.php?procedure=geoLocate&param_0=' . $_SERVER['REMOTE_ADDR']));
echo '</pre>';

function parsePILgrim($url){
	if(false !== $request = get_headers($url, 1)){
		$statusCode = intval(substr(reset($request), strpos(reset($request), ' ') + 1, 3));
		if(isset($request['PILgrim'])){
			$request = unserialize($request['PILgrim']);
			foreach($request as $keys => $values){
				if(isset($values)){
					$request[$keys] = rawurldecode($values);
				}
			}
			return $request;
		}else{
			return !trigger_error($statusCode, E_USER_NOTICE);
		}
	}else{
		return !trigger_error('Request failed.', E_USER_NOTICE);
	}
}
?>
And then:
remote.php (running elsewhere)
<?php
if(isset($_GET['procedure'])){
	if(!strcmp($_GET['procedure'], 'geoLocate')){
		if(isset($_GET['param_0'])){
			if(ip2long($_GET['param_0']) === false){
				header("HTTP/1.1 405 Method Not Allowed");
			}else{
				$geoData = geoLocate('http://api.hostip.info/?' . $_GET['param_0']);
				if($geoData === false){
					header("HTTP/1.1 503 Service Unavailable");
				}else{
					header("PILgrim: " . serialize($geoData));
				}
			}
		}else{
			header("HTTP/1.1 405 Method Not Allowed");
		}
	}else{
		header("HTTP/1.1 400 Bad Request");
	}
}else{
	header("HTTP/1.1 400 Bad Request");
}

function geoLocate($url){
	// Standard way
	//$xmlString = @file_get_contents($url);

	// CURL way
	$ch = curl_init();
	$timeout = 0; // set to zero for no timeout
	curl_setopt ($ch, CURLOPT_URL, $url);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	$xmlString = @curl_exec($ch);
	$mimeType = strtolower(curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
	$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	$curlErr = curl_error($ch);
	curl_close($ch);

	if($httpCode !== 200){
		return $httpCode;
	}elseif($xmlString === false || strpos($mimeType, 'xml') === false || $curlErr != ''){
	//if($xmlString === false || strpos($xmlString, '<?xml') !== 0){
		return false;
	}else{
		$parser = xml_parser_create();
		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
		xml_parse_into_struct($parser, $xmlString, $vals);
		xml_parser_free($parser);
		$xmlString = array();
		$parser = array();
		for($i = 0; $i < count($vals) - 1; $i++){
			if(isset($vals[$i]['value'])){
				$xmlString[$vals[$i]['tag']] = $vals[$i]['value'];
			}
		}
		$parser['location'] = rawurlencode(strval($xmlString['gml:name']));
		$parser['country'] = rawurlencode(strval($xmlString['countryName']));
		if(isset($xmlString['gml:coordinates'])){
			$parser['longitude'] = rawurlencode(floatval(array_shift(explode(',', $xmlString['gml:coordinates']))));
			$parser['latitude'] = rawurlencode(floatval(array_pop(explode(',', $xmlString['gml:coordinates']))));
		}else{
			$parser['longitude'] = null;
			$parser['latitude'] = null;
		}
		return $parser;
	}
}
?>
So now basically at the page http://redpando.110mb.com/remote.php I have a remote procedure that can be invoked from another page and return data to that page. It functions by making a GET request via the URL so if you wanted to use the geoLocate function in order to determine the geoLocation of an ip you would input something like this http://redpando.110mb.com/remote.php?procedure=geoLocate&param_0=127.0.0.1 The bolded area is what controls the function you're calling and the parameters being passed to it. It will generate a header line of PILgrim: some PHP serialized value in response to the request.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Jan 3rd, 2008, 5:18 PM   #8
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: Soap

As long as it works.
Sane is offline   Reply With Quote
Old Jan 3rd, 2008, 6:08 PM   #9
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 403
Rep Power: 3 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Re: Soap

-_- my server doesn't support get_headers because it isn't a PHP 5 server lol that sucks. Any way to get the headers in PHP 4?
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Jan 3rd, 2008, 6:26 PM   #10
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: Soap

Yikes. Always test first bud.

I'm not quite sure. So have you tried using cURL?

And maybe someone else knows a hack you could use. If not, I could perhaps helps you decipher the SOAP documentation for PHP.
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
connect to a ssl-webservice with soap ken q C++ 3 May 5th, 2006 8:39 AM
perl, SOAP and C# allenmpcx Perl 0 Mar 25th, 2006 3:46 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:14 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC