PHP - Gd - Broken Image Problem
OK, hello everyone from your newest newbie - to this forum anyway.
First thing to say is I do not claim to be the best php coder there is - as you will see when you look at my code ! Secondly, I have scoured/googled many sources to try and understand an answer to my problem without success. So, please first look at this page - http://www.thepearsons-ws.co.uk/php/MetMonthly.php If you pick March 2011 say you see a list of data presented on the same page. This is the effect I want to get to with a GD graph. If you now try my first attempt - http://www.thepearsons-ws.co.uk/php/raingraph3monthlyselect.php - and pick March 2011 and Submit AND click the link you get a graph on a new page. OK, but now what I want - I want the image on that same first page. So, I have the attached code which produces this - http://www.thepearsons-ws.co.uk/php/raingraph3monthlyselect2.php I have hacked the code around a bit but basically it's - PHP - form and data selection HTML - form with pull downs PHP - display graph. The image is broken. If I remove the HTML block completely it produces output but of course I can not vary the selection. Any small element of HTML here destroys the image - no whitespace or such - just <html> is enough. So, any clues on how to correctly structure this code would be greatly appreciated. Regards Phil Similar TutorialsI recently changed hosts, now my image uploader which used to work fine doesn't work. $indeximage = $_FILES['indeximage']; if($indeximage) { $indeximagename = basename($_FILES['indeximage']['name']); $indeximagenew = $_SERVER['DOCUMENT_ROOT'] . '/images/uploaded/index/' . $indeximagename; if (!file_exists($indeximagenew)) { if ((move_uploaded_file($_FILES['indeximage']['tmp_name'], $indeximagenew)) === true) { echo 'Index Image uploaded to this address '; echo 'http://www.address.co.uk/images/uploaded/index/'; echo $indeximagename; echo '<br />'; }else { echo 'Unable to move Index Image into the right folder.'; } } } It now echos Unable to move Index Image into the right folder. I tried putting: ini_set("display_errors", "1"); error_reporting(E_ALL); at the beginning. Before the upload it reads: Notice: Undefined index: images in /var/www/vhosts/huhmagazine.co.uk/httpdocs/admin/images.php on line 58 Notice: Undefined index: indeximage in /var/www/vhosts/huhmagazine.co.uk/httpdocs/admin/images.php on line 62 After it reads: Warning: move_uploaded_file(): Unable to move '/tmp/phpTd67fh' to '/var/www/vhosts/huhmagazine.co.uk/httpdocs/images/uploaded/index/calidewitt.jpg' in /var/www/vhosts/huhmagazine.co.uk/httpdocs/admin/images.php on line 71 This code is creating broken image.please check it png and gd is enabled. i also remove the header but still getting broken image. there is no space before/after php tags.thanks you my code Code: [Select] <?php // Set the content-type header('Content-Type: image/png'); // Create the image $im = imagecreatetruecolor(400, 30); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); // The text to draw $text = 'Testing...'; // Replace path by your own font path $font = 'arial.ttf'; // Add some shadow to the text imagettftext($im, 20, 0, 11, 21, $grey, $font, $text); // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?> I get a php error...Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given $sql = "SELECT `pm_messages`.`conversation_id` FROM `pm_messages` GROUP BY `pm_messages`.`conversation_id` WHERE `pm_messages`.`conversation_id` = ${conversation['id']}"; $result = mysql_query($sql); $replies = mysql_fetch_assoc($result); Much of the PHP documentation is broken into very small pages. I find that this makes it very difficult to use. Does anyone else find this? I have a hackish but useful program which takes the PHP single-file documentation and splits it into one page per extension, ensuring that links between pages work correctly. It works quite well. I wonder if anyone else would find this useful? If so, then I should have time in the next few weeks to clean it up and make it publicly available. I copied the code for password_hash at php.net: <?php /** * In this case, we want to increase the default cost for BCRYPT to 12. * Note that we also switched to BCRYPT, which will always be 60 characters. */ $options = [ 'cost' => 12, ]; echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options); ?> and changed it for use in my login page:
$options = ['cost' => 12,]; $user = mysqli_real_escape_string($db_link,$_GET['username']); $pass = password_hash($_GET['password'], PASSWORD_BCRYPT, $options); but my page keeps saying invalid user/pass. Upon echoing the $pass I find that the result changes EACH time. so I created a test page that runs the code from php.net (verbatim code) 20x and I got: [pre]
$2y$10$Nlf0J520viR4C5jd3nIdd.6M3OMKACx503Jm3PiXDYZIs.13XAheq [/pre] Is password_hash broken? or am I mistaken to think that it's supposed to return the same output everytime fror the same input? Edited March 17, 2019 by Karaethontypos corrected this doesnt work and ive spent ages trying to figure it out
its the bit with else
<?php //CORS header header("Access-Control-Allow-Origin: *"); //Capture parameter $create = $_POST['create']; $fuser = $_POST['fuser']; if (!file_exists("uploads/$fuser/$create")); { if ($f = fopen("uploads/$fuser/$create", 'w')) { fwrite($f, 1); fclose($f); echo 'OK'; } } else { $f = fopen("uploads/$fuser/$create", 'w') fwrite($f, 5); fclose($f); echo 'FAIL' ; } ?>this bit does work below, its until i try to do else if , or else <?php //CORS header header("Access-Control-Allow-Origin: *"); //Capture parameter $create = $_POST['create']; $fuser = $_POST['fuser']; if (!file_exists("uploads/$fuser/$create")); { if ($f = fopen("uploads/$fuser/$create", 'w')) { fwrite($f, 1); fclose($f); echo 'OK'; } }help $compQ = "SELECT companies.companyid, companies.companyname, companies.companylogo, companies.companyoccupation, companies.industry, eQuestions.capitalrequested FROM companies LEFT JOIN eQuestions ON companies.companyid = eQuestions.companyid"; This is not displaying data correctly. I'm assuming eQuestions.capitalrequested is not in the correct spot? If I have a web page located he www . company . com / how-to-repair-your-computer.html
And I decide to re-structure my website like this www . company . com / articles / how-to-repair-your-computer.html
How do I make sure that people don't search and end up at the old, now broken, link?
It seem inevitable that as a website grows, that you will want to re-organize things. What is the best way to make sure that anyone who searches or clicks on an old link - say from an email from a friend - doesn't get a 404 error?
Also, how do you avoid ruining a web pages rank on Google after you move things? (I think if the URL changes, Google makes you start all over as far as getting listed on page-1 and all of that?
Is this something I have to hande on my end, or is it a Google issue, or something else?
[ m ]printf[/ m]produces a link to
php.net/<span>printf
Unless you use nobbc tags, then it works fine ???
Edited by Barand, 24 November 2014 - 02:25 PM. I'm very out of practice, and trying to figure out old broken code. From a previous search page, results are pulled from the database, and the variables are passed. At first it works, but then, when I click on the pagination links to see the next page of results, it stops working. The next page appears with no info. Here's the code, I think it has something to do with the passed variables toward the bottom of the code, but I can't figure out what to do. <code> <?php require ('databaseconnection'); $display = 2; // it's intentionally only 2 for the moment to test pagination if (isset($_GET['np'])) { $num_pages = $_GET['np']; } else { $data = "SELECT COUNT(*), `descriptors`.*, `plantae`.* FROM `descriptors` LEFT JOIN `plantae` ON (`descriptors`.`plant_id` = `plantae`.`plant_name`) WHERE `leaf_shape` LIKE '%$s1%' AND `leaf_venation` LIKE '%$s3%' AND `leaf_margin` LIKE '%$s4%'"; $result = mysql_query ($data); if (!$result) { die("Oops, my query failed. The query is: <br>$data<br>The error is:<br>".mysql_error()); } $row = mysql_fetch_array($result, MYSQL_NUM); //row 40 above seems to be where a problem is $num_records = $row[0]; if ($num_records > $display) { $num_pages = ceil ($num_records/$display); } else { $num_pages = 1; } } if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } if(isset($_GET[submitted])) { // Now collect all info into $item variable $shape = $_GET['s1']; $color = $_GET['s2']; $vein = $_GET['s3']; $margin = $_GET['s4']; // This will take all info from database where row tutorial is $item and collects it into $data variable $data = mysql_query("SELECT `descriptors`.* ,`plantae`.* FROM `descriptors` LEFT JOIN `plantae` ON (`descriptors`.`plant_id` = `plantae`.`plant_name`) WHERE `leaf_shape` LIKE '%$s1%' AND `leaf_venation` LIKE '%$s3%' AND 'leaf_margin' LIKE '%$s4%' ORDER BY `plantae`.`scientific_name` ASC LIMIT $start, $display"); //chs added this in... echo '<table align="center" cellspacing="0" cellpading-"5"> <tr> <td align="left"><b></b></td> <td align="left"><b></b></td> <td align="left"><b>Leaf margin</b></td> <td align="left"><b>Leaf venation</b></td> </tr> '; while($row = mysql_fetch_array($data)){ echo '<tr> <td align="left"> <a href="view_plant.php?id=' . $row['plant_name'] . '">View plant</a> </td> <td align="left"> </td> <td align="left">' . $row['scientific_name'] . '</td> <td align="left">' . $row['common_name'] . '</td> <td align="left">' . $row['leaf_shape'] . '</td> </tr>'; } echo '</table>'; } if ($num_pages > 1) { echo '<br /><p>'; $current_page = ($start/$display) + 1; if ($current_page != 1) { echo '<a href="leafsearch4c.php?s=' . ($start - $display) . '&np=;' . $num_pages . '&s1=' . $s1 . '&s2=' . $s2 . '&s3=' . $s3 . '&s4=' . $s4 . '">Previous</a> '; } for ($i = 1; $i <= $num_pages; $i++) { if($i != $current_page) { echo '<a href="leafsearch4c.php?s=' . (($display * ($i - 1))) . '$np=' . $num_pages . '&s1=' . $s1 . '&s2=' . $s2 . '&s3=' . $s3 . '&s4=' . $s4 .'">' . $i . '</a>'; } else { echo $i . ' '; } } if ($current_page != $num_pages) { echo '<a href="leafsearch4c.php?s=' . ($start + $display) . '$np=' . $num_pages . '&s1=' . $s1 . '&s2=' . $s2 . '&s3=' . $s3 . '&s4=' . $s4 .'"> Next</a>'; } } //added curly ?></code> Ok mixing javascript with php.... im having bugs . I basically want to replace any broken image links with a picture "noimage.gif" in the images folder. I tried this code but am getting the error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/showroom.php on line 78 This is the javascript header - all seems fine: <script language="JavaScript" type="text/javascript"> function ImgError(source){ source.src = "/images/noimage.gif"; source.onerror = ""; return true; } </script> this is the code thats erroring... is it the way ive written in the code into the IMG tag? while($row = mysql_fetch_array($result)){ echo "<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH=100% BORDER=0>"; echo "<TR />"; echo "<TD WIDTH=30% VALIGN=TOP />"; echo " <A HREF='images/".$row['photo']."' target=_blank><IMG SRC='images/".$row['photo']."' width=186 height=155 border=0 onerror="ImgError(this);" /></A> "; echo "<br />"; echo "</TD>"; echo "<TD WIDTH=10 VALIGN=TOP />"; Hi I am a php learner and I am having some problems while loading images from templates. I will explain everything so hope you can understand my question.. My Folder Structure WEB SITE NAME - index.php [default landing page] + Images [images folder] + css [css folder] + templates [templates folder] |-- header.inc.php [header template] |-- footer.inc.php [footer template] + includes [folder for all classes and variables] + js [folder for all js files] + contact-us [this is a folder] |--index.php [this is the file inside the contact-us folder] + about-us [this is a folder] |-- index.php [this is the file inside the about-us folder] This is the header.inc.php file [just a example to let you understand my problem] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "URL/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="URL/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Web Site Name</title> <link href="css/reset.css" rel="stylesheet" type="text/css" /> <link href="css/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script> </head> <body> <img src="images/phpmadeeasy.jpg" width="200" height="70" alt="php made easy logo" /> </body> ------------------------------------------------------------------------------ This is a sample main landing index.php page [i added codes only where i get into problems] <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ As you can guess, default index.php file works fine... load both logo and banner images but... this is the index.php file located under the about-us folder <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="../images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ Here only the banner image load because the template file still show the logo image path as "images/phpmadeeasy.jpg" instead of "../images/phpmadeeasy.jpg" so is there any way me to define the default image folder as a variable so i can use that variable to load images from any directory level Example: <?php echo $images; ?>images/phpmadeeasy.jpg" <script type="text/javascript" src="<?php echo $js; ?>/jquery-1.4.4.min.js" <link href="<?php echo $css; ?>reset.css" rel="stylesheet" type="text/css" Thanks........... Hi I am a php learner and I am having some problems while loading images from templates. I will explain everything so hope you can understand my question.. My Folder Structure WEB SITE NAME - index.php [default landing page] + Images [images folder] + css [css folder] + templates [templates folder] |-- header.inc.php [header template] |-- footer.inc.php [footer template] + includes [folder for all classes and variables] + js [folder for all js files] + contact-us [this is a folder] |--index.php [this is the file inside the contact-us folder] + about-us [this is a folder] |-- index.php [this is the file inside the about-us folder] This is the header.inc.php file without some html markups Quote <title>Web Site Name</title> <link href="css/reset.css" rel="stylesheet" type="text/css" /> <link href="css/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script> </head> <body> <img src="images/phpmadeeasy.jpg" width="200" height="70" alt="php made easy logo" /> </body> ------------------------------------------------------------------------------ This is a sample main landing index.php page [i added codes only where i get into problems] Quote <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ As you can guess, default index.php file works fine... load both logo and banner images but... this is the index.php file located under the about-us folder Quote <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="../images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ Here only the banner image load because the template file still show the logo image path as "images/phpmadeeasy.jpg" instead of "../images/phpmadeeasy.jpg" so is there any way me to define the default image folder as a variable so i can use that variable to load images from any directory level Example: Quote <?php echo $images; ?>images/phpmadeeasy.jpg" <script type="text/javascript" src="<?php echo $js; ?>/jquery-1.4.4.min.js" <link href="<?php echo $css; ?>reset.css" rel="stylesheet" type="text/css" Thanks........... So on my website I have a basic if statement that checks some arguments to see if a user can add another user as a friend. Well I had gotten that part down and for the longest time other people on my website have been able to use the feature. Now all of a sudden the if statement doesn't work? Why? Here is the statement: if ($privacy['privacy']['who_can_add'] == '1' AND $zext->user['id'] != '0' AND $zext->user['id'] != $u['id']) { $add_friend = $u['add_friend']; } of course if I put $add_friend outside the if statement, the button appears. How can a statment work one day but not the other? Is it an issue with my server? dump of $privacy: Code: [Select] $ => Array (4) ( | ['hide_o_status'] = Integer(1) 0 | ['who_can_view'] = Integer(1) 1 | ['who_can_add'] = Integer(1) 1 | ['who_can_contact'] = Integer(1) 1 ) dump of $zext->user['id']: Code: [Select] $ = String(2) "10" dump of $u['id']: Code: [Select] $ = String(2) "4" it all has correct information and the if statement has not been changed from before when it had worked and outputted $add_friend all day long. it worked until last night, i don't know what happened or why, php version has not been changed or anything. if anybody has any ideas on what's going on help would be much appreciated. Thanks, Matt. I have 2 pages in my flash site that call some PHP files. The pages are a feedback page and a locator page. When my server went from PHP4 to PHP5 both pages stopped displaying the content. When I load the flash pages with Fiddler open, fiddler shows a 500 error on the PHP files that the flash is calling. I'm certain my database connections are good, file paths have not changed since the server maintenance, and I have .htaccess files except they are blank. Can anyone advise what I can do to find where the problem is? I have the PHP code below that showed the 500 errors. Any help would be really appreciated. This is the locator page: Code: [Select] <?php include_once('db_connect.inc.php'); $query = "SELECT state FROM stores group BY state ORDER BY state"; $result = mysql_query($query); if(mysql_num_rows($result)==NULL){ $r_string = '&error=1&msg=No Records Found.'; }else{ $r_string = '&error=0&n='.mysql_num_rows($result) . '&r_states='; $i = 0; $r=''; while ($row = mysql_fetch_assoc($result)) { if($r!='') $r .= '||'; $r .= $row['state']; $i++; } $r_string .= $r; // add extra & to prevent returning extra chars at the end $r_string .='&'; } echo $r_string; ?> This is the feedback page: Code: [Select] <?php include_once('inc/feedbackconn.inc.php'); echo '&rsult='; $query = "SELECT * FROM messages where active!=0"; $result = mysql_query($query); $num = @mysql_num_rows($result); $cfeed=$_POST['sFeed']; $cfeed--; $query = "SELECT * FROM messages where active='1' ORDER BY id LIMIT " . $cfeed . ',1'; $result = mysql_query($query); //$row = mysql_fetch_array($result); if($num==NULL){ echo "No Records."; exit(); } while($row = @mysql_fetch_array($result)){ $b_name = stripslashes($row[strName]); $b_loc = stripslashes($row[strLocation]); $b_mes = stripslashes($row[strMessage]); $b_id = $row[id]; $b_active = $row[active]; $feedArray[] = array("name"=>$b_name,"location"=>$b_loc,"feedback"=>$b_mes,"id"=>$b_id,"active"=>$b_active); } /* /////////////// DISPLAY THE RECORDS ///////////////// */ $numOfMessages = sizeOf($feedArray); for($i=0;$i<$numOfMessages;$i++){ //------------------------------------------------------------------ //echo $feedArray[$i]['id']."<br>\n"; echo '<b><i>' . $feedArray[$i]['feedback']."</i><br><br>"; echo $feedArray[$i]['name']."<br>"; echo $feedArray[$i]['location']."</b>"; //--------------------------------------------------------------------- } echo '&tFeeds=' . $num; echo '&cFeed=' . $_POST['sFeed']; ?> Hey People, Im stuck right now and I need some fresh eyes. Seems this functions someone made that I gotta fix is broken Im assuming maybe a missing bracket or one out of place.. but.. Im not seeing it, ive been staring at it for far to long tryin to fix it find the issue etc.. and its eluding me. Right now the error I am getting is "unexpected $end" heres the function Code: [Select] function getlinkedinstoredContacts($user_id,$limit=10,$offset=1){ $query = $this->db->get_where('cm_user_linkedin_contacts', array('user_id' => $user_id,'same_company'=>'Y'),$limit,$offset); if ($query->num_rows() > 0){ $contacts = $query->result(); //Loop throught the contact list foreach ($contacts as $key => $contact){ $headline = $contact->headline; if (preg_match('/(at )| @ /', $headline)){$arr = preg_split('/(at )| @ /', $headline, 2);} elseif (preg_match('/,/', $headline)){$arr = preg_split('/,/', $headline, 2);} else{$arr[0] = $headline;$arr[1] = '';} $arr[0] = preg_replace('/^\s*/', '', $arr[0]); $arr[0] = preg_replace('/\s*$/', '', $arr[0]); $arr[1] = preg_replace('/^\s*/', '', $arr[1]); $arr[1] = preg_replace('/\s*$/', '', $arr[1]); $current_company_position = $arr[0]; // job_title $current_company_name=$arr[1]; //company //for testing if ($counter > 21){unset($contacts[$key]);} else{ $contact->job_title=$current_company_position; $contact->current_company=$current_company_name; if ($contact->picture_url == ''){ $contact->picture_url = $this->config->item('base_url') . "static/images/avatar-large.jpg')"; $contacts[$key]=$contact; $counter++; } } return $contacts; } return null; } Hey folks. okay, I took over the admin of a website ( http://www.annualclownsdirectory.com ) a while back. I have changed nothing in the php but there seems to be a problem with account activation. As a total newbie with php (I can work out what things do by reading the code, and can notice obvious mistakes but thats about it...) I have NO idea what is going on here to stop it working. If I make a test account the email is sent to me with the link to click on to activate the account, which looks like this: " http://www.annualclownsdirectory.com/confirm.php?id=330&hash=c6efb8f1d00beef170bd0df223ab87f1 " but when clicked the website throws up this: "Sorry, either this account is already active or it cannot be found, try logging in. If you have just created this account and are getting this error then please wait a couple of minutes and try again" Now when I check in myphpadmin the account is there, it's status is "unconfirmed" and I can't see anything wrong with the code (but as I say I am a total fresher here lol). I have attached register.php so you can see what is there. I can see no "md5" variable in the phpmyadmin section for clown_account. If any other files are needed please just say! And again, apologies for being useless! Sam / Bifford I want to reduce a picture size from 600px * 500px to 60px * 50px size, then crop it become 50px *50px. I have two groups of codes, 1 is to reduce the size of image, other 1 is to crop the image. The problem is they works separately, how to combine this two groups of codes to make them work together? Below is my codes : Code: [Select] <?php //codes of group A - Reduce the size of image from 600px * 500px to 60px * 50px $save2 = "images/users/" . $image_name_2; //This is the new file you saving list($width2, $height2) = getimagesize($file) ; $modwidth2 = 50; $diff2 = $width2 / $modwidth2; $modheight2 = $height2 / $diff2; $tn2 = imagecreatetruecolor($modwidth2, $modheight2) ; $image2 = imagecreatefromjpeg($file) ; imagecopyresampled($tn2, $image2, 0, 0, 0, 0, $modwidth2, $modheight2, $width2, $height2) ; imagejpeg($tn2, $save2, 100) ; //codes of group B - Crop the image from 60px * 50px to 50px * 50px $save3 = "images/users/" . $image_name_3; list($width3, $height3) = getimagesize($file) ; $modwidth3 = 60; $diff3 = $width3 / $modwidth3; $modheight3 = $height3 / $diff3; $left = 0; $top = 0; $cropwidth = 50; //thumb size $cropheight = 50; $tn3 = imagecreatetruecolor($cropwidth, $cropheight) ; $image3 = imagecreatefromjpeg($file) ; imagecopyresampled($tn3, $image3, 0, 0, $left, $top, $cropwidth, $cropheight, $modwidth3, $modheight3) ; imagejpeg($tn3, $save3, 100) ; //save the cropped image ?> As you can see from 2 groups of codes above, 1st group resize the pic then save it to a folder. 2nd group of codes crop the pic then save it into the folder too. My question is ... After 1st group of codes resize the picture, is it necessary to save it into folder before I can crop it? If it is necessary, then I need to write new lines of codes to retrieve the resized pic from the folder for 2nd group of codes to crop it? If it is not necessary, after resizing the pic, how do I pass the pic to 2nd group of codes to crop it? php image-resizing I have a very weird problem. On my website i have a script that takes random pages and displays them on the homepage. It works without a problem on its own but when i have it included in the homepage using include('webmaster fav.php'); i get this error: Warning: Cannot use a scalar value as an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 18 and this error: Warning: array_unique() [function.array-unique]: The argument should be an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 20 and this error: Warning: array_unique() [function.array-unique]: The argument should be an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 21 and this error: Warning: Cannot use a scalar value as an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 23 I am kindof new to php but i think its a good script and it works without errors when it isn't included on the homepage it works. what could be the problem? heres the code: <?php $directory = "/mnt/w0210/d28/s25/b02a8bb2/www/data/"; //the list of pages i want to be random on the site $directory = (!strstr($directory,"*") || $directory =="./" ) ? $directory."*" : $directory; //Checks if the wildcard operator is present, and if not it adds it by default at the end; $files = glob($directory); //Yes, it was that easy to get all the files; $size=sizeof($files); for($i=0;$i<sizeof($files) ; $i++){ //Loop through the files and adds to array; $fp = fopen($files[$i],"r"); $contents[$i]=fgets($fp,999); fclose($fp); } for($x=0;$x<15;$x++){ $numb[$x]=rand(1, sizeof($files)); } $x=count($numb)-count(array_unique($numb)); $num = array_unique ($numb); for($q=0;$x<15;$x++){ $numb[$x]=rand(1, sizeof($files)); } //$imploded = implode(" ", $contents); //get rid of spaces //$newcontent=explode("~", $imploded); // sort into chucks so i can display the data. for($i=0;$i<15; $i++){ $number=$num[$i]; if($contents[$number]==""||$contents[$number]==" "||$contents[$number]==null){ } else{ echo "<li>"; $replacedcontent=str_replace(' ', '-',$contents[$number]); echo "<br/><a href='games/$replacedcontent'>"; $newrcontent=str_replace('-', ' ',$replacedcontent); echo "<img src='$newrcontent.jpg' border='2'></img>"; echo "<br/>$newrcontent</a></li>"; } } ?> i copied and pasted it from many sites examples so thats why some comments are weird... but basically it gets all the data files. reads the title and puts them in an array, then chooses some random ones and puts them in with their image so they can be displayed on the homepage. Dear fourm, i am wondering if anyone can shed some light on this form submission problem with back/forward buttons. long story short: i used to make a form, then submit to a form process php file. errors were difficult to deal with. Thus, many people tell me to submit to the same page. I now submit to the same page. my homepage has a login button. i use a csrf token in a hidden input matched with a session variable. i decided to submit to same page and handle the submit like so: if server request-method = post and isset input name and isset session token then check the token with hash_equals if everything matches then show the login page. i don't have a problem with the form and the form submission processing. everything i fine. now when i use the browser refresh button on the login page, i am sent back to the homepage. all is good. when i press the back button, i go back to the homepage again. super. then i press the forward button in the browser and i get a not connected error. the back button now also shows this error. i tinkered around a bit and added crazy ideas and it worked one time with unset($_POST) as an else to the if mentioned above. the idea is that if server request-method is post without an else. the page is listed below for any get request to process. i assume that the browser is trying to repost data is empty but my if statement should kick it out to the get code, right? what i want is to unset the csrf token and the matching session token for security purposes. i suppose that this breaks the back/forward buttons? how can i get the browser to show the homepage regardless of the post situation? there must be a logical answer. something in my code is breaking this an preventing the browser from simply loading the home page any help is greatly appreciated! Thank you. |