Jump to content

Dareros

Members
  • Posts

    21
  • Joined

  • Last visited

Dareros's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Yes, strange behavior! $start return : 1416165131.3015 $end return : 1416165131.4172 $diff return : 1416165131417.2 How that can happen ?
  2. Hi; why does this snippet of code doesn't measure the time required to include the file in milliseconds. The problem is unknown for me because the variable $diff always have the wrong value. Here is the code : <?php $start = microtime(true); include('/path/to/my/script.php'); $end = microtime(true); $diff = ($end-$start)*1000; echo 'The script took ' . $diff . 'ms to proceed.'; ?> The problem is that the variable $diff return a big number instead of a couple of milliseconds, for example it return a value such as 1416110398494 which is illogical why ? Regards
  3. Hi, i have a problem to include files witch have multiple dots, here is example : include("/path/to/filename.txt"); // This one work fine include("/path/to/filename.txt.txt"); // Give 500 error, even if the full path is correct include("/path/to/dire.c.tory/filename.txt"); // Give 500 error, even if the full path is correct So what is the problem ? How to know if a giving path $path contain files or directories with multiple dots or just one or no dot ? something like : function is_multiple_dots($path) { // return true in the case of presence of two or more dots in the name of at least one directory or filename // return false in the case of presence of at maximum of one dot per filename or directory name } Regards
  4. Hi, but how to get the status code and other headers information ? This is the header i get, still doesn't contain all the info why ? 0 : X-Content-Type-Options: nosniff 1 : Server: Apache 2 : X-Powered-By: 3 : P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM" 4 : Content-Type: text/html; charset=utf-8 5 : Expires: Mon, 1 Jan 2001 00:00:00 GMT 6 : Last-Modified: Wed, 08 Oct 2014 15:09:06 GMT 7 : Cache-Control: post-check=0, pre-check=0 8 : Pragma: no-cache Thank you
  5. Hi; I want to get the response headers using ob_get_contents ? For example using file_get_contents, it is easy by accessing the variable $http_response_header like that : <?php $content = file_get_contents($url); print_r($http_response_header); ?> But how to do that using ob_get_contents without a file_get_contents ? something like for example : <?php ob_start(); include($path_to_script_here); $string = ob_get_contents(); // Access the headers here ob_end_clean(); ?> Thank you
  6. Hi; i would like to search for a regular expression to grab all printf occurences including the folowing senarios : printf("something"); printf("something", variables); printf("something", variables, variables); printf("something);something", variables, variables); To simplify the third and fourth cases, the regex should start from printf(" and go intil it find ); with a white space after it. But i didn't realise how to do it. This trick should work also for the first and second case. Thanks
  7. Is there a difference between a single quote regex and and double quote regex ? for example : <?php $res1 = preg_match('/shi*t/', $comment); $res2 = preg_match("/shi*t/", $comment); ?> Thank you
  8. Okay, i haven't tested it locally yet. So if both are identical and it is only google.com magic than no problem. But i haven't tried it yet to answer you. Thank you.
  9. Hi, the issue now is not the response header. It is the page content itself which render differently using both functions. I have modified the code so you can test it on google and see that the resulting page for the fule_get_contents version with test1 have the google black toolbar on the top while the curl version with test2 doesn't have it why ? <?php function test1() { $options = array( 'http' => array( 'user_agent' => $_SERVER['HTTP_USER_AGENT'], // who am i 'max_redirects' => 7, // stop after 10 redirects 'timeout' => 120, // timeout on response 'follow_location' => true ) ); $context = stream_context_create( $options ); $page = @file_get_contents( 'http://www.google.com', false, $context ); echo $page; } function test2() { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.google.com'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //curl_setopt($ch, CURLOPT_NOBODY, 0); //curl_setopt($ch, CURLOPT_GET, 0); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 7); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt ($ch, CURLOPT_COOKIEFILE, "./cookie.txt"); curl_setopt ($ch, CURLOPT_COOKIEJAR, "./cookie.txt"); curl_setopt($ch, CURLOPT_AUTOREFERER, true); $response = curl_exec($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); // Extract header info $body = substr($response, $header_size); // extract html body of the page curl_close($ch); echo $body; // print the html response } test1(); //test2(); ?> Thanks
  10. Okay, i have resolved the problem of headers so now i can receive headers information but why the two functions below doesn't return the same result, just copy past it and test it yourself. I want to make the function test2 identical to test1 so i test one function and command out the other to see the result. <?php function test1() { $options = array( 'http' => array( 'user_agent' => $_SERVER['HTTP_USER_AGENT'], // who am i 'max_redirects' => 7, // stop after 10 redirects 'timeout' => 120, // timeout on response 'follow_location' => true ) ); $context = stream_context_create( $options ); $page = @file_get_contents( 'http://www.google.com', false, $context ); print_r($http_response_header); echo $page; } function test2() { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.google.com'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_NOBODY, false); curl_setopt($ch, CURLOPT_GET, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 7); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt ($ch, CURLOPT_COOKIEFILE, "./cookie.txt"); curl_setopt ($ch, CURLOPT_COOKIEJAR, "./cookie.txt"); $output = curl_exec($ch); curl_close($ch); print_r($http_response_header); echo $output; } //test1(); test2(); ?> Thank you
  11. Hi, i would like to translate this code to request the url http://www.google.com and get header response with file_get_contents into cUrl command. This is the file_get_contents version : <?php $options = array( 'http' => array( 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'max_redirects' => 7, 'timeout' => 120, 'follow_location' => false ) ); $context = stream_context_create( $options ); $page = @file_get_contents( 'http://www.google.com', false, $context ); print_r($http_response_header); echo $page; ?> Now, i have tried to translate it using cUrl with the code below but i don't get the same result, for example $http_response_header is void and you can test it yourself to see the difference : <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.google.com'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); $page = curl_exec($ch); curl_close($ch); print_r($http_response_header); echo $page; ?> Thank you.
  12. Okay, i am using Joomla. So can i grab the requested page content and do preg_replace all occurences of /ctrl from links. Also is your .htaccess trick will alow passing QUERY_STRING such as a=alpha&b=beta to the controller.php because in your example $_GET['filename'] contain the full path to the requested physical script and so won' contain any query string on it also how does controller.php will process post requests ? Thank you
  13. Thank you very mush, your idea works perfectly. Just have a little issue i would like you to help me with please. When i move the controller.php file into a sub directory such as ctrl, the paths of all the files become: The controller full path : /var/www/html/site/ctrl/controller.php The .htaccess full path : /var/www/html/site/.htaccess The index.php full path : /var/www/html/site/index.php And this is the content of my controller.php <?php include( $_GET['filename'] ); ?> The issue in this case is that /var/www/html/site/index.php which represent http://www.yoursite.com/index.php render html content okay but the css and javascript files paths contains wrong paths so they don't render for example i get : <link rel="stylesheet" href="/site/ctrl/templates/system/css/system.css" type="text/css" /> instead of <link rel="stylesheet" href="/site/templates/system/css/system.css" type="text/css" /> The same for other css and javascript files so what is the solution in this case because i have no clue ? being in .htaccess or in controller.php. Thank you
  14. Hi; I have succesfully managed to route all the traffic to the file controller.php using this command line of .htaccess : RewriteEngine On RewriteRule (.*) /var/www/html/site/controller.php [L,QSA] Now how to tell the controller.php to process the url that was passed. For example i have tried that: controller.php : <?php include( $_SERVER["REQUEST_URI"] ); ?> but the controller.php didn't do anything i keep getting a blank page when i browse any webpage such as site/index.php so how to tell controller.php to echo the content of the request ? because the user shouldn't notice any change as if there is no controller.php. Thank you.
  15. I understand what you mean, you want to regex starting by http or www to guess that this is a url. I have a better alternative because some times, it is a relative url and some times it is absolute with or without protocol. So the alternative i have is to remove all possible cases one by one. The possible cases we can have are : 1. '?id=5&start=0' 2. '?id=5&start=0&something' 3. 'something&id=5&start=0' 4. 'something1&id=5&start=0&something2' Now, the replacements should be for each case : 1. '' 2. '?something' 3. 'something' 4. 'something1&something2'
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.