PHP - Ob_get_contents Give Empty String
Hi all, I need some help.
My ob_get_contents() is empty and gives me a empty file everytime. I tried different cache script it is still the same. I have also tried fwrite($fp, 'hello') In this case, it successfully writes to the file. But when i use ob_start and ob_get_contents, it will be empty. can anyone please advice. My simplified script is here <?php // Settings $cachedir = 'cache/'; // Directory to cache files in (keep outside web root) $cachetime = 600; // Seconds to cache files for $cacheext = 'html'; // Extension to give cached files (usually cache, htm, txt) // Ignore List $ignore_list = array( '/rss.php', '/search/' ); // Script $page = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // Requested page $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create $ignore_page = false; for ($i = 0; $i < count($ignore_list); $i++) { $ignore_page = (strpos($page, $ignore_list[$i]) !== false) ? true : $ignore_page; } $cachefile_created = ((@file_exists($cachefile)) and ($ignore_page === false)) ? @filemtime($cachefile) : 0; @clearstatcache(); // Show file from cache if still valid if (time() - $cachetime < $cachefile_created) { //ob_start('ob_gzhandler'); @readfile($cachefile); //ob_end_flush(); exit(); } // If we're still here, we need to generate a cache file ob_start(); ?> All My HTML AND PHP CODES TO RUN THE SITE <?php // Now the script has run, generate a new cache file $fp = @fopen($cachefile, 'w'); // save the contents of output buffer to the file @fwrite($fp, ob_get_contents()); @fclose($fp); ob_end_flush(); ?> Similar TutorialsIf the value of $keyword is empty, only then it should print "Hi". else if should print "Hello". Problem is sometimes the value $keyword will be "0". How to handle this condition Code: [Select] $keyword=0; //$keyword='abc'; if (empty($keyword)) { echo 'Hi'; } else { echo "Hello"; } Hello i have a system where leaders add members, i want to display a table of members WHERE the 'leader' field equals 'myusername' so that leaders only see members they added. when using the WHERE function i get a database empty as the result but when i remove the WHERE function i get all the data returned Code: [Select] include("system/include/session.php"); $myUname = $session->username; echo "$myUname"; function displayMembers(){ global $database; $q = "SELECT * " ."FROM ".TBL_MEMBERS." WHERE leader = '$myUname'"; $result = $database->query($q); $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } echo "<table>\n"; echo "<thead> <tr> <th>Full Name</th> <th>Gender</th> <th>DOB</th> <th>Post Code</th> <th>Email Address</th> <th>Edit User</th> </tr> </thead>\n"; for($i=0; $i<$num_rows; $i++){ $Mprefix = mysql_result($result,$i,"prefix"); $Mfname = mysql_result($result,$i,"firstname"); $Mlname = mysql_result($result,$i,"lastname"); $Mgender = mysql_result($result,$i,"gender"); $Mdob = mysql_result($result,$i,"dob"); $Mpostcode = mysql_result($result,$i,"postcode"); $Memail = mysql_result($result,$i,"email"); echo " <tbody> <tr> <td>$Mprefix $Mfname $Mlname</td> <td>$Mgender</td> <td>$Mdob</td> <td>$Mpostcode</td> <td>$Memail</td> <td> <center> <form action=\"system/admin/adminprocess.php\" method=\"POST\"> <input type=\"hidden\" name=\"deluser\" value=\"$uname\"> <input type=\"hidden\" name=\"subdeluser\" value=\"1\"> <input type=\"submit\" class=\"button plain\" value=\"Edit Member\"> </form> </center> </td> </tr> </tbody>\n"; } echo "</table><br>\n"; } all help i am thankful for I noticed that strtolower() wasn't working. My script was adding blank rows to a text file that was supposed to be lowercase emails, so I wrote the following script to confirm it's not working: <?php $var = "Foo"; echo "$var<br />"; echo srttolower($var)."<br />"; $var = strtolower($var); echo "$var<br />"; ?> This page just prints "Foo" once on the screen where I should see Foo foo foo I then checked my error log, and I'm getting Call to undefined function messages for strtolower(). Any ideas? Hi all ! What would be the best way to identify and handle an empty array sent from JS to PHP? This rather simple looking problem has resulted in a lot of confusion to me. $_POST['myArray'] = ""; // an empty string -- this is how the empty array from JS is received in PHP
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 Edited by Dareros, 07 October 2014 - 06:20 PM. Hello, I am trying to change the string 'IRM Reporting Portal' to 'BIS Reporting Portal' as illustrated in the attachment 'Requirements.jpg'. On inspecting 'IRM Reporting Portal', I noticed the function DoResizeMS (). I found this function call in only one file across the entire code. That file is 'header.dsp' (attached) This leads me to believe that the string 'IRM Reporting Portal' is being dynamically generated in 'header.dsp' (Between ob_get_contents() and ob_start()) How do I change that string to 'BIS Reporting Portal'? Please help. I am a PHP newbie. Thanks, Trinanjan. Hello Everyone, I am having issues where people are submitting null characters on my website (I.e. %00). Currently, I check if their is a value by using the empty function, and I also am checking if the value after running the trim command is =="". How can I check for these special characters to make sure that whatever they are submitting actually contains some sort of legitimate value? Thanks! Man, I'm having a rough week with questions--if you're following at home. Basically matching a Coach's first and last name to another table, which if matched will yield information about that coach's team. Code: [Select] // or get user by username $current_user = wp_get_current_user(); $current_first = $current_user->user_firstname; $current_last = $current_user->user_lastname; $current_id = $current_user->ID; echo '<div class="contact_form">'; echo $current_first . ' ' . $current_last .' :: '; $query = "SELECT * FROM schools WHERE coachFirst='".$current_first."' AND coachLast='".$current_last."'"; $result = mysql_query ($query); if(!$result) { echo 'There is not a match for your name.'; } else { while($school= mysql_fetch_array($result)) { echo $school['school'] . ' ' . $school['id']; include(ABSPATH ."wp-content/plugins/my-team/form.php"); } echo '</div>'; echo '<div class="roster">'; include(ABSPATH ."wp-content/plugins/my-team/roster.php"); echo '</div>'; } What I am looking for is that if any field in a database is empty, the form comes back and puts in the word "empty" into the web page, but not the database. I got this right now, it shows the first part fine, but the second part it doesn't show the "Empty" comment... I don't understand why... as far as I can tell the code is fine... Code: [Select] <?php //Nonconformity, Disposition, Comments and Comments & Additional Details echo '<div id="box3">'; if (!empty($row['Nonconformity']) || !empty($row['Disposition']) || !empty($row['Comments']) || !empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />' . $row['Nonconformity'] . '</div>'; echo '<div id="dis"><span class="b">Disposition: </span><br />' . $row['Disposition'] . '</div>'; echo '<div id="comm"><span class="b">Comments: </span><br />' . $row['Comments'] . '</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />' . $row['CommentsAdditional_Details'] . '</div>';} else if (empty($row['Nonconformity']) || empty($row['Disposition']) || empty($row['Comments']) || empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />Empty</div>'; echo '<div id="dis"><span class="b">Disposition: <br /></span>Empty</div>'; echo '<div id="comm"><span class="b">Comments: <br /></span>Empty</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />Empty</div>';} echo '</div>'; ?> How to do #3 by a PHP page instead? mainly so that there wouldn't be a need to export the sql after doing #2 then import it into the online phpmyadmin(#3) #1. Convert database from foxpro to sql #2. Change some fields in the sql table #3. Upload to phpmyadmin Is it possible to create a code to export from the server and then import the sql online? like by making use of mysql_fetch_array() and insert into In a Switch statement, can you give the Default: a specific name, maybe like this... switch ($resultsCode){ // Missing Primary Key. case 'COMMENT_MISSING_KEYS_2050': echo '<h1>System Error</h1>'; echo '<p>A Fatal Error has occurred. Please contact the System Administrator. (2050)</p>'; break; default 'DEFAULT_CATCHALL_ERROR_CODE_9999': echo '<p>You have reached the catch-all error code... (9999)</p>'; break; Debbie I am trying to learn PHP basics, and I just cant figure out a way to insert color when certain conditions are met. In my code below, I want to print out red color on lets say, odd numbers from 20-49. Appreciate your help big time! <?php for ($i=20; $i<=49; $i++){ echo "$i<br>"; } ?> Hi, Hope this is the right place for this... I have php routines that print itineraries. For some reason the timestamp (1351378800) returns the same date Sunday 28th October (2012) as the time stamp (1351465200). $count = 0; while ($count <= ($nights+1)) { echo date ('l', $startdate1)." (".$startdate1.")"; echo "<br>"; echo date ('jS F', $startdate1); $startdate1 += 86400; // more code } Any ideas? Many thanks, Peter I wanna give error messages if the user dont enter their name, email or comments. I trıed to do it but mine didnt work. Please help me do it. Index.php page Code: [Select] <html> <head> <title>Guestbook</title> </head> <body> <font color="#CC0000" size="+2">Please sign our guestbook</font> <br \> <br \> <?php echo "<form name=\"Guestbook\" action=\"confirm.php\" method=\"post\">\n"; echo "<table bgcolor=\"#DAE5CD\">\n"; echo " <tr>\n"; echo " <td valign=\"top\">Name: </td>\n"; echo " <td><input type=\"text\" name=\"name\" size=\"25\" value=\"Your Name\"></td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td valign=\"top\">E-mail:</td>\n"; echo " <td><input type=\"text\" name=\"email\" size=\"25\" value=\"example@mail.com\"></td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td valign=\"top\">Comments:</td>\n"; echo " <td><textarea rows=\"5\" cols=\"30\" name=\"comments\">Comments</textarea></td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td></td>\n"; echo " <td align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Submit\"> <input type=\"reset\" value=\"Clear\"> </td>\n"; echo " </tr>\n"; echo "</table>\n"; echo "</form> "; ?> </body> </html> confirm.php page Code: [Select] <html> <head> <title> Submission receieved! </title> </head> <body> <font size="+2" color="#00B0EB">Your submission has been sent successfully!</font><br /> <br /> <?php //extract($_REQUEST); if (!isset($_POST["$submit"])) { if (empty($_POST["name"])) { echo "Please enter your name!"; } else if (empty($_POST["email"])) { echo "Please enter your E-mail"; } else if (empty($_POST["comments"])) { echo "Please enter some text"; } } ?> <table bgcolor="#DAE5CD" width="%50" cellpadding="5"> <tr> <td valign="top" width="75">Name : </td> <td> <?php echo $_POST["name"];?> </td> </tr> <tr> <td valign="top">E-Mail : </td> <td> <?php echo $_POST["email"]; ?> </td> </tr> <tr> <td valign="top">Comments :</td> <td> <?php echo $_POST["comments"]; ?> </td> </tr> </table> </body> </html> Hey, I would like to get some practice in the following areas: - arrays (including multidimensional and associative) - functions and their return values I would appreciate it if anyone could give me/point me to some exercises/challenges. Thanks! Hello, I have made a PHP script that will feed an existing XML file. The file stores song details like, title, name of singer etc ... Now the file structure is like this for the moment: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <music> <song> <title>Without me</title> <artist>Eminem</artist> <url>songs/coreIssues.mp3</url> <image>img/den.jpg</image> <discspeed>11</discspeed> </song></music> But I need it to be: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <music> <song mainTitle="Eminem - Without me"> <title>Without me</title> <artist>Eminem</artist> <url>songs/coreIssues.mp3</url> <image>img/den.jpg</image> <discspeed>11</discspeed> </song></music> I need it to be like that so if I want to delete a song from the list I just check for the element which will have a unique mainTitle and then delete that element with all it's details. Now, I've searched on Google for some solutions but didn't find any yet. Anyone here knows how to do this? Thanks! Is it possible to feed the browser a default save as name for the image when outputting to the browser, instead of it defaulting to the .php file name? So, instead of myimage.php I could use imagename.jpg or whatever I want. Alright, this is the code that i cant seem to get working. Its supposed to update the pin_lock field in my database. I have two databases that it needs to read from, the Account database to verify the login, then the Game database to modify the pin_lock field. It comes up that its sucessfully modified the entry but when i check it, its still the same as it was before. session_start(); if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') { print("<center>Incorrect verification code!"); die(); } require_once('config.php'); mysql_select_db($accdb); $accountid=$_POST['accountid']; $pass=$_POST['pass']; $email=$_POST["email"]; $idnumber=$_POST["question"]; $phone=$_POST["answer"]; session_start(); if(!$_POST["accountid"]) { print("<center>Account ID Field Empty!"); die(); } if(!$_POST["email"]) { print("<center>E-mail Address Field Empty!"); die(); } if(!$_POST["question"]) { print("<center>Security Questions Field Empty!"); die(); } if(!$_POST["answer"]) { print("<center>Answer Field Empty!"); die(); } if(!ereg("^[0-9a-z]{4,12}$",$accountid)) { print("<center>Account ID Only letters from \"a\" to \"z\" and numbers, lenght of 4 to 12 characters"); die(); } if(!ereg("^[0-9a-z]{4,14}$",$pass)) { print("<center>Password Only letters from \"a\" to \"z\" and numbers, lenght of 4 to 14 characters"); die(); } if(!ereg("^[0-9a-zA-Z_]{4,128}$", (strtr($email, Array('@'=>'','.'=>''))))) { print("<center>E-mail Only letters a to z and special chars @ . are allowed!"); die(); } if($_POST["pass"]!=$_POST["pass2"]) { print("<center>Passwords do not match!"); die(); } $ac = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid'"))); if (!$ac) { print("<center>Account ID does not exist!"); die(); } $em = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND email='$email'"))); if (!$em) { print("<center>E-mail is incorrect!"); die(); } $q = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND idnumber='$idnumber'"))); if (!$q) { print("<center>Security Question is incorrect!"); die(); } $an = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND phone='$phone'"))); if (!$an) { print("<center>Answer is incorrect!"); die(); } $ac = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid'"))); mysql_select_db($gamedb); $temp["query"] = sprintf("UPDATE cq_user SET lock_key='0' WHERE account_id='$selectedid'"); if (!mysql_query($temp["query"])) { die(mysql_error()); } else { print("<center>You bank pin has been removed!"); } Any ideas what is wrong with it? Hi everyone, first thanks for caring to read my post! I am very very new to php but have a really good idea for a site so thought this could be a good chance to finally learn. The site is basically going to be a simple yet very well structured and organised repository for articles with the ability for users to post comments at the bottom of each article (logged in users). The users can also post articles and select which sections they want to put them in. The admin could then review all submissions and accept and then put them in the order in which they best fit (since the articles will usually be relevant to different stages and should be placed in order of assumed knowledge, if that makes sense) Kind of like a tutorials site with content being submitted. I imagine a really uncluttered site that looks more old school than web 2.0. From the first page is just like a simple search engine and underneath a kind of sitemap with each topic showing how many articles are in each. Then as you click into the topic area you are shown another sitemap like display of the articles in this which are perhaps some sectioning to define the type of article it is. As I say, I am quite new so I wondered if you had some suggestions of the top 'aids' to achieving this, and how you would suggest I progress to get it all setup? Or indeed any frameworks already that fit my needs? I hope to be active here and look forward to being to give something back some day. Edit: after reading this through,, I realise I just described a kind of wiki, but thats not really what I had in mind- more just how the old school basic but very clean and functional sites were back in the day (meaning no disrespect to any of the newer ones!). Thank you for reading. is this a good way of doing a simple admin different rights e.g if secret word then go to adminpage.php Code: [Select] session_start(); $captcha = $_POST["captcha"] ; $secretword = $_SESSION["secretword"] ; if (strcmp( $captcha, $secretword )) { // it's a bot } else { // matched -- it's a human } |