How to access PHP Through URL to get a new URL [call Baidu Map] I want to perform a navigation on my mobile phone
If the URL address of the current navigation is entered into the IE address bar can be accessed normally: http://api.map.baidu.com/direction? Origin = latlng: 24.481428, 118.124813 | name: Test start point & destination = latlng: 24.503361, 118.139877 | name: Test end point & mode = driving & region = Xiamen & output = html
After the input, press enter to find that the address is changed:
Http://map.baidu.com /? L = & s = nav % 26sn % 3D1% 24% 24% 24% 2C2794316. 21% 24% 24% E6 % B5 % 8B % E8 % AF % 95% E8 % B5 % B7 % E7 % 82% B9 % 24% 24% 24% 24% 24% 26en % 3D1% 24% 24% 24% 24% 2C2796984. 18% 24% 24% E6 % B5 % 8B % E8 % AF % 95% E7 % BB % 88% E7 % 82% B9 % 24% 24% 24% 24% 24% 26sc % 3D194% 26ec % 3D194
I want to know how to use PHP to obtain a new URL based on the original URL after the request? Thank you.
Reply to discussion (solution)
The reason for transcoding is that it contains Chinese characters. I found that the IPHONE navigation page cannot be opened and is blank.
However, if a new URL is obtained after a URL request is sent, you can enable the Baidu map normally by configuring it.
So I want to write a function to handle this problem. thank you.
Original? Is the url of http://api.map.baidu.com/direction? Origin = latlng: 24.481428, 118.124813 | name: Test start point & destination = latlng: 24.503361, 118.139877 | name: Test end point & mode = driving & region = Xiamen & output = html
The new url is http://map.baidu.com /? L = & s = nav % 26sn % 3D1% 24% 24% 24% 2C2794316. 21% 24% 24% E6 % B5 % 8B % E8 % AF % 95% E8 % B5 % B7 % E7 % 82% B9 % 24% 24% 24% 24% 24% 26en % 3D1% 24% 24% 24% 24% 2C2796984. 18% 24% 24% E6 % B5 % 8B % E8 % AF % 95% E7 % BB % 88% E7 % 82% B9 % 24% 24% 24% 24% 24% 26sc % 3D194% 26ec % 3D194
Can I use a new url? ,? No ,???
So you want to get the root ?? Url? Get the new url and then use it?
Original? Is the url of http://api.map.baidu.com/direction? Origin = latlng: 24.481428, 118.124813 | name: Test start point & destination = latlng: 24.503361, 118.139877 | name: Test end point & mode = driving & region = Xiamen & output = html
The new url is http://map.baidu.com /? L = & s = nav % 26sn % 3D1% 24% 24% 24% 2C2794316. 21% 24% 24% E6 % B5 % 8B % E8 % AF % 95% E8 % B5 % B7 % E7 % 82% B9 % 24% 24% 24% 24% 24% 26en % 3D1% 24% 24% 24% 24% 2C2796984. 18% 24% 24% E6 % B5 % 8B % E8 % AF % 95% E7 % BB % 88% E7 % 82% B9 % 24% 24% 24% 24% 24% 26sc % 3D194% 26ec % 3D194
Can I use a new url? ,? No ,???
So you want to get the root ?? Url? Get the new url and then use it?
This is what it means, brother. I am like using an old URL to generate a new URL.
Thank you.
Thank you for your reply.
However, I am using Sina SAE, which prompts me:
Warning: get_headers () has been disabled for security reasons in test. php on line 7
Can get_headers () be replaced by another method? Thank you.
Try.
$ Url = 'http: // api.map.baidu.com/direction? Origin = latlng: 24.481428, 118.124813 | name: Test start point & destination = latlng: 24.503361, 118.139877 | name: Test end point & mode = driving & region = Xiamen & output = html '; $ newurl = getMapUrl ($ url); echo $ newurl; function getMapUrl ($ url) {file_get_contents ($ url); $ result = $ http_response_header; if ($ result) {foreach ($ result as $ val) {if (substr ($ val, 0,10) = 'Location: ') {return str_replace ('Location :','', $ val) ;}} return '';}
Disabled functions:
Php_real_logo_guid
Php_egg_logo_guid
Readlink
Linkinfo
Symlink
Link
Set_file_buffer
Exec
System
Escapeshellcmd
Escapeshellarg
Passthru
Shell_exec
Proc_open
Proc_close
Proc_terminate
Proc_get_status
Proc_nice
Getmyuid
Getmygid
Getmyinode
Putenv
Getopt
Sys_getloadavg
Getrusage
Get_current_user
Magic_quotes_runtime
Set_magic_quotes_runtime
Import_request_variables
Debug_zval_dump
Ini_alter
Dl
Pclose
Popen
Stream_socket_client
Stream_socket_server
Stream_socket_accept
Stream_socket_pair
Stream_get_transports
Stream_wrapper_restore
Get_headers
Mail
Mb_send_mail
Openlog
Syslog
Closelog
Apc_add
Apc_bin_dump
Apc_bin_dumpfile
Apc_bin_load
Apc_bin_loadfile
Apc_cache_info
Apc_cas
Apc_clear_cache
Apc_compile_file
Apc_dec
Apc_define_constants
Apc_delete_file
Apc_delete
Apc_exists
Apc_fetch
Apc_inc
Apc_load_constants
Apc_sma_info
Apc_store
Flock
Pfsockopen
Posix_kill
Apache_child_terminate
Apache_get_modules
Apache_get_version
Apache_getenv
Apache_lookup_uri
Apache_reset_timeout
Apache_response_headers
Apache_setenv
Virtual
Mysql_pconnect
Socket_create
Socket_create_pair
Disabled class:
SQLiteDatabase
SQLiteResult
SQLiteUnbuffered
SQLiteException
APCIterator
Urlencode?
Try.
$ Url = 'http: // api.map.baidu.com/direction? Origin = latlng: 24.481428, 118.124813 | name: Test start point & destination = latlng: 24.503361, 118.139877 | name: Test end point & mode = driving & region = Xiamen & output = html '; $ newurl = getMapUrl ($ url); echo $ newurl; function getMapUrl ($ url) {file_get_contents ($ url); $ result = $ http_response_header; if ($ result) {foreach ($ result as $ val) {if (substr ($ val, 0,10) = 'Location: ') {return str_replace ('Location :','', $ val) ;}} return '';}
Disabled functions:
Php_real_logo_guid
Php_egg_logo_guid
Readlink
Linkinfo
Symlink
Link
Set_file_buffer
Exec
System
Escapeshellcmd
Escapeshellarg
Passthru
Shell_exec
Proc_open
Proc_close
Proc_terminate
Proc_get_status
Proc_nice
Getmyuid
Getmygid
Getmyinode
Putenv
Getopt
Sys_getloadavg
Getrusage
Get_current_user
Magic_quotes_runtime
Set_magic_quotes_runtime
Import_request_variables
Debug_zval_dump
Ini_alter
Dl
Pclose
Popen
Stream_socket_client
Stream_socket_server
Stream_socket_accept
Stream_socket_pair
Stream_get_transports
Stream_wrapper_restore
Get_headers
Mail
Mb_send_mail
Openlog
Syslog
Closelog
Apc_add
Apc_bin_dump
Apc_bin_dumpfile
Apc_bin_load
Apc_bin_loadfile
Apc_cache_info
Apc_cas
Apc_clear_cache
Apc_compile_file
Apc_dec
Apc_define_constants
Apc_delete_file
Apc_delete
Apc_exists
Apc_fetch
Apc_inc
Apc_load_constants
Apc_sma_info
Apc_store
Flock
Pfsockopen
Posix_kill
Apache_child_terminate
Apache_get_modules
Apache_get_version
Apache_getenv
Apache_lookup_uri
Apache_reset_timeout
Apache_response_headers
Apache_setenv
Virtual
Mysql_pconnect
Socket_create
Socket_create_pair
Disabled class:
SQLiteDatabase
SQLiteResult
SQLiteUnbuffered
SQLiteException
APCIterator
Powerful, bro. You got 100 points. Close the post.
Thank you.
Later, I found another one and shared it by the way.
private function getHeadersNew($url){ $ch= curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); $f=curl_exec($ch); curl_close($ch); $h=explode("\n",$f); $r=array(); foreach( $h as $t){ $rr=explode(":",$t,2); if(count($rr)==2 ){ $r[$rr[0]]=trim($rr[1]);} } return $r; }