PHP Variables and Redirects...

by 3 replies
4
I am working on a php app that interacts with Twitter profile images. In the Twitter API, you can call a profile image by using:

http://api.twitter.com/1/users/profile_image/USERNAME

That will redirect to the actual image url, something like:
http://a1.twimg.com/profile_images/6...-bw_normal.png

What I need to do is somehow give my script the first url (http://api.twitter.com/1/users/profile_image/USERNAME) and then return and save the redirected url to a variable.

Like $firstimage = http://a1.twimg.com/profile_images/6...-bw_normal.png

and then I need to somehow get $realimage = http://a1.twimg.com/profile_images/6...-bw_normal.png

How can I tell my script to get the *real* url once I give it $firstimage?

Any suggestions would be much appreciated!
#programming #php #redirects #variables
  • You might have a look at PHP's get_headers function.

    Run this code and see what it does. I think the get_headers function might have what you're looking for.


    Actually, forget the code below. The forum's software is wonky and it's removing variable names. I saved the sample code over at Coderun studio. You can see the code there, and click "Run" if you want to run it. http://www.coderun.com/ide/?w=tKQinCobZkCJ0zDmKZ-Xew

    PHP Code:
    <?php
     
    'http://api.twitter.com/1/users/profile_image/USERNAME';

     = 
    get_headers(,1);


    echo 
    '<h3>Here\'s all the response headers in an array</h3>';
    echo 
    '<pre>';
    print_r();
    echo 
    '</pre>';

    echo 
    '<h3>And here is the location of the image</h3>';
     = ;
    echo ;
    echo 
    '<img src="'..'" />';
    ?>
    • [ 1 ] Thanks
    • [1] reply
    • That worked PERFECTLY thank you so much! I've gotta go research get_headers and see exactly what it's doing. Very cool.
      • [1] reply

Next Topics on Trending Feed