PHP - Fread() Can't Read .asp Page Fully
Dear friends,
I wrote a code to extract a text from a pages of a site like this: ************ $handle = @fopen($url, 'r'); $contents = ''; if ($handle) { while (!feof($handle)) { $contents .= fread($handle, 8192); } ************ This code is working properly with many pages just pages those are began with the following tags: ************ ... <body> <form name="aspnetForm" method="post" action="ViewContents.aspx?Contract=cms_Contents_I_News&amp%3br=721192" id="aspnetForm"> <input type="hidden" name="__VIEWSTATE" id=" __VIEWSTATE" value="" /> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwL+raDpAgL3qPzdCwLyp86ZD5mqDm6ZnRL/pRerpqyobvzmy5LB" /> ************ The result of function read() in variable $content is not full. It's just theme of the page without main content. I mean there isn't the story related to id of page (e.g. 721192) in the $content. Why? Is the above <form> affected the result? What can i do? Please help me. Similar TutorialsHi! I run a site the requires users to access largeish files, for download as well for streaming to the browser. It's fairly active, so assuming the worst, how bad is getting php to read the files that would be stored outside of the webroot and then getting it to echo it to a page dynamically for the browser to then read? Currently, I just have the files stored accessible to the web, but a htaccess protects them via requiring a cookie but also requires the referrer to be my site. Now I'm not totally stupid and realise those are both easily spoofed, so I'm looking for a better solution. How do the file hosting sites do it? Using a token system has to involve PHP or some other server side scripting, but then getting the server to read the file with fread() or some similar equivalent would be resource heavy, no? Is that the best way to do it? Hello. I need help adding a text file content by one and then saving. My current code is $myFile = "serving"; $fh = fopen($myFile, 'w+') or die("can't open file"); $conv = fread($fh, 4); $stringData = $conv++; fwrite($fh, $stringData); fclose($fh); I was told this would work, but of course, it doesn't. It always returns 1. I also tried casting it as an int by using $stringData = (int) $conv++; I want to load and display the content of a text file (actually it is a cache file). I tested both method using a long for loop as Code: [Select] for ($i=0; $i < 10000; $i++) { $handle = fopen("test.txt", "r"); $text = fread($handle, filesize("test.txt")); fclose($handle); echo $text; }and Code: [Select] for ($i=0; $i < 10000; $i++) { $text = file_get_contents("test.txt"); echo $text; } but the results were similar, though with a large distribution of the comparative data. The speed of a method was 0.5 to 2.0 faster than the other one (in various runs). Which method do you recommend? Could you please quote the pros and cons of each method? I have a php page in which javascript called like this <script language="JavaScript" type="text/javascript" src="http://www.test.com/test.php"></script> the output of the page shows a well detail table , but when i use file_get_content method to get that all detail in a varaible its just took above javascript like $a=<script language="JavaScript" type="text/javascript" src="http://www.test.com/test.php"></script> when i right click on page to view source it show just <script language="JavaScript" type="text/javascript" src="http://www.test.com/test.php"></script>. But on actual page there is a html table which detail i have to store in table, Can any one tell me method. Hi i am trying to read a page that i open but i keep getting errors and dont know why any ideas. The code im using is: foreach($url_extq_data as $a) { $var .=$a; } // now replace all the tags in the substring and out put the data $from = array("{our_track}", "{name}", "{surname}", "{email}", "{title}", "{gender}", "{dobday}", "{dobmonth}", "{dobyear}", "{address}", "{address2}", "{town}", "{county}", "{postcode}", "{tel}", "{mobile}", "{timestampu}", "{timestampr}", "{username}", "{password}", "{company}", "{siteurl}", "{fax}", "{tracking}"); $to = array("$our_id", "$name", "$surname", "$email", "$title", "$gender", "$dobday", "$dobmonth", "$dobyear", "$address", "$address2", "$town", "$county", "$postcode", "$tel", "$mobile", "$timestampu", "$timestampr", "$username", "$password", "$company", "$siteurl", "$fax", "$trackit"); $final_url = str_replace($from, $to, $var); // open url and wait for response $handle = fopen('$final_url', "r"); echo $final_url; ##$contents2 = stream_get_contents($handle); $contents2 = ''; $contents2 .= fread($handle, 100); $contents2 = trim($contents2); This is what i get back: <br /> <b>Warning</b>: fopen($final_url) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in <b>/home/s/e/searlco/web/public_html/ms_creg.php</b> on line <b>232</b><br /> http://www.cleanleads.co.uk/lead.aspx?campid=30&suppid=284&HSID=1121&HOID=52&FirstName=Dafydd&LastName=Thomas&AddressLine1=31 Cottage Street&Postcode=SS131HR&Gender=M&DateOfBirth=13/10/1980&emailaddress=dait@tedfsdfsdit.com&title=Mr&SupplierSourceCode=11866<br /> <b>Warning</b>: fread(): supplied argument is not a valid stream resource in <b>/home/s/e/searlco/web/public_html/ms_creg.php</b> on line <b>236</b><br /> ER Any help anyone???? im lost Hi all I am pulling my hair out trying to get the following script to work Code: [Select] <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist"); // log in at server1.example.com on port 22 if(!($con = ssh2_connect("*.*.*.*", 22))){ echo "fail: unable to establish connection\n"; } else { // try to authenticate with username root, password secretpassword if(!ssh2_auth_password($con, "root", "********")) { echo "fail: unable to authenticate\n"; } else { // allright, we're in! echo "okay: logged in...\n"; // execute a command if (!($stream = ssh2_exec($con, "ls -al" ))) { echo "fail: unable to execute command\n"; } else { echo "should be ok"; // collect returning data from command stream_set_blocking($stream, true); $data = "path to file checked by logging into WINSCP and looking at properties. Is a .txt file"; echo $data; while ($buf = fread($stream,4096)) { $data .= $buf; } fclose($stream); } } } Basically shouldnt this display the contents of the file to me? On screen I just get Quote okay: logged in... should be ok What is my error? Thanks I found a script online that I am trying to get working. It was giving a 500 error from the get go and I've pinpointed it to the $data = fread() line. Does anyone know why? <?php $file = "../../media/v_360.m4v"; $filesize = filesize($file); $offset = 0; $length = $filesize; if (isset($_SERVER['HTTP_RANGE'])) { // if the HTTP_RANGE header is set we're dealing with partial content $partialContent = true; // find the requested range // this might be too simplistic, apparently the client can request // multiple ranges, which can become pretty complex, so ignore it for now preg_match('/bytes=(\d+)-(\d+)?/', $_SERVER['HTTP_RANGE'], $matches); $offset = intval($matches[1]); $length = intval($matches[2]) - $offset; } else { $partialContent = false; } $file = fopen($file, 'r'); // seek to the requested offset, this is 0 if it's not a partial content request fseek($file, $offset); $data = fread($file, $length); /* fclose($file); if ($partialContent) { // output the right headers for partial content header('HTTP/1.1 206 Partial Content'); header('Content-Range: bytes ' . $offset . '-' . ($offset + $length) . '/' . $filesize); } // output the regular HTTP headers header('Content-Type: ' . $ctype); header('Content-Length: ' . $filesize); header('Content-Disposition: attachment; filename="' . $fileName . '"'); header('Accept-Ranges: bytes'); // don't forget to send the data too print($data); */ ?> Its trying to read a 60mb file. Do you think it is timing out and that is causing the error? G'day all, i've got this script that I found on the net some time back but not entirely sure where, however it works well except I want to add a feature so it shows the image details from a txt file. Here is the gallery script: <?php function getDirectory( $path = '.', $level = 0 ){ $ignore = array( 'cgi-bin', '.', '..' ); $dh = @opendir( $path ); while( false !== ( $file = readdir( $dh ) ) ){ if( !in_array( $file, $ignore ) ){ if( is_dir( "$path/$file" ) ){ $dir = $path . $file; echo "<h2>$file</h2><p>"; $dh1 = @opendir( $dir ); while( false !== ( $image = readdir( $dh1 ) ) ){ if( !in_array( $image, $ignore ) ){ if( !is_dir( "$dir/$image" ) ){ if (preg_match("/.jpg/", $image)) { echo "<a href=\"$dir/$image\" rel=\"lightbox\"><img src=\"gallery-thumbnail.php?file=$file/$image\" border=2 style='border-color: #981C1E'></a>\n"; } } } } echo "</p>"; $level++; } } } closedir( $dh ); } getDirectory('gallery/'); ?> Now, what i'm wanting is to read a txt file either in the root or 'gallery' directory, where it has the file name, title, description, photographer. (something like filename.jpg|title of image|description about image|J King). so when the image is displayed, a script reads the text file and will show the image info beside it. Now i've got this bit of snippet from an old script I used once, but can't seem to get it to work anywhere, so any help is greatly appreciated. $text = "gallery.txt"; $fh=fopen($text, "r"); while(!feof($fh)) { $temp = explode("|", $line); $title[$temp[0]] = $temp[1]; $description[$temp[0]] = $temp[2]; $photographer[$temp[0]] = $temp[3]; $line=fgets($fh); unset($temp); } Hello,
I try to get website speed of some website, but i can read only ''domain.com'' i can't read website files like css , js ... why ? i use proxies for this job.
here is the php code:
$options = array( 'useragent' => "Firefox (+http://www.firefox.org)", // who am i 'connecttimeout' => 120, // timeout on connect 'timeout' => 120, // timeout on response 'redirect' => 10, // stop after 10 redirects 'referer' => "http://www.google.com", 'proxyhost' =>'85.25.8.14:80' ); $response = http_get("http://solve-ict.com/wp-content/themes/ict%20theme/js/jquery-1.7.1.min.js", $options , $info);but it works fine with http://domain.com/ , but with files css or js it gives 404, using some free proxy servers available ? Thanks. Hi, Im trying to create a really simple password protected page that is fairly secure but when the user doesnt enter a password the wrong error is displayed. Can anyone see a problem? Also could someone please check that im properly compairing the hash password of 2135fa0dd7fb99d167b420b7ff34ec98 with what the user entered when its hashed? login.php <?php session_start(); ?> <?php $submit = $_POST['submit']; $password = md5($_POST['password']); if ($submit) { if ($password) { if ($password == '2135fa0dd7fb99d167b420b7ff34ec98') { $_SESSION['user'] = logged; header('Location: page.php'); } else { header('Location: index.php?id=1'); } } else { header('Location: index.php?id=2'); } } else { header('Location: index.php?id=1'); } ?> index.php <?php $id=$_REQUEST['id']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/xml; charset=utf-8" /> <title>Keys</title> <link rel = "stylesheet" type = "text/css" href = "css/layout.css" /> </head> <body> <div id="header"> <h1>Keys</h1> </div> <div id="secondheader"> </div> <div id="main"> <form method="POST" action="login.php"> Password: <input type="password" name="password" onfocus="selected(this)" onblur="notselected(this)"> <input type="submit" name="submit" value="Login"> </form> <br/> <?php if ($id==1) { echo "Invalid password. Please try again"; } elseif ($id==2) { echo "Please enter a password"; } ?> </div> <div id="footer"> </div> <div id="left"> </div> </body> </html> Thanks in advance. Trying to get this done: Page_1 has many external links, when certain links are clicked i do not want user to go directly to page, but rather go to a special add page_2 where user must click a second time on the link to finally get there. The add page_2 must show on screen the name of the initial link from page_1, it must change accordingly with the link it came from page_1,once on page_2 the hyperlink redirects outside the site. So far i am thinking give an id to the div or "<a href..." on page_1 then somehow have page_2 detect that id and fill in the variable for the final external link. Other wise is there a way to detect a url from incoming? I guess a similar example is how some domain name sellers landing page will indicate the name of the site. Such as "Thisdomain.com" is for sale. same landing page but the name changes according to the domain that was typed. Is w3c a truce source to follow for any errors found on a website?
For eg. I have my links setup like this. < a href="record.php?id=4&user=smith"></a>
W3C is tell me to not use "&" symbol and that instead escape it as &
So what do I just replace & with & in all my links?
I have used the XAMPP installer to install php and MySQL locall on my computer. I also succeeded in setting the security for XAMPP pages, the MySQL admin user root and phpMyAdmin login. When I enter phpMyAdmin via the link in the XAMPP initial page I do however receive a red notification: phpMyAdmin configuration storage is not fully configured; some extensions are not activated. To find out click here. I have attached a screenshot showing three items which are not OK, shown in red. I looked up in the documentation, but could not find out. I hope someone can help. I don't even know if it is important to fix this problem. Regards, Erik Attached Files XAMPP2.jpg 41.08KB 0 downloads Hi could anyone help me please. Hey all, I'm working on a website to show various products. I am using PHP, HTML, MySQL. I have a products page which shows a table of products (either all or just products from a specific category). Currently, the page works fine, shows an image, brand, name, and price of each product. However, when I have tried to make the image and the brand and name a link, it doesn't fully work. In the page source it will show correctly, but on the webpage itself I cannot click on the links. I have scoured various forums and manuals and have tried all the various ways to code the <a href=> but it still does not work right. Here's a snippet of the code with the link... Code: [Select] /*Other code above for MySQL queries, HTML table etc*/ <td> <?php echo '<a href="details.php?id=' . $row['id'] . '"><img src="resize.php?id=' . $row['id'] . '"/></a>'; ?> </td> <td> <?php echo "<a href=\"details.php?id=" . $row['id'] . "\">" . $row['brand'] . "<br>" . $row['name'] . "</a><br>"; echo "Price: $" . $row['price'] . "<br>"; ?> </td> I have even tried putting the <a href="details.php?id=<?php echo $row['id']; ?> ... </a> just between the <td> and </td>. I still can't click the links on the page, even though they are technically there. The page source will show <a href="details.php?id=1"> ... =2"> ... =3"> ... etc for each product that is displayed. If I actually type details.php?id=1 in my browser and go back to the products page the text will change color to the "visited link" color. Any insight into my dilemma? Thanks in advance... This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=358359.0 Hello All,
I'm having trouble trying to "wrap my head around" how I can make the query in my code below more efficient, elegant, and certainly immune to a SQL-injection attack
So, I have a form (which can be seen in the attached screenshot) which has the user first select a search-type via a dropdown listbox. The two choices pertain to two columns in the underlying table i.e. store_name and item_description. Once that selection is completed the user is expected to enter a search-term (which is typically in relation to the choice selected in the first prompt).
Now, what I would like to happen is that the query be created based on both, the value in the search-type prompt, as well as the value in search-term textbox, and of course, the query must be a parameterized prepared statement (to minimize the possiblity of a SQL-inection attach).
Essentially I would like to get rid of the following code (which I believe is potentially redundant, and contains a hard-coded column name between the WHERE and LIKE), to make things less complicated and more elegant/flexible
if ($searchtype == "store_name") { $sql = "SELECT * FROM `shoplist` WHERE store_name LIKE :searchterm ORDER BY store_name ASC"; } else if ($searchtype == "item_description") { $sql = "SELECT * FROM `shoplist` WHERE item_description LIKE :searchterm ORDER BY store_name ASC"; }Here's what I tried: // Tried this first but it didn't work...gave some kind of error pertaining to the parameter 2 // Prepare the query ONCE $query = "SELECT * FROM `shoplist` WHERE ? LIKE ? ORDER BY ? ASC"; $searchterm = '%' . $searchterm . '%'; $statement = $conn->prepare($query); $statement->bindValue(1, $searchtype); $statement->bindParam(2, $searchterm); $statement->bindValue(3, $searchtype); $statement->execute(); // ----------------------------------------------------------------------------------------------------------- // // Tried this as well, but was getting unexpected results (mostly all rows being returned, regardless of input) // Prepare the query ONCE $query = "SELECT * FROM `shoplist` WHERE :searchtype LIKE :searchterm ORDER BY :searchtype ASC"; $searchterm = '%' . $searchterm . '%'; $statement = $conn->prepare($query); $statement->bindValue(':searchtype', $searchtype); $statement->bindValue(':searchterm', '%' . $searchterm . '%'); $statement->execute();Here's the complete code (pertaining to the problem/request): // create short variable names if(isset($_POST['searchtype'])) { $searchtype=$_POST['searchtype']; } if(isset($_POST['searchterm'])) { $searchterm=trim($_POST['searchterm']); } if(isset($_POST['searchtype']) && isset($_POST['searchterm'])) { if (!get_magic_quotes_gpc()) { $searchtype = addslashes($searchtype); $searchterm = addslashes($searchterm); } } if(isset($_POST['searchtype']) && isset($_POST['searchterm'])) { // ****** Setup customized query ****** if ($searchtype == "store_name") { // The following statement is potentially open to SQL-inection attack and has therefore been REM(arked) // $sql = "SELECT * FROM `shoplist` WHERE " . $searchtype . " LIKE :searchterm ORDER BY store_name ASC"; // The following may not be open to SQL-injection attack, but has the column name hard-coded in-between the WHERE and LIKE clauses // I would like the the column name to be set based on the value chosen by the user in the form dropdown listbox for "searchtype" $sql = "SELECT * FROM `shoplist` WHERE store_name LIKE :searchterm ORDER BY store_name ASC"; } else if ($searchtype == "item_description") { // The following statement is potentially open to SQL-inection attack and has therefore been REM(arked) // $sql = "SELECT * FROM `shoplist` WHERE " . $searchtype . " LIKE :searchterm ORDER BY item_description ASC"; // The following may not be open to SQL-injection attack, but has the column name hard-coded in-between the WHERE and LIKE clauses // I would like the the column name to be set based on the value chosen by the user in the form dropdown listbox for "searchtype" $sql = "SELECT * FROM `shoplist` WHERE item_description LIKE :searchterm ORDER BY item_description ASC"; } $statement = $conn->prepare($sql); $statement->bindValue(':searchterm', '%' . $searchterm . '%'); $statement->execute(); ... ... ... }Thanks guys! Attached Files Search-Screen-SS.png 21.31KB 0 downloads Greetings. I'm working on a Wordpress site utilizing a fully-responsive theme ( www.ailimconsulting.com ). One of the features that was requested was the integration of a special menu hover effect found at GitHub that creates a shadow below the menu item being moused over ( you can see this effect by visiting the link above ). As part of the fully responsive nature of the theme, when the browser collapses to a certain point or the site is viewed on mobile devices the menu itself collapses to a single-tabbed system. The problem is that the class that controls the shadow float causes this collapsed menu to look like crap. So, we want to remove the directives of this class from all the mobile viewing settings ( the @media controls ).
The effect is added to the menu via the Appearance / Menus in the CSS Classes field in each menu item with the class name of .float-shadow.
The effect works perfectly in full browser mode but needs t be removed from all the @media sections of the CSS that control the fully-responsive nature of the theme in various devices dimensions. For example, these are the @media directives:
/*-------------------[320px]------------------*/ |