php-general Digest 12 Sep 2008 09:39:40 -0000 Issue 5677

Topics (messages 279924 through 279938):

Re: New Server Install
        279924 by: Tom Chubb

Maps / Distance / GeoCoding [php/mysql]
        279925 by: Nathan Rixham
        279926 by: Nathan Rixham

Re: Readdir() question
        279927 by: Nathan Rixham
        279928 by: Jochem Maas

Re: Why MS Won't Retire Browsers -- was: Interntet Explorer 8 beater 2
        279929 by: Sancar Saran
        279935 by: Colin Guthrie

Re: Serving pages based on user input
        279930 by: prasad

Re: Interntet Explorer 8 beater 2
        279931 by: Lester Caine

Re: Mysqli issue
        279932 by: Chris

Re: ASCII Captcha
        279933 by: Yeti

ldapsearch problems
        279934 by: Michael Fischer

Browser could not get mp3 files from http site
        279936 by: hce

Re: Google Maps Distance Between UK Postcodes
        279937 by: Colin Guthrie

Re: namespaces ... coming to a php5.3 near you.
        279938 by: Jochem Maas

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
2008/9/11 Shawn McKenzie <[EMAIL PROTECTED]>

>
>
> Tom Chubb wrote:
>
>>
>>
>> 2008/9/11 Ashley Sheridan <[EMAIL PROTECTED] <mailto:
>> [EMAIL PROTECTED]>>
>>
>>    I believe that MySQL uses a particular port when connecting over a
>>    network such as you're doing. I can't remember the exact port number,
>>    but you can Google it. Just check that there's nothing blocking this
>>    port either on your computer, the server, or the router/switch or
>>    whatever else you are using to connect the computers on the network
>>
>>
>>    Ash
>>    www.ashleysheridan.co.uk <http://www.ashleysheridan.co.uk>
>>
>>
>>    ---------- Forwarded message ----------
>>    From: Shawn McKenzie <[EMAIL PROTECTED]
>>    <mailto:[EMAIL PROTECTED]>>
>>    To: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>>    Date: Wed, 10 Sep 2008 21:31:41 -0500
>>    Subject: [PHP] Re: New Server Install
>>    Shawn McKenzie wrote:
>>
>>        Robbert van Andel wrote:
>>
>>            I am working on a new webserver running Fedora 9.  I
>>            installed php-mysql and
>>            php-mssql via yum.  When I try to connect to our mysql
>>            server using php, I
>>            get the following error: Can't connect to MySQL server on
>>            'mysqlservername'
>>            (13)
>>
>>                        Here's the weird part, I can connect to the mysql
>> database
>>            server just fine
>>            from the web server's command line so I'm pretty confident
>>            that it's not a
>>            firewall issue.  While trying to connect using PHP, I see
>>            no packets leaving
>>            the webserver.
>>                        Any thoughts?
>>
>>                        Thanks,
>>
>>            Robbert
>>
>>
>>
>>        Well, for MySQL there are multiple user perms.  In the user
>>        table you may see multiple entries for, let's say root.
>>
>>        mysql> use mysql;
>>        mysql> select host,user,password from user;
>>
>>        host        user    password
>>        *        root    *22669F8A96AC3CE42B3E5E8087893840412E035F
>>        localhost    root
>>
>>        So, root, if accessing from localhost, requires NO paswword.
>>         But root, accessing from any other host requires a password.
>>         Also, this could have more host entries, but probably not by
>>        default.
>>
>>        If your db server is on a different host from your web server,
>>        this or similar is most likely your problem.
>>
>>        -Shawn
>>
>>
>>    Or, there is no * entry (all hosts).  In which case you should add
>>    a specific entry for your web server.
>>
>>    -Shawn
>>
>>    --    PHP General Mailing List (http://www.php.net/)
>>    To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
>>    --
>>    PHP General Mailing List (http://www.php.net/)
>>    To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>> I was trying to access MySQL on a remote server from an Excel spreadsheet
>> and I think it was port 3306 but I still haven't got it working yet!
>> HTH
>>
>
> Install MyODBC and setup an ODBC connection on your PC.
>
> -Shawn
>

Did that and got an error response. I think it's the remote host but was
late Friday afternoon last week and haven't got round to trying it again.
Thanks though.
Anyway, sorry this is veering OT

--- End Message ---
--- Begin Message ---
re: an earlier thread

as promised here are some note's on geo-coding using mysql and php (and geoip and distance between points) also worth reading up on wiki about the great circle and associated content! (+openGIS)

Won't make sense to all unless you're working with spatial data - if anybody needs I also have the full ip to location databases; + the geo-cords or every dwelling place in the world (basically a mashup of all decent databases combined - about 4gb worth when rar'd)

if your a postgres coder you want be checkign out postgis and pgrouting
---------

Geo Data & Spatial

All geo columns are of type GEOMETRY sith SPATIAL indexes (see mysql 5 spatial documentation http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html); in short they are binary storage columns for geodata. (here's a handy link about it aswell: http://dev.mysql.com/tech-resources/articles/4.1/gis-with-mysql.html )

you extract data from them by using:

X(point) as lon
Y(point) as lat

or AsText(point)

in where statements you use MBRContains

some functions:

function spatialCountryFromIp($ipNumeric=false) {
        if($ipNumeric) {
                $getResultsSQL = " select
                                                                l.isocode,
                                                                l.en,
                                                                X(l.geopoint) 
as lon,
                                                                Y(l.geopoint) 
as lat
                                                        from
                                                                
geodata.spatialip_country as i
                                                        inner join
                                                                
geodata.spatialloc_country as l
                                                        ON
                                                                
MBRContains(l.geopoint,i.geopoint)
                                                        where
MBRContains(i.iprange,PointFromText('Point(0 ".($ipNumeric/10000000).")'));";
                $result = mysql_query($getResultsSQL);
                /* do what you want with data */
        }
}

public function spatialCityFromIp($ipNumeric=false, $within=1, $units='km') {

        if($ipNumeric) {
                if(strtolower(trim($units)) == 'km') {
                        $single_unit = 0.0089992800575953923686105111591073;
                }
                $offset = 1*$single_unit;
                if(is_numeric($within) && $within) {
                        $offset = $within*$single_unit;
                }
                $getResultsSQL = " select
                                                                l.cid,
                                                                l.name,
                                                                X(l.point) as 
lon,
                                                                Y(l.point) as 
lat,
                                                                l.cc,
                                                                l.pop,
                                                                ACOS(
                                                                        
SIN(Y(g.geopoint)*pi()/180)*SIN(Y(l.point)*pi()/180)
                                                                        
+COS(Y(g.geopoint)*pi()/180)*COS(Y(l.point)*pi()/180)
                                                                        
*COS((X(l.point)-X(g.geopoint))*pi()/180)
                                                                )*6372.795
                                                                as distance
                                                        from
                                                                
geodata.spatialip_city as g
                                                        inner join
                                                                
geodata.spatialloc_city as l
                                                                ON
                                                                MBRContains(
                                                                                
GeomFromText(
                                                                                
CONCAT(
                                                                                
        'POLYGON(
                                                                                
                (
                                                                                                
',X(g.geopoint)-(".$offset."),' ',Y(g.geopoint)-(".$offset."),',
                                                                                                
',X(g.geopoint)+(".$offset."),' ',Y(g.geopoint)-(".$offset."),',
                                                                                                
',X(g.geopoint)+(".$offset."),' ',Y(g.geopoint)+(".$offset."),',
                                                                                                
',X(g.geopoint)-(".$offset."),' ',Y(g.geopoint)+(".$offset."),',
                                                                                                
',X(g.geopoint)-(".$offset."),' ',Y(g.geopoint)-(".$offset."),'
                                                                                
                )
                                                                                
        )
                                                                                
'))
                                                                ,l.point)
                                                        where
MBRContains(g.iprange,PointFromText('Point(0 ".($ipNumeric/10000000).")'))
                                                        ORDER BY
                                                                distance;";
                $result = mysql_query($getResultsSQL);
                /* do something with returned data */
        } else {
                return false;
        }
}


the key to using spatial indexes is MBRContains() together with POLYGON OR POINT()

where the column has point data in it, you use a POLYGON to select info around it, this is your radius as it where, but square! the polygon goes:

        dMinLong + " " + dMinLat
        dMaxLong + " " + dMinLat
        dMaxLong + " " + dMaxLat
        dMinLong + " " + dMaxLat
        dMinLong + " " + dMinLat
        
so.. in the above spatialCityFromIp function we:

query the spatialip_city first of all, using the final where clause:
        MBRContains(g.iprange,PointFromText('Point(0 
".($ipNumeric/10000000).")'))
the iprange column is a gemotery column, that stores ip ranges as a POLYGON, think of the iprange as being stored as a box with four corners

        0 ipsi/10000000
        1 ipsi/10000000
        1 ipei/10000000
        0 ipei/10000000
        0 ipsi/10000000
where the longitude is always 1 or 0 and the latitude acually stores the iprange
(ipsi = start ip in range as numeric)
(ipei = end ip in range as numeric)
so we query the polygon to which POLYGON (iprange) the POINT (in this case a numeric ip) is in.

this returns a single row which contains the iprange and long/lat point

we then INNER JOIN the spatialloc_city table on the returned long/lat point, to find which places that point is near to do this, again we use MBRContains, but this time the stored data is a point, so we want to draw a virtual polygon and return all the points within that polygon we obviously had to calculate the dimensions of the box, we did this by finding the degree value of 1km: 0.0089992800575953923686105111591073 and multiplying it by the amount of km's we want to search within, say 15km (15*0.0089992800575953923686105111591073)

MBRContains(
                GeomFromText(
                CONCAT(
                        'POLYGON(
                                (
                                ',X(g.geopoint)-(".$offset."),' 
',Y(g.geopoint)-(".$offset."),',
                                ',X(g.geopoint)+(".$offset."),' 
',Y(g.geopoint)-(".$offset."),',
                                ',X(g.geopoint)+(".$offset."),' 
',Y(g.geopoint)+(".$offset."),',
                                ',X(g.geopoint)-(".$offset."),' 
',Y(g.geopoint)+(".$offset."),',
                                ',X(g.geopoint)-(".$offset."),' 
',Y(g.geopoint)-(".$offset."),'
                                )
                        )
                '))
,l.point)

this will be the same for your postcode/business database,
say geopoint was the long/lat of a postcode and each business had it's own long/lat assigned to it, set offset to 10 and it'll return all businesses within 10km of postcode's lat/lon

the final thing we've done is ordered by distance, by calculating the distance from the ip's point to the places point

this calculation is:
ACOS(
        SIN(g.lat*pi()/180)*SIN(Y(point)*pi()/180)
        +COS(g.lat*pi()/180)*COS(Y(point)*pi()/180)
        *COS((X(point)-g.lon)*pi()/180)
)*6372.795
as distance

you may want to read up on the "Great Circle" wikipedia has a good article on it, but basically that little string up there will calc distance as the crow flies from any two points.

those three sql statements there will cover everything you could need to do, it's just a case of putting them together how you want mate.



more reference::

to insert geo POINT into a table..
INSERT INTO table (pointcol) VALUES (
        PointFromText(CONCAT('POINT(',lon,' ',lat,')'))
        )



a really simply lookup:

select
AsText(geopoint)
from
spatialloc_country as i
where
MBRContains(i.geopoint,PointFromText('POINT(-2 54)'));

AND

select
AsText(geopoint)
from
spatialloc_city as i
where
MBRContains(i.geopoint,PointFromText('POINT(LON LAT)'));

(replace lon and lat above)

regards all

--- End Message ---
--- Begin Message ---
Nathan Rixham wrote:
re: an earlier thread

[snip]

or you may just need this bit:

distance =
ACOS( SIN(Y(g.geopoint)*pi()/180)*SIN(Y(l.point)*pi()/180) +COS(Y(g.geopoint)*pi()/180)*COS(Y(l.point)*pi()/180)
*COS((X(l.point)-X(g.geopoint))*pi()/180))*6372.795

used to calc the distance between two points on the surface of the earth accurately
--- End Message ---
--- Begin Message ---
Jochem Maas wrote:
Nathan Rixham schreef:
Stut wrote:
maybe this is into coding standards and ethics.. but this may be acceptable:
if( !defined('__DIR__') ) {
  define('__DIR__' , dirname(__FILE__));
}

however realistically you'd have to do this in every file and nto just in one include

which would give an error on second and subsequent define()s

yet if(!defined... it's already defined so won't be defined subsequent times :)

still crap though

--- End Message ---
--- Begin Message ---
Nathan Rixham schreef:
Jochem Maas wrote:
Nathan Rixham schreef:
Stut wrote:
maybe this is into coding standards and ethics.. but this may be acceptable:
if( !defined('__DIR__') ) {
  define('__DIR__' , dirname(__FILE__));
}

however realistically you'd have to do this in every file and nto just in one include

which would give an error on second and subsequent define()s

yet if(!defined... it's already defined so won't be defined subsequent times :)

my bad


still crap though


yes :-P

--- End Message ---
--- Begin Message ---
Because,

M$ earning money from Win GUI. No WinGUI no money.

From the begining, M$ try to broke web compatibilty in every way...

Sure M$ has bad records about software quality. But even ask yourself. WHY IE 
(especially 5 and 6) SO buggy even M$ standards.

M$ isn't mr nice guy and they wont get a dime from web.

They hate web and internet from begining.

M$ is anti web IT company. They are too big they are to bold (or bald) to 
accept changing market and they got too much money on 
bank to do someting very very stupid.

Like Windows VISTA.

Don't expect anything good from M$...

Regards

Sancar

--- End Message ---
--- Begin Message ---
Sancar Saran wrote:
Don't expect anything good from M$...

Oh I don't expect anything good from them, never have, never will, but that still doesn't change my point that sunset dates would probably be better for them in the long run... looking for a reason up upgrade a subborn user who wont drink the vista kool aid? Stop them surfing and get them to upgrade!

Other browsers muscling in? just make IE not suck and deploy it on older OSes.. It's not really that hard to do (or wouldn't have been if IE wasn't a critial part of the OS!).

Still not holding out much hope and there is not much point in musing over "what could have"'s, but I really do hope that future browsers have this built in (again not much hope!)

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---
--- Begin Message ---
Jochem Maas wrote:
tedd schreef:
At 10:02 PM -0700 8/23/08, Prasad Chand wrote:
Thanks for that information. But in my case I need to serve pages based on selection of US states. There are 50 of them, so generating pages dynamically would have been a nice idea.

WTF? do you have any idea why we write scripts as opposed to endless
copy/pasting of plain (X|(x)HT)ML?

and really you don't need to generate 50 pages, merely 50 URLs that
end up triggering a single script (which in turn generates output based
on the request URL).


OK late reply but just to set the record straight. I did not mean generating 50 different pages!!! I would as well do it in html if thats the case. I meant generating a single page with the desired content based on form input. As of now I am using includes to generate the page. I will be more careful with the wording next time.


Really, there are 50 of them!?!?  :-)

unofficially there are 51, well Tony Blair would like to think so.

You don't have to generate 50 pages dynamically to do it -- try this:

http://webbytedd.com/bbb/map/

That demo is done with just pure css -- no php nor javascript.
 >
Plus each one of those States can be linked to another page -- AND-- it is user friendly, validates, accessible, and SEO friendly. What more could anyone want?

a version of europe actually :-P

seriously how much time did you spend hacking that together? and
how did your eyes bleed?


If you don't know php, then I think the best way to ask a question on this list by telling us what you want to do rather than asking specific php questions trying to do something they way you think it might work.

Thanks for your comment. I was completely new to php so the questions were unrefined, now I am much more comfortable. map-navigation is a good idea but I will need to change the look and feel and I need to give it more time and then I am willing to right now. Btw, I could not download the outline of the map when i saved it as you haven't given permission to the "states" folder. I had to create the states folder and then download the outline of the us map.


no. the best thing would be to RTFM and STFW for a few years,
but hey hell will freeze over first ;-)


Cheer,

tedd



--- End Message ---
--- Begin Message ---
Jochem Maas wrote:
Colin Guthrie schreef:
Lester Caine wrote:
Jochem - You not had the problem of M$ changing default font sizes in different versions of windows? IT departments have enough problems with INSTALLING an upgrade without asking them to CHANGE the font size as well :) The complaint from THIS site was that they could not log out because the 'logout' button was hidden - selecting a size smaller font on the browser fixes the problem, but we have to add a scroll bar to the menu because "They can't change from the default settings" :(

Yeah font sizes are a pain... tip of the day: Don't put and XML preamble in if you are using XHTML and get your doctypes right. Once you do that, the font size problems are a lot easier to address.

indeed they are a pain, properly validating strict xHTML is the start of
making it manageable, other part is defining suitable style sheets that fix
the problem. plenty of eggheads offer blogs posts/articles etc that define
the issues and offer cross-browser font-size solutions.

IE font-size hell is exactly that, but there is no reason to have to pass it
on to the client ... going through M$Hell is our job ;-)

My NEW stuff addresses the problem, AND I provide free upgrades as part of the maintenance, BUT it can take several YEARS to get permission to apply those upgrades ;)

Actually this is good example of where it can be difficult to update things. I have still to get permission to switch some sites from PHP5.0.6 even though we KNOW that 5.2.6 provides speed improvements! The system is working fine for them and they do not want to break it - and yet they insist on running Windows Update in the background WHICH DOES JUST THAT - Go figure :(

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--- End Message ---
--- Begin Message ---
Jason Pruim wrote:
No political undertones in this one I promise! :)

Attempting to setup a prepared statement in php that will update a record in a mysql database using mysqli

Here is the relevant code:
    $stmt = mysqli_stmt_init($link);
mysqli_stmt_prepare($stmt, "UPDATE purl.schreur (FName, LName, email, phone, record, subscribed, date, IPAddress, Business, Address1, City, State, Zip, Coffee, Meeting, areaPlans) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

That's an insert query.

An update query is:

update table set field1=value1, field2=value2 etc where id='X';

--
Postgresql & php tutorials
http://www.designmagick.com/


--- End Message ---
--- Begin Message ---
> Not so good if you're using lynx, or if you're blind, I guess.

I often tell my clients the reasons for accessibility and usually i
get the answer "We don't have any blind customers so we don't care
about them". So much for fair play in the web.

--- End Message ---
--- Begin Message ---
hi there,

i'm having a problem regarding ldapsearch(filters).

on the console everything works fine:
<snip>
ldapsearch -bdc=xxx,dc=at -Dcn=admin,dc=xxx,dc=at -hxx.xx.xx.xx -p389 -x
-W socialSecurityNumber=xxxxxxxxxx
</snip>
with this is get a valid result, but with

but in my php script
<code>
$ldap = ldap_connect('xx.xx.xx.xx','389');
ldap_bind($ldap,'cn=admin,dc=xxx,dc=at','xxxxxx');

$filter = "(socialSecurityNumber=xxxxxxxxxx)";
$search =
ldap_search($ldap,'ou=People,dc=xxx,dc=at',filter,array("uid","ou"));
$result = ldap_get_entries($ldap,$search);
var_dump($result);

ldap_unbind($ldap);
</code>

i just get the output:
<snip>
array(1) {
  ["count"]=>
  int(0)
}
</snip>

any ideas?

lg, Michael Fischer
-- 
email: [EMAIL PROTECTED]
web: http://www.webfischer.at


--- End Message ---
--- Begin Message ---
Hi,

I have a php file audio.php to send mp3 file audio.mp3 to browsers,
the browser needs following html code to play mp3 file. I thought it
should work if I put the the audio.mp3 file in the same localtion with
the http://www.myweb.com/audio.php. But the browser could not get the
audio.mp3. I guess something is missing here, please correct me.

<embed target="audio.mp3"
.....
/>

Thank you.

Jim

--- End Message ---
--- Begin Message ---
Boyd, Todd M. wrote:
-----Original Message-----
From: tedd

Considering that my other profession is Geophysicist, I'm kind of up
on those sort of things. The Earth is an oblate spheroid and the
computation to include the curvature of the earth would be a bit more
involved.

---8<--- snip

But it's also NOT an oblate spheroid! :)

http://blogs.discovermagazine.com/badastronomy/2008/09/08/ten-things-you
-dont-know-about-the-earth/

Todd Vs. Tedd: A deathmatch separated only by one vowel! FIIIIIIGHT!!!

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---
--- Begin Message ---
Jochem Maas schreef:
has anyone here downloaded/compiled 5.3 and played with namespaces?
have you encountered any issues/problems?

so no-one? really? none of you muppets ever even smelled a namespace?

I'd like to hear from you as I've been asked to compile a reference documenting anything/everything people may have come across (so far as namespaces go), if you have some reproduce code, all
the better.

rgds,
Jochem



--- End Message ---

Reply via email to