phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP Security: Requesting a Protected Document using HTTP Authentication

Tag: security, login, authentication, HTTP authentication   Category: PHP Security
post: 27 Feb 2008 read: 248


PHP Security HTTP Authentication Step By Step Tutorial - Part 2: We have created a protected document at here. In this post, we will try to open that page from other page. We must pass HTTP Authentication on that page.

You can use like this:


<?php
    //open socket
    if(!($fp = fsockopen("localhost", 80)))
    {
        print("Couldn't open socket!<br>\n");
        exit;
    }
    //make request for document
    fputs($fp, "HEAD /test/phpsecurity/protecthttp.php HTTP/1.0\r\n");

    //send username and password
    fputs($fp, "Authorization: Basic " .
        base64_encode("mia:secret") .
        "\r\n");

    //end request
    fputs($fp, "\r\n");

    //dump response from server
    fpassthru($fp);
?>

Try to change username and password at line 13, like:


base64_encode("youyou:secret")

May be you get message like this:


HTTP/1.1 401 Unauthorized Date: Wed, 27 Feb 2008 23:43:32
Apache/2.0.59 (Win32) PHP/4.4.7 X-Powered-By: 
PHP/4.4.7 WWW-Authenticate: Basic realm="PHPEveryDay's
Protected Area" Connection: close Content-Type: text/html 



| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
CAPTCHA - part 3 : "Are you human or ....?" (Build Your CAPTCHA)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting