An-Najah National University

Razi Alsayyed Blog

This is a blog about my experience with programming, networking and systems

 
  • Wednesday, January 21, 2009
  • Make a Post Request through PHP Script
  • Making a GET Request through PHP is very easy, you can treat the URL of the target page as a file, open it using fopen while include the parameters in the URL String:
     
    $result = file_get_contents("www.example.com?param1=value1&param2=value2");
     
    But some times GET does not work, specially when you need to communicate with other platforms "other servers" which already written and expect a POST request.
    Making a Post Request is Easy to, but it is a little tricky, because in POST requests you can not add the paramters to the end of the URL as in GET, instead you need to send them in the HTTP headers, and in order to do that, you need to open a socket using fsocketopen and send all the HTTP headers that the target server expect:
     
     
    function PostRequest($url, $referer, $_data) {
        // convert variables array to string:
        $data = array();    
        while(list
  • Bookmark and Share Email
     
  • Sunday, January 18, 2009
  • PHP script to find a PC location in a network based on its MAC address
  • Following is a PHP script I wrote to find a PC location in a farm of CISCO switches based on its MAC address, the script connects to a central switch, trys to find where the PC is connected "on which port", if it does not find it, then the script connects to the next switch based on CDP protocol. NOTE: Some regular expressions may be not accurate in all circumstances, take it as is at your risk, or feel free to change it. <?php function login($telnet,$username,$password) { $response = readBuffer($telnet); if($username != null) fputs($telnet,"{$username}\r\n"); fputs($telnet,"{$password}\r\n"); $response .= readBuffer($telnet); // if the switch in user mode // then go to exec mode if(preg_match("/[a-z0-9_\(\)\-]+>$/i",$response) ) { $response .= sendCommand($telnet,"en"); $response .= sendCommand($telnet,$password); } preg_match("/[a-z0-9_\(\)\-]+[#>]$/i",$response,$out); return str_replace("#","",$out[0]); // return hostn
  • Bookmark and Share Email
     

PROFILE

Razi F. Alsayyed
Computer Engineer
I am a 26 years old computer enginner, graduated from An-Najah National University in 2005, and working in it since that.
 
Show Full Profile
 
 

GENERAL POSTS

 
Please do not email me if you do not know me
Please do not e-mail me if you do not know me