Solved

HTTP response help!!! i got 3hrs!!! Think im gonna cry :-)

Posted on 2004-08-13
12
167 Views
Last Modified: 2010-04-06
Hi all,

    I am using a maping company to display interactive maps on my site. They offer routing and proximity searches and the way they work is that you pass information to a url and it returns a location_id or a routing_id which you then include in a applet.

The problem is i'm a newbie, i dont know how to use the HTTP response as a variable. i.e.

if i open a browser and pass the url : -

themapcompany?street=$street&city=$city ...etc

then a location_id is returned to the screen. But i need to get that information as a variable, how?

Oh yeah and i have 3hrs to do this so i'm panicing.

Thanks, Chris.
0
Comment
Question by:icb01co2
12 Comments
 
LVL 3

Expert Comment

by:alskdj80
ID: 11793376
ok, im not sure... but i think you're using an applet (if you're using jsp or php it would be alot easier)

anyways, in your applet (probably in your init() function), you can just do:
String myStreet = searchparms.get("street");
String myCity = searchparms.get("city");
... etc...

and then you can use these variables to get your location_id

(i think this is your question, if not, ive completely misunderstood)
0
 
LVL 3

Expert Comment

by:alskdj80
ID: 11793406
oh, dear, i completely forgot about the most important part, which is the function that actually does it, hahaha, whoops

ok, i'll type it out more clearly, with code.... hmm, actually, it seems that theres this exact thing online...

http://www.rgagnon.com/javadetails/java-0049.html
0
 
LVL 1

Author Comment

by:icb01co2
ID: 11793452
ok im not really descriping this clearly.

- if i opened a url i.e.

http://www.somesite.php?id=5;

and this would print to the screen the following: -

"1 | this is line one"


what i need to do is not to actually type the url into a browser but to use some php method that uses the url as an argument and returns what would be printed to the screen. i.e.

$from_url = someMethod("http://www.somesite.php?id=5");

here $from_url would equal "1 | this is line one".

Thanks, Chris.



0
 
LVL 3

Expert Comment

by:alskdj80
ID: 11793800
hmm, im still rather unclear about what you want...

what i think you need is just to get the URL address thats in the browser window and put it into a function??

anyways, to get the complete URL, just do
<?php
$url = "http://".$_SERVER["HTTP_HOST"].$_SERVER['SCRIPT_NAME' ];

//then put into function
$from_url = someMethod($url);
?>
0
 
LVL 3

Expert Comment

by:alskdj80
ID: 11793833
hmm, i forgot about your query strings... ok, ignore the prev post...

<?php
$url = "http://".$_SERVER["HTTP_HOST"].$_SERVER['SCRIPT_NAME' ].$_SERVER['QUERY_STRING'];

//then put into function
$from_url = someMethod($url);
?>

the extra "$_SERVER['QUERY_STRING']" will handle the query strings
0
 
LVL 3

Expert Comment

by:alskdj80
ID: 11793841
of course, i may be way off on what i think you want... either way, let me know, thanks!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:icb01co2
ID: 11794101
lol, erm i am probably the worse person to explain anything. But no i don't need to know how to retrive url information, i know how to do all that.

Here ill just show you: -

ive made a simple .php file called extract.php which outputs some numbers depending on what you pass to it i.e.

http://www.pitmanskills.com/extract.php?number=6

will return:

show me how you extract this number | 36
show me how you extract this number | 144

Basically i would like to know how you would get those numbers '36' and '144' and use them as .php variables by using some function that gets three response generated by my script. I think
fsockopen() is something like what i need but i dont know how to use it?

Thanks, Chris.




0
 
LVL 3

Expert Comment

by:alskdj80
ID: 11794440
oh, i see... so the map website is not your own but rather something like mapquest?... you want to send in a url and then when they display on their site something like "location_id is 123" (in html), then you want to somehow get 123?

is that what you mean?
0
 
LVL 3

Accepted Solution

by:
dufduf earned 150 total points
ID: 11794515
Is this even close?-)

<?php
$url = "http://www.pitmanskills.com/extract.php?number=6";
list($num1, $num2) = retrieve($url);
echo "num1: '$num1', num2: '$num2'\n";
print_r($numbers);

function retrieve($url) {

        $lines = file($url);
        $numbers = array();
        for ( $i = 0; $i < count($lines); $i++ ) {
                list($crap, $num) = explode("|", $lines[$i]);
                list($num, $crap) = explode("<", $num);
                if ( $num > 0 ) {
                        $numbers[] = trim($num);
                }
        }
        return $numbers;

}
?>
0
 
LVL 18

Expert Comment

by:arantius
ID: 11801262
<?
$c=curl_init("url_goes_here");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$data=curl_exec($c)
curl_close($c);
?>

will put whatever is at that url into $data
0
 
LVL 1

Expert Comment

by:kahnadex
ID: 11825672
When you make a HTTP POST to the Map website, it will always return a response that is a string.  I'm not way too familiar with PHP, but there is definitely an HTTP object included in it's API.

What you need to do is make a web request to the URL including your custom query strings and then capture the response.  The object you make the HTTP POST with should have a way to get a response or actually contain the response text itself.  From there, you can parse out what you are expecting back.

Parsing should be easy to do..  Once you have the response as a string.. Maybe the website returns you
"location_id=444533434&mapid=23232323&zoom=22"

You can split the string based on & to get these values in a string array
Array Item 1 : location_id=444533434
Array Item 2 : mapid=23232323
Array Item 3 : zoom=22

You can split each of those results based on the equals sign.  For example with item 1 above:
Array Item 1: location_id
Array Item 2: 444533434

This will work great with name/pair values.  If the response is encoded with parity or encrypted, it will of course have to be decode/decrypted.

Hope this helps
0
 
LVL 1

Author Comment

by:icb01co2
ID: 11989923
Sorry for the late response guys, but your answers were exactly what i needed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
File names with & character 6 70
Lines Not Lining Up 2 63
Adjust the position 3 50
React or Angular? 6 54
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now