WordPress Plugin Development: How do I retrieve the destination url of a redirected page with wp_remote_head()?
-
The following function returns the url of a redirected page. function get_destination_url_curl( $url ) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $a = curl_exec($ch); curl_close($ch); if (preg_match('#Location: (.*)#', $a, $r)) return trim($r[1]); } I'm wondering if the WordPress http://codex.wordpress.org/HTTP_API can handle it. I tried the following code but the returned value of array[headers][location] is always empty. $args = array( 'redirection' => 0, ); $array_response = wp_remote_head( $url, $args ); echo '<pre>' . print_r( $array_response, true ) . '</pre>'
-
Answer:
wp_remote_head() should return a 'location' index in the resulting array... $result = wp_remote_head( $your_url, $your_args ); echo $result['headers']['location'];
Russell Heimlich at Quora Visit the source
Related Q & A:
- How will the search rank get impacted if i move my mobile website to a single page application?Best solution by Webmasters
- How can I retrieve a deleted pic/video from my digital camera?Best solution by easeus.com
- How can I retrieve my contacts that I had with a previous yahoo account?Best solution by answers.yahoo.com
- How can I retrieve a conversation?Best solution by Stack Overflow
- How can I get AT&T Yahoo as a home page?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.