DISQUS

Md Emran Hasan (phpfour): HTTP Class for PHP (supports both cURL and fsockopen)

  • Omi Azad · 1 year ago
    You can add this function in Orchid framework. :)
  • Md Emran Hasan (phpfour) · 1 year ago
    Yeah Omi bhai - i've already planned that :) Just not been able to log into the SVN lately :(
  • masud · 1 year ago
    Great job Emran vai. Finally you released this. :)
    yea its a good idea if you add this to orchid framework. :)

    cool man :)
  • H2 · 1 year ago
    Well done Batman! A very good one. I was thinking that we need such a class library for orchid. Can I please add your class with default distribution?

    You are doing excellent. Keep up the good work. Godspeed.
  • Md Emran Hasan (phpfour) · 1 year ago
    Thanks Hasin. And yes, i would be honored if this is added to orchid.
  • Jahedur Rahman · 1 year ago
    Wow, It's a nice theme. Tobe menu gula dekhte ekto asubidha hocche r ki :)
  • Anis uddin Ahmad · 1 year ago
    Simply GENIUS!
    Excellent structure, easy to use and ???????? documentation.
  • Jack · 1 year ago
    Thanks for the code. I found it in the Code Igniter forums. I turned it into a library for use in my most recent web app.
  • Md Emran Hasan (phpfour) · 1 year ago
    @jack: Great to know that it came to help you exactly in the manner i expected it would. Great to know that you're using it in your project :)
  • tapos · 1 year ago
    cool work.
  • Andy Gelox · 1 year ago
    Thx for this awesome class. How to make it aouto detect for curl or dsockopen ?
  • Md Emran Hasan (phpfour) · 1 year ago
    @Andy Gelox: You're welcome. The class tries to use cURL by default, but if cURL is not installed, it automatically falls back to fsockopen. And you can specify by yourself in case you need to. Cheers!
  • Richard · 1 year ago
    When use the class ,I notice
    the cURL require a website need longer time then fsockect.is it?
  • H-BES · 1 year ago
    Hi,

    with allow redirect set to true if i call a page with status code 302 i can't read the headers of destination page, i read only the headers of first page.

    it's normal?

    can you help me?

    Thanks

    ciao
    riccardo
  • Brainbug · 1 year ago
    Thanks for sharing the class.

    It is quite helpful in php4 and php5. Love how it degrades automatically if there is no CURL. Have you though of supporting stream wrappers?
  • Vince · 1 year ago
    It seems that fsockopen method doesn't follow redirects.
  • Md Emran Hasan (phpfour) · 1 year ago
    Well, it should follow redirects with or without cURL. I will have a look
    into it and will update the source if needed. Thanks
  • Eydun · 11 months ago
    Is it possible with this class to post data, so they can be fetch on the other side with: file_get_contents("php://input")?
  • Md Emran Hasan (phpfour) · 11 months ago
    Yes, of course !
  • pwb · 10 months ago
    What's the point of cURL if fsockopen works?
  • Md Emran Hasan (phpfour) · 8 months ago
    The library supports both, so it's the choice of the dev :)
  • Rob · 9 months ago
    Could you please show me an example of the usage of cookies inside this class?
  • Md Emran Hasan (phpfour) · 8 months ago
    Yes, it's similar to how you add a param:
    $http->addCookie('logged_in_user' , '747');
  • David Kierznowski · 9 months ago
    Any reason the redirects on fsockopen route don't support 301 redirects?

    --snip--
    if ($this->status == '302' && $this->redirect == TRUE)
    --snip--
  • Md Emran Hasan (phpfour) · 8 months ago
    Fixed. Thanks for noticing.
  • Dean · 6 months ago
    Thanks for making this useful class available. I was wondering if there's a way to download a zip file using this utility - to be unzipped later.
  • sue · 5 months ago
    Hi Emran,

    Thanks for this class. It definetly makes code simple. Please see my code below(just used your example with little tweaks).

    I have couple of questions:

    1) We have special chars in password. Can i use it directly.
    2) We have SSO authentication. After authenticating it will forward to index.jsp page. When I use the below code, even though I specify userId/pswd, it is not authenticating. It is stopping at the login page. Can you please guide me how to come over this. Thanks.

    $http = new Http();
    $http->useCurl(false);
    $http->setMethod('GET');
    $http->addParam('user_name', 'test.id');
    $http->addParam('password', 'test!!pwd');
    $http->followRedirects(true);
    //$http->setReferrer('https://www.test.com/suite/portal/index.jsp');
    $http->execute('https://www.test.com/suite/portal/index.jsp');

    echo ($http->error) ? $http->error : $http->result;
  • Md Emran Hasan (phpfour) · 2 months ago
    Thanks for your comment. Special character on password should work okay as I've done so before. Regarding your login issue, I'm afraid it needs to be inspected more closely. Email me if you think you need my help on this.
  • bill · 4 months ago
    That is one fine piece of code. I am very new to PHP and that will make my life so much simpler. I just have one question, How do i go about using proxies in it? Sorry if it is right in front of me but I have only been trying my hand a PHP for a few weeks now.
  • Md Emran Hasan (phpfour) · 2 months ago
    Thanks for your comment. Unfortunately, proxies have not been implemented yet. Hope to add soon.