PHP - Is It Possible To Detect A 'type' Of Proxy?
I was wondering if there was a way or if it's even possible to determine the type of a proxy using php. When I say type I mean http, socks4 or socks5.
Using cURL I think it's safe to assume that if a proxy returns a code of 200 then that proxy is good and http, correct? However, how would I go about determining the type of proxies I have in a list, assuming they are good and socks4 and/or socks5? Similar TutorialsHello Is there any way to find out what is type of proxy? I mean Anonymous, Transparent etc. Hi,
I would like to ask if someone knows a trick to know if the script is running on a shared hosting or a vps or a dedicated server.
Regards
I have piping set up, where when I send an e-mail to a certain address, a script executes. This script will parse the e-mail and will post the body of the e-mails (along with a picture, if attached) to a blog. This all works okay, except the problem I keep running into is when I send from different devices (desktop, Android phone, BlackBerry), the e-mails have different character sets or encoding. So one e-mail will show up just fine, and then the body of another will look something like this: Quote --90e6ba6e83a0846c8504926b9478 Content-Type: text/html; charset=ISO-8859-1 This is the content of the e-mail. --90e6ba6e83a0846c8504926b9478-- So what I'm wondering is if there is any way to detect the charset/encoding and automatically decode it properly? The only solution I have so far -- and I'm not very good with PHP, I'll admit -- is to just "hack" my way through, by using stristr() to see if the body contains certain characters (like "ISO-8859-1"), and then extracting the text that is in between, say, "ISO-8859-1" and "--". Of course, this is very crude, and has many problems on its own. So what I am looking for is if there is some sort of way to automatically get the body of an e-mail in plain text, regardless of whether the e-mail has an attachment, how it's encoded, or what mail client was used. Thanks for your time! Folks,
I am building a membership script for 21 months now!!! That long!!!
Not pasting the whole script as really long. Would do your head in. if($_SERVER["REQUEST_METHOD"] == "POST") { if(!isset($_FILES["id_verification_video_file"])) //REtype { echo "no isset"; } else { $id_verification_video_file = $_FILES['id_verification_video_file']; //REtype //Feed Id Video Verification File Upload Directory Path. $directory_path = "uploads/videos/id_verifications/"; //Make Directory under $user in 'uploads/videos/id_verifications' Folder. if(!is_dir("$directory_path" . "$user")) { $mode = "0777"; mkdir("$directory_path" . "$user", "$mode", TRUE); //Thanks Requinix for my "$mode" typo hint. } //Grab Uploading File details. $Errors = Array(); //SHOULD I KEEP THIS LINE OR NOT ? $file_name = $_FILES["id_verification_video_file"]["name"]; $file_tmp = $_FILES["id_verification_video_file"]["tmp_name"]; $file_type = $_FILES["id_verification_video_file"]["type"]; $file_size = $_FILES["id_verification_video_file"]["size"]; $file_error = $_FILES['id_verification_video_file']['error']; //Grab File Extension details. $file_extension = pathinfo($file_name, PATHINFO_EXTENSION); if(file_exists('$directory_path' . '$user/' . '$file_name')) { $Errors[] = "Error: You have already uploaded a video file to verify your ID!"; exit(); } else { //Feed allowed File Extension(s). $allowed_file_extensions = array("mp4" => "video/mp4","wmv" => "video/wmv"); //Feed allowed file size. $max_file_size_allowed_in_bytes = 1024*1024*100; //Allowed limit: 100MB. $max_file_size_allowed_in_kilobytes = 1024*100; $max_file_size_allowed_in_megabytes = 100; $max_file_size_allowed = "$max_file_size_allowed_in_bytes"; //RETYPE //Verify File Extension. if(!array_key_exists($file_extension,$allowed_file_extensions)) die("Error: Select a valid video file format. Select an MP4 or WAV file."); //Verify MIME Type of the file. elseif(!in_array($file_type,$allowed_file_extensions)) { echo "Error:<font size ='5' font color ='red'><b>There was a problem uploading your video file $file_name! Make sure your file is an MP4 or a WAV file. You may try again now.</b></color></size>"; //THANKS TO REQUINIX FOR BRINNGING IT TO MY ATTENTION I AM STILL PROCESSING THE SCRIPT AFTER THIS LINE WHEN I SHOULD NOT. exit(); } //Verify File Size. Allowed Max Limit: 100MB. elseif($file_size>$max_file_size_allowed) die("Error: Your Video File Size is larger than the allowed limit of: $max_file_size_allowed_in_megabytes."); //Fixed variable name typo. Thanks to Requinix & Simon JM. //Move uploaded File to newly created directory on the server. move_uploaded_file("file_tmp","$directory_path" . "$user/" . "$file_name"); //Notify user their File was uploaded successfully. echo "<font size ='5' font color ='red'><b>Your Video File \"$file_name\" has been uploaded successfully! You will get notified once your Id has been verified successfully.</b></color></size>";
Can you spot my coding error ? hi there, i am fairly new to OOPs in php, i get an error when i declare the argument type (as object) in a function and pass the same type (object). class eBlast { public static function getEmail(object $result) { return $result->email; } } $r = mysql_fetch_object($query); eBlast::getEmail($r); echo gettype($r); // outputs: object error is : Code: [Select] Catchable fatal error: Argument 1 passed to eBlast::getEmail() must be an instance of object, instance of stdClass given, called in C:\wamp\www\integra\client\pl_eblast\admin\send_emails.php on line 145 and defined in C:\wamp\www\integra\client\pl_eblast\app\app.eBlast.php on line 8 if i remove the type declaration in the function it works, but just would like to know why it shows error when pass the same type, also isnt mysql_fetch_object is the instance of stdclass? thanks in advance! I have this PHP script to fetch whois information of domain. It works, but when I try to connect whois server via proxy, then it doesnt work. The proxy ip is taken from proxylist.hidemyass.com. What I do wrong? Thank you for help.
$server = "whois.nic.cz"; $domain = "klikzone.cz"; function QueryWhoisServer($server, $domain){ $proxy = "85.111.25.189:8080"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $server); curl_setopt($ch, CURLOPT_PORT, 43); curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $domain . "\r\n"); $data = curl_exec($ch); curl_close($ch); return $data; } Could someone give me a cross-domain proxy script? I am trying to post data to mysql databases on two servers. I need a proxy that would enable me to use curl with another ip address. How do I find a paid proxy server that supports curl? Hi I need a script to hide IP address with proxy and read a web page
$username="myuser"; The script doesn't work, it doesn't show me the page output. Any solution? Hi, I'm trying to understand any how I can block all users trying to view my website through proxies. With the following code, what I have done is a quick version through php (with headers and ports) and not the firewall which isn't exactly the best way but still stops a lot of them. <?php $user_ip = $_SERVER['REMOTE_ADDR']; $headers = array('CLIENT_IP','FORWARDED','FORWARDED_FOR','FORWARDED_FOR_IP','VIA','X_FORWARDED','X_FORWARDED_FOR','HTTP_CLIENT_IP','HTTP_FORWARDED','HTTP_FORWARDED_FOR','HTTP_FORWARDED_FOR_IP','HTTP_PROXY_CONNECTION','HTTP_VIA','HTTP_X_FORWARDED','HTTP_X_FORWARDED_FOR'); foreach ($headers as $header) { if (isset($_SERVER[$header])) { header("Location: /proxy-not-allowed/"); die; } } $queryIP = "SELECT `user_ip_address` FROM `my_table` WHERE `user_ip_address` = :user_ip_address AND `user_blocked` = :user_blocked LIMIT 1"; $queryIP1 = $pdo->prepare($queryIP); $queryIP1->execute(array(':user_ip_address' => $user_ip, ':user_blocked' => 'No')); $queryIP2 = $queryIP1->rowCount(); if ($queryIP2 === 0) { $ports = array(80, 81, 553, 554, 1080, 3128, 4480, 6588, 8000, 8080); foreach ($ports as $port) { $connection = @fsockopen($user_ip, $port, $errno, $errstr, 0.1); if (is_resource($connection)) { header("Location: /proxy-not-allowed/"); die; } } } ?> The headers script blocks any proxy sending those headers while the ports script blocks those using any assigned ports I add. I have tested this which seems to be good, though it won't block all proxies due to the assigned one I have. Is this the best way to go about blocking scripts if I don't have access to the firewall? What I am trying to do is allow users to view my HTTPS website normally and block all proxies. Even if I have some users blocked, I do not want them to be cheeky and use a proxy or even register on my website through a proxy. I was thinking of just using the 443 port as my website is https (is that wise?). Any advice would be great. Edited January 4, 2019 by Cobra23 using curl, ive managed to get my program to log me into a proboards site. I can view the main forum page. The problem is, the links to viewing the page is something like href="index.cgi?board=general&thread=1111&page=45" I did a str_replace to replace the index.cgi to href= "link_processor?board=general&thread=1111&page=45" The idea was that link_processor would contain the data "board=general&thread=1111&page=45" However, i now realise that the way the php would see that as 4 different get variables link processor = board=general thread = 1111 page = 45 How could i make it all part of the link_processor variable because if i can keep the string intact, i just have to pass it to a curl function and i can display the page easily! I was on a proxy and it didnt detect it, idk why. if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['HTTP_X_FORWARDED']) || !empty($_SERVER['HTTP_FORWARDED_FOR']) || empty($_SERVER['HTTP_CONNECTION']) || $hostaddr == "." || stripos($hostaddr, "tor-exit") || !empty($_SERVER['HTTP_VIA']) || empty($_SERVER['HTTP_ACCEPT_ENCODING']) || in_array($_SERVER['REMOTE_PORT'], array(8080,80,6588,8000,3128,553,554)) ) { die('on Proxy'); I have some videos stored above web root. I then have a PHP file that acts as a proxy to hand the videos to the user. The reason for this is so not just anybody can download the videos. They have to be authenticated. If I am on the PC, it prompts for a download so I know the script is working. When I try it on my iPad, I get the big play button but with a cross through it. When I try it on my iPhone, the movie interface loads, but I am then prompted with "Cannot play movie: The server is not correctly configured" What could that be referring to? My script is below: <?php include("config.php"); //just includes session_start and db connection if ($_SESSION['user']['authed'] == true) { session_write_close(); $id = $_GET['id']; $query = mysql_query("SELECT filename FROM episodes WHERE id = '$id'"); $row = mysql_fetch_array($query); $filename = "../../media/".$row['filename']; header( 'Content-Description: File Transfer' ); header( 'Content-Type: application/octet-stream' ); header( 'Content-Disposition: attachment; filename='.basename( $filename ) ); header( 'Content-Transfer-Encoding: binary' ); header( 'Expires: 0' ); header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); header( 'Pragma: public' ); header( 'Content-Length: ' . filesize( $filename ) ); ob_clean(); flush(); readfile( $filename ); exit; } ?> Cannot Get IP Address Behind A Proxy Server.I am using $aph = apache_request_headers(); print $aph['PC-Remote-Addr'] . "<br/>"; print "HTTP_CLIENT_IP: " . $_SERVER["HTTP_CLIENT_IP"] . "<br/>"; print "HTTP_X_FORWARDED_FOR: " . $_SERVER["HTTP_X_FORWARDED_FOR"] . "<br/>"; print "REMOTE_ADDR: " . $_SERVER["REMOTE_ADDR"] . "<br/>"; print "CLUSTER CLIENT " . $_SERVER["HTTP_X_CLUSTER_CLIENT_IP"] . "<br/>"; exit; but does not give output.Please suggest me how to get ip behind proxy server. I'm going to write a script that determines if a proxy is good or not through cURL and I would like to know if anyone knows what qualifies a proxy as being good. Let's assume I need to do some surfing through a proxy - that's it. Is there a way in PHP to determine the 'type' of proxy? For example (elite, codeen, etc.) If the proxy page exists is that all I need to run cURL through it or otherwise consider it as being good? Or should I focus my attention towards simply going through the whole process of getting a 'dummy' page using cURL through the proxy and, should it succeed, it will be considered good. I suppose if I can avoid the latter then the script would be more efficient. Advice and suggestions are always greatly appreciated here. Hi guys, I am creating a script as I am using this to detection the proxy server levels. <?php //proxy levels //Level 3 Elite Proxy, connection looks like a regular client //Level 2 Anonymous Proxy, no ip is forworded but target site could still tell it's a proxy //Level 1 Transparent Proxy, ip is forworded and target site would be able to tell it's a proxy if(!$_SERVER['HTTP_X_FORWARDED_FOR'] && !$_SERVER['HTTP_VIA'] && !$_SERVER['HTTP_PROXY_CONNECTION']){ echo '3'; } elseif(!$_SERVER['HTTP_X_FORWARDED_FOR']){ echo '2'; } else echo '1'; ?> I want the script to check the ip that if the proxy server is a Codeen/PlanetLab and BotNet proxy servers, then place on level one and if they are safe/unsafe to use. I cannot find the code to do the methods. Please help me! Thanks in advance. Received HTTP code 403 from proxy after CONNECT Code: [Select] <?php function getPage($proxy, $url, $referer, $agent, $header, $timeout) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_REFERER, $referer); curl_setopt($ch, CURLOPT_USERAGENT, $agent); $result['EXE'] = curl_exec($ch); $result['INF'] = curl_getinfo($ch); $result['ERR'] = curl_error($ch); curl_close($ch); return $result; } $result = getPage( '89.106.13.93:80', // use valid proxy 'http://www.northplanet.co.uk', 'http://www.youtexv.com/', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8', 1, 5); print_r ($result); ?> Using Slim to route endpoints to my application. In addition, I have many endpoints (mostly accessed via xhr) which need to be forwarded to another server, and I am using Guzzle to do so. Note only do I have to transfer text/json, I also have to send and retrieve files (currently only csv files, but will later add pdf). Accomplishing this was easier than I expected, but expect I may still be doing certain portions wrong. Anything look off, especially with the multipart forms for file uploads as well as the downloading of files? Thank you <?php $app = new \Slim\App($container); //Local requests $app->get('/settings', function (Request $request, Response $response) { return $this->view->render($response, 'somePage.html',$this->bla->getData()); }); //more local endpoints... $proxyEndpoints=[ '/bla'=>['put'], '/bla/bla/{id:[0-9]+}'=>['delete','put'], '/foo/{id:[0-9]+}'=>['get','put','delete','post'], //more proxy endpoints... ]; foreach ($proxyEndpoints as $route=>$methods) { foreach ($methods as $method) { $app->$method($route, function(Request $request, Response $response) { return $this->remoteServer->proxy($request, $response); //add content type if desired. }); } } <?php class RemoteServer { protected $httpClient, $contentType; public function __construct(\GuzzleHttp\Client $httpClient, string $contentType='application/json') { $this->httpClient=$httpClient; $this->contentType=$contentType; } public function proxy(\Slim\Http\Request $request, \Slim\Http\Response $response, string $contentType=null, \Closure $callback=null):\Slim\Http\Response { $contentType=$contentType??$this->contentType; if($contentType!=='application/json' && $callback) { throw new \Exception('Callback can only be used with contentType application/json'); } $method=$request->getMethod(); $bodyParams=in_array($method,['PUT','POST'])?(array)$request->getParsedBody():[]; //Ignore body for GET and DELETE methods $queryParams=$request->getQueryParams(); $data=array_merge($queryParams, $bodyParams); ///Would be better to write slim's body to guzzle's body so that get parameters are preserved and not overriden by body parameters. $path=$request->getUri()->getPath(); $contentTypeHeader=$request->getContentType(); if(substr($contentTypeHeader, 0, 19)==='multipart/form-data'){ syslog(LOG_INFO, 'contentType: '.$contentTypeHeader); $files = $request->getUploadedFiles(); $multiparts=[]; $errors=[]; foreach($files as $name=>$file) { if ($error=$file->getError()) { $errors[]=[ 'name'=> $name, 'filename'=> $file->getClientFilename(), 'error' => $this->getFileErrorMessage($error) ]; } else { $multiparts[]=[ 'name'=> $name, 'filename'=> $file->getClientFilename(), 'contents' => $file->getStream(), 'headers' => [ //Not needed, right? 'Size' => $file->getSize(), 'Content-Type' => $file->getClientMediaType() ] ]; } } if($errors) return $response->withJson($errors, 422); $multiparts[]=[ 'name'=> 'data', 'contents' => json_encode($data), 'headers' => ['Content-Type' => 'application/json'] ]; $options=['multipart' => $multiparts]; } else { $options = in_array($method,['PUT','POST'])?['json'=>$data]:['query'=>$data]; } try { $curlResponse = $this->httpClient->request($method, $path, $options); } catch (\GuzzleHttp\Exception\RequestException $e) { //Errors only return JSON //Networking error which includes ConnectException and TooManyRedirectsException syslog(LOG_ERR, 'Proxy error: '.$e->getMessage()); if ($e->hasResponse()) { $curlResponse=$e->getResponse(); return $response->withJson(json_decode($curlResponse->getBody()), $curlResponse->getStatusCode()); } else { return $response->withJson($e->getMessage(), $e->getMessage()); } } $statusCode=$curlResponse->getStatusCode(); switch($contentType) { case 'application/json': //Application and server error messages will be returned. Consider hiding server errors. $content=json_decode($curlResponse->getBody()); if($callback) { $content=$callback($content, $statusCode); } return $response->withJson($content, $statusCode); case 'text/html': case 'text/plain': //Application and server error messages will be returned. Consider hiding server errors. $response = $response->withStatus($statusCode); return $response->getBody()->write($curlResponse->getBody()); case 'text/csv': foreach ($response->getHeaders() as $name => $values) { syslog(LOG_INFO, "headers: $name: ". implode(', ', $values)); } if($statusCode===200) { return $response->withHeader('Content-Type', 'application/force-download') ->withHeader('Content-Type', 'application/octet-stream') ->withHeader('Content-Type', 'application/download') ->withHeader('Content-Description', 'File Transfer') ->withHeader('Content-Transfer-Encoding', 'binary') ->withHeader('Content-Disposition', 'attachment; filename="data.csv"') ->withHeader('Expires', '0') ->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') ->withHeader('Pragma', 'public') ->withBody($curlResponse->getBody()); } else { return $response->withJson(json_decode($curlResponse->getBody()), $statusCode); } break; default: throw new \Exception("Invalid proxy contentType: $contentType"); } } private function getFileErrorMessage($code){ switch ($code) { case UPLOAD_ERR_INI_SIZE: $message = "The uploaded file exceeds the upload_max_filesize directive in php.ini"; break; case UPLOAD_ERR_FORM_SIZE: $message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"; break; case UPLOAD_ERR_PARTIAL: $message = "The uploaded file was only partially uploaded"; break; case UPLOAD_ERR_NO_FILE: $message = "No file was uploaded"; break; case UPLOAD_ERR_NO_TMP_DIR: $message = "Missing a temporary folder"; break; case UPLOAD_ERR_CANT_WRITE: $message = "Failed to write file to disk"; break; case UPLOAD_ERR_EXTENSION: $message = "File upload stopped by extension"; break; default: $message = "Unknown upload error"; break; } return $message; } public function callApi(\GuzzleHttp\Psr7\Request $request, array $data=[]):\GuzzleHttp\Psr7\Response { try { $response = $this->httpClient->send($request, $data); } catch (\GuzzleHttp\Exception\ClientException $e) { $response=$e->getResponse(); } catch (\GuzzleHttp\Exception\RequestException $e) { //Networking error which includes ConnectException and TooManyRedirectsException if ($e->hasResponse()) { $response=$e->getResponse(); } else { $response=new \GuzzleHttp\Psr7\Response($e->getCode(), [], $e->getMessage()); } } catch (\GuzzleHttp\Exception\ServerException $e) { //Consider not including all information back to client $response=$e->getResponse(); } return $response; } }
Guys, I recently came across this about using a tor socks proxy as a default proxy server in my local home network. So, to my centos-box, I've set the service up with a default soks-port 9050 and the local ip address of this machine is 10.10.1.5. Here's a part of the tor's config file:
SocksPort 10.10.1.5:9050
[jazz@centos-box ~]$ top -u jazz | grep tor 3413 jazz 20 0 76256 32m 9720 S 0.0 0.3 0:01.55 tor [jazz@centos-box ~]$ nmap -Pn 10.10.1.5 | grep 9050 9050/tcp open tor-socks Now, I'm completely able to use that socks proxy from the centos-box with my default browser / curl or whatever you want to be, but if I go to my laptop and set the proxy-socket up to its browser, I've got a message of "TOR is not an HTTP proxy" and half or more ( not all of them ) of my bookmarks web-sites don't work. However, a message when I'm running this service says: Sep 12 13:16:01.769 [notice] You configured a non-loopback address '10.10.1.5:9050' for SocksPort. This allows everybody on your local network to use your machine as a proxy. Make sure this is what you wanted. Sep 12 13:16:01.769 [notice] Opening Socks listener on 10.10.1.5:9050 Ideas? Edited by jazzman1, 12 September 2014 - 12:39 PM. |