Forum Moderators: coopster

Message Too Old, No Replies

Better error handling with PHP?

Using HTTP_REFERER to keep the prospective clients interested...

         

mipapage

12:02 am on Nov 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's the scoop.
I've modified a PHP real estate script that seems to be kicking butt in the search engines (Thank you WebmasterWorld!) - problem is that when the clients sell a place, the listing is deleted from the site, but the page for that listing stays in the SE's until they update - so people may get a search result for a listing-page that no longer exists - Hello 404!

I was hoping to use the http_referer data from the inbound url, and if it was from a search engine, use the terms that they input to provide alternative listings based on what currently exists in the database.

Theory
I've seen this done, so I know it can be, but now to figure out how.

  1. Get the referer: If it contains a search engine name then go ahead.
  2. Parse the url to get an array.
  3. Split the array[query] portion of the parsed URL based on Ampersand.
  4. This gets me an array that will contain, among other things, a 'q=search+terms' or 'p=search+terms' value.

This is the part where I break down.

What I think I need to do
I need to select the value in the array that contains the 'p=' or 'q=' (for example), and then trim off that bit and split the rest using '+'.

Thing is, I don't know how to select the value from the array, as it doesn't seem to always be in the same place... Any ideas?



Code Example:
$urlarray =
parse_url ("http://search.yahoo.com/search?
p=search+terms&ei=UTF-8&fr=fp-tab-web-
t&n=20&fl=0&x=wrt");

print($urlarray[query]); gets me:
p=alicante+airport&ei=UTF-8&fr=fp-tab-web-t&n=20&fl=0&x=wrt

And print_r(split("&",$urlarray[query]); gets me:
Array ( [0] => p=search+terms [1] => ei=UTF-8
[2] => fr=fp-tab-web-t [3] => n=20 [4] => fl=0 [5] =>
x=wrt )

That p=search+terms is what I need to get at.

hakre

12:50 am on Nov 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi mipapage,

take a look at the parse_str [php.net] function. here you go with ease:

parse_str($urlarray['query'],$urlqueryvars);

you'll find the value of q in

$urlqueryvars['q']
then.

hint: you often can get usefull tips quickly by using the online documentation on php.net. just use php.net/function-name and read the comments by others there.

- hakre

mipapage

8:40 am on Nov 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the help hakre!

hint: you often can get usefull tips quickly by using the online documentation on php.net. just use php.net/function-name and read the comments by others there.

I do use this quite a bit, but my inexperience often gets me searching around for the right function - this and that there are always >1 way to do something sometimes gets me going in circles... or the wrong direction altogether!



Whohoo! 600 posts!

hakre

8:47 am on Nov 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



there are always >1 way to do something

fairly true. and on webmasterworld you'll find another thousand ways to do ;)