PHP - Illegal String Offset
I am writing a script that downloads stock data and graphs the prices using libchart charting library. After downloading data to array $prices, I use the following line to add a new data point to my chart:
$serie1->addPoint(new Point($prices[$i]['date'], $prices[$i]['price']);
$prices contains both date and price keys. However, this throws off illegal string offset error for both keys. I have checked with isset, both variables contain values. I have also tried typecasting, date with (string) and price with (float), but these threw off new errors.
What could be causing the illegal string offset error? Is there a way to silence it?
Edited by codingcasually, 01 November 2014 - 03:55 AM. Similar TutorialsHi guys, why am i getting this error: Illegal string offset 'user_id' but when echo $value it brings the correct output. Thanks
$user_id = 5; $user_name = "obodo"; $_SESSION['test'] = array('user_id' => $user_id, 'user_name' => $user_name); foreach( $_SESSION['test'] as $value ) { echo $value['user_id']; //give error /* echo $value //works */ }
Ok, I am sure you have all come across this error before. I am trying to understand why this occurs in a straight forward (spelled out for the complete dumb ass) kind of way. I made the most simple script I could come up with that would produce the error, but I am still uncertain as to what causes it, or what the fix is. Here is the script. Using all the letters and numbers available I print the total characters in the string, run a for statement to print out each character in order from the string index, and get the error "Undefined String Offset 36". Which is the total number of characters in the string starting at 0. The test script can be accessed at the following url: http://icca.exiled-alliance.com/classtest.php $test = "abcdefghijklmnopqrstuvwxyz1234567890"; $b = "<br />"; echo $test; echo $b; echo "There are " .strlen($test). " characters in the above string"; echo $b; for($x=0;$x<=strlen($test);$x++){ echo $test[$x]. "-->number $x"; echo $b; } Can anyone clear up why that error pops up from the way I have this scripted. Hello, I have this script that I have been running a long time that is included in my site with a php include. It reads data from a cached file in an array. I noticed last night something has happened and it won't load in my site anymore and causes my site not to load. I determined this through various troubleshooting. Through the various troubleshooting I was able to get an error "Fatal error: Cannot use string offset as an array in /home4/mesquiu0/public_html/nws_alerts_scroller.php on line 44". This is strange because nothing has changed on my server or with this script. Also if I run it by itself it runs fine. http://www.mesquitew...ts_scroller.php but, when I include it in my site it won't load and I get the error. I am not sure what is causing this. I have done some research and it appears to be cause by a key as though it were an array of arrays. I just don't see it though.
Here is the portion of the code it is referring to.
// IF there are alerts if(!empty($atomAlerts)) { // IF there are alerts usort($atomAlerts, 'a_sort'); // sort locations foreach($atomAlerts as $aak => $aav) { // FOR EACH alert, get the data from the cache file $caav = count($aav); // count alerts for($i=0;$i<$caav;$i++) { // FOR EACH alert // assemble alert data $title[$i][0] = '<b>'.strtoupper($aav[$i][0]).'</b>'; @$adarray[$aav[$i][10].' '.$title[$i][0]] .= ' - <a href="'.$alertURL.'?a=' .$aav[$i][14].'#WA'.$aav[$i][13].'" title=" Details for '.$aav[$i][12] .' '.$aav[$i][0].'">' .$aav[$i][12] ."</a>"; } } }Here is a sample of the cached file the script reads from. $atomAlerts = array ( 'TXZ104' => array ( 0 => array ( 0 => 'Dense Fog Advisory', 1 => 'Expected', 2 => 'Minor', 3 => 'Likely', 4 => 1418136720, 5 => 1418148000, 6 => 'Anderson; Bell; Bosque; Collin; Comanche; Cooke; Coryell; Dallas; Delta; Denton; Eastland; Ellis; Erath; Falls; Fannin; Freestone; Grayson; Hamilton; Henderson; Hill; Hood; Hopkins; Hunt; Jack; Johnson; Kaufman; Lamar; Lampasas; Leon; Limestone; McLennan; Milam; Mills; Montague; Navarro; Palo Pinto; Parker; Rains; Robertson; Rockwall; Somervell; Stephens; Tarrant; Van Zandt; Wise; Young', 7 => 'DENSE FOG IS OCCURRING OVER THE REGION WHICH WILL CREATE VERY HAZARDOUS DRIVING CONDITIONS. SLOW DOWN...USE YOUR LOW BEAM HEADLIGHTS...AND LEAVE PLENTY OF DISTANCE BETWEEN YOU AND THE VEHICLE AHEAD OF YOU.', 8 => '...DENSE FOG ADVISORY NOW IN EFFECT UNTIL NOON CST TODAY... * LOCATION...ALL OF NORTH CENTRAL TEXAS. * VISIBILITY...WIDESPREAD VISIBILITY REDUCTIONS OF LESS THAN 1/4 OF A MILE. VISIBILITIES WILL BEGIN TO IMPROVE AFTER NOON. * IMPACTS...DENSE FOG WILL MAKE DRIVING HAZARDOUS.', 9 => '#F60', 10 => ' <img src="./images/FGY.gif" width="12" height="12" alt="Dense Fog Advisory" title=" Dense Fog Advisory" />', 11 => '56', 12 => 'Collin Co', 13 => '1', 14 => 'TXZ104', 15 => '', ), ),Any idea what might be causing this. I don't see anything right off the bat. Just strange it loads fine alone and the problem only happens and happened out of the blue when I include it in my site. I have tried to isolate it to see what might be conflicting with it but have been unsuccessful. I also would add it only errors and doesn't load when included in my site when there is an alert. Right now there is no alerts at the moment. There was alerts at the time this happened. -Thanks Edited by Texan78, 09 December 2014 - 02:19 PM. Hi, I know the problem that I am having is related to the change in PHP5 about strings and arrays, however I do not understand why my script is affected. It seems like I am not trying to add more variables to an array. I do not success in order solve the problem. Help me please: // Build View Array if ($view_result!=false) { $i=0; while ($view_row =@ mysql_fetch_array($view_result)){ $i++; $view_rows[$i] = $view_row; // build view_comments array if ($viewcomments=="yes") { $sql = "SELECT * FROM blog_comments WHERE nBlogId=".$view_row["nIdCode"]." ORDER BY nIdCode DESC"; $result = mysql_query($sql,$con); if ($result!=false){ $j=0; while ($comment_row =@ mysql_fetch_array($result)){ $j++; $view_comment_rows[$i][$j] = $comment_row; } } } } } else { $problem = "2"; } // increment view counter for either the single blog being shown // or ALL blogs being shown //The problem is here if ($view_rows[1]["nIdCode"]!="" && strpos($_SERVER["PHP_SELF"],"admin.php")==false){ if ($viewmode=="single"){ $blogid = $view_rows[1]["nIdCode"]; $sql = "UPDATE blog SET nViews=nViews+1 WHERE nIdCode=".$blogid; } else { for ($i=1;$i<=count($view_rows);$i++){ $blog_array[$i] = $view_rows[$i]["nIdCode"]; } $blogids = implode(",",$blog_array); $sql = "UPDATE blog SET nViews=nViews+1 WHERE nIdCode IN (".$blogids.")"; } $result = mysql_query($sql,$con); if ($result==false){ print "<li>Problem with SQL<br>[".$sql."]</li>\n"; } } } Last edited by sbarros (2011-01-08 18:21:52) I am writing a data scraping script but i am getting fatal error.Can someone please help me. My code:- Code: [Select] <?php $con = mysql_connect("localhost","root",""); mysql_select_db("cakeshop", $con); $test = '<form name="select"> <p><font color="#000000" size="3"><select name="city" size="1" onchange="self.location.href=this.options[this.selectedIndex].value"> <option value="xxxwi.htm">Wisconsin</option> <option value="xxxwy.htm">Wyoming</option> </select><br clear="all"> </font><font color="#000000" size="2">Click on the state below where you want to send cake<br> or use the pull down menu above </font> </form> '; preg_match_all('~<option\s+value="(.*?)">(.*?)</option>~', $test, $out); for($i=0;$i<=2;$i++) { $data = file_get_contents('http://xxx.com/'.$out[1][$i].''); preg_match_all('~<option\s+value="(.*?)">(.*?)</option>~', $data, $city); //$klimit = sizeof($city); $klimit = count($city[1]); for($k=2 ;$k < $klimit; $k++) { $data = file_get_contents('http://xxx.com/'.$city[1][$k].''); //Error on this line $regex = '~<td\s+colspan="2"\s+width="350"><font\s+size="2">\s+<b>\s+(.*?) <\/b><br>(.*?) <br>(.*?),\s+(.*?)\s+<br>(.*?), (.*?)\s+<BR><BR><font\s+size="2"><img\s+src="\.\.\/images\/phone1.gif"\s+align="left"\s+hspace="4"\s+alt\s+=(.*)>\s+-\s+Phone\s+#\s+(.*?)\s+<\/font>\s+<BR>\s+<font\s+size\s+="1">~'; preg_match_all($regex, $data, $final); $jlimit = count($final[1]); for($j=0 ;$j < $jlimit; $j++) { $name = $final[1][$j]; $name = mysql_real_escape_string($name); $address = $final[2][$j]; $address = mysql_real_escape_string($address); $city = $final[3][$j]; $city = mysql_real_escape_string($city); $state = $final[4][$j]; $state = mysql_real_escape_string($state); $pincode = $final[6][$j]; $pincode = mysql_real_escape_string($pincode); $telephone = $final[8][$j]; $telephone = mysql_real_escape_string($telephone); mysql_query("INSERT INTO cakeshop (name, address, city, state, pincode, telephone) VALUES ('$name', '$address', '$city', '$state', '$pincode', '$telephone')"); } } } mysql_close($con); echo "Data scraping completed"; ?> Error message :- Code: [Select] Fatal error: Cannot use string offset as an array in C:\Users\Booone\AppData\Roaming\NuSphere\PhpED\projects\scraping1.php Error is on this line "$data = file_get_contents('http://xxx.com/'.$city[1][$k].'');" My code Code: [Select] <?php set_time_limit (0); include("config.php"); $data = "<td><a href='/hospitals-in/Alabama'>Alabama</a></td> <td><a href='/hospitals-in/District-of-Columbia'>District of Columbia</a></td> <td><a href='/hospitals-in/Kentucky'>Kentucky</a></td> <td><a href='/hospitals-in/Montana'>Montana</a></td> <td><a href='/hospitals-in/Ohio'>Ohio</a></td> <td><a href='/hospitals-in/Texas'>Texas</a></td> <td><a href='/hospitals-in/Alaska'>Alaska</a></td> <td><a href='/hospitals-in/Florida'>Florida</a></td> <td><a href='/hospitals-in/Louisiana'>Louisiana</a></td> <td><a href='/hospitals-in/Nebraska'>Nebraska</a></td> <td><a href='/hospitals-in/Oklahoma'>Oklahoma</a></td> <td><a href='/hospitals-in/Utah'>Utah</a></td> <td><a href='/hospitals-in/America-Samoa'>America Samoa</a></td> <td><a href='/hospitals-in/Georgia'>Georgia</a></td> <td><a href='/hospitals-in/Maine'>Maine</a></td> <td><a href='/hospitals-in/Nevada'>Nevada</a></td> <td><a href='/hospitals-in/Oregon'>Oregon</a></td> <td><a href='/hospitals-in/Vermont'>Vermont</a></td> <td><a href='/hospitals-in/Arizona'>Arizona</a></td> <td><a href='/hospitals-in/Hawaii'>Hawaii</a></td> <td><a href='/hospitals-in/Maryland'>Maryland</a></td> <td><a href='/hospitals-in/New-Hampshire'>New Hampshire</a></td> <td><a href='/hospitals-in/Pennsylvania'>Pennsylvania</a></td> <td><a href='/hospitals-in/Virgin-Islands'>Virgin Islands</a></td> <td><a href='/hospitals-in/Arkansas'>Arkansas</a></td> <td><a href='/hospitals-in/Idaho'>Idaho</a></td> <td><a href='/hospitals-in/Massachusetts'>Massachusetts</a></td> <td><a href='/hospitals-in/New-Jersey'>New Jersey</a></td> <td><a href='/hospitals-in/Puerto-Rico'>Puerto Rico</a></td> <td><a href='/hospitals-in/Virginia'>Virginia</a></td> <td><a href='/hospitals-in/California'>California</a></td> <td><a href='/hospitals-in/Illinois'>Illinois</a></td> <td><a href='/hospitals-in/Michigan'>Michigan</a></td> <td><a href='/hospitals-in/New-Mexico'>New Mexico</a></td> <td><a href='/hospitals-in/Rhode-Island'>Rhode Island</a></td> <td><a href='/hospitals-in/Washington'>Washington</a></td> <td><a href='/hospitals-in/Colorado'>Colorado</a></td> <td><a href='/hospitals-in/Indiana'>Indiana</a></td> <td><a href='/hospitals-in/Minnesota'>Minnesota</a></td> <td><a href='/hospitals-in/New-York'>New York</a></td> <td><a href='/hospitals-in/South-Carolina'>South Carolina</a></td> <td><a href='/hospitals-in/West-Virginia'>West Virginia</a></td> <td><a href='/hospitals-in/Connecticut'>Connecticut</a></td> <td><a href='/hospitals-in/Iowa'>Iowa</a></td> <td><a href='/hospitals-in/Mississippi'>Mississippi</a></td> <td><a href='/hospitals-in/North-Carolina'>North Carolina</a></td> <td><a href='/hospitals-in/South-Dakota'>South Dakota</a></td> <td><a href='/hospitals-in/Wisconsin'>Wisconsin</a></td> <td><a href='/hospitals-in/Delaware'>Delaware</a></td> <td><a href='/hospitals-in/Kansas'>Kansas</a></td> <td><a href='/hospitals-in/Missouri'>Missouri</a></td> <td><a href='/hospitals-in/North-Dakota'>North Dakota</a></td> <td><a href='/hospitals-in/Tennessee'>Tennessee</a></td> <td><a href='/hospitals-in/Wyoming'>Wyoming</a></td>"; preg_match_all("~<td><a\s+href='(.*?)'>(.*?)</a></td>~", $data, $link); echo '<pre>'; echo print_r($link); echo '</pre>' ; $countlink = count($link[1]); for($i=0 ; $i < $countlink; $i++) { if (is_array($link)) { $sitelink = "http://www.xxx.com".$link[1][$i]; $hospitallink = file_get_contents("$sitelink"); preg_match_all("~<td><a href=\"/hospital/(.*?)\">(.*?)</a></td>~", $hospitallink, $hospitalinfo); $city = $link[2][$i]; $countinfo = count($hospitalinfo[1]); for($j=0 ; $j < $countinfo ; $j++) { $infolink = "http://www.xxx.com/hospital/".$hospitalinfo[1][$j]; $getinfo = file_get_contents("$infolink"); $regex = "~<b>Name:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>Address:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>Phone:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>Number\s+of\s+Beds:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>Type:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>System:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>Website:</b>\s+<a href=\"(.*?)\">(.*?)</a>\s+</p>\s+<p>\s+(.*?)</p>~s"; preg_match_all($regex, $getinfo, $critinfo); preg_match_all("~<li>\s+(.*?)</li>~s", $getinfo, $servinfo); preg_match_all("~<h4>Hospital\s+Quality\s+and\s+Rating\s+information</h4>\s+<p>Data\s+based\s+on\s+2010\s+Health\s+Quality\s+Alliance\s+database</p>\s+<p>\s+<b>(.*?)</b><br>\s+(.*?)</p>~s", $getinfo, $mortality); preg_match_all("/(\d+)?\.?(\d+)?%/", $mortality[2][0], $number); $name = $critinfo[1][0]; $address = preg_replace('/\s\s+/', ' ', $address); $number = implode(",", $number[0]); $servinfo = implode(",", $servinfo[1]); $sql = "INSERT INTO hospital (name, address, servinfo, mortality) VALUES ('$name', '$address', '$servinfo', '$number')"; $exec_sql = mysql_query($sql); } } } ?> print_r($link) shows this :- Code: [Select] Array ( [0] => Array ( [0] => Alabama [1] => District of Columbia [2] => Kentucky [3] => Montana [4] => Ohio [5] => Texas [6] => Alaska [7] => Florida [8] => Louisiana [9] => Nebraska [10] => Oklahoma [11] => Utah [12] => America Samoa [13] => Georgia [14] => Maine [15] => Nevada [16] => Oregon [17] => Vermont [18] => Arizona [19] => Hawaii [20] => Maryland [21] => New Hampshire [22] => Pennsylvania [23] => Virgin Islands [24] => Arkansas [25] => Idaho [26] => Massachusetts [27] => New Jersey [28] => Puerto Rico [29] => Virginia [30] => California [31] => Illinois [32] => Michigan [33] => New Mexico [34] => Rhode Island [35] => Washington [36] => Colorado [37] => Indiana [38] => Minnesota [39] => New York [40] => South Carolina [41] => West Virginia [42] => Connecticut [43] => Iowa [44] => Mississippi [45] => North Carolina [46] => South Dakota [47] => Wisconsin [48] => Delaware [49] => Kansas [50] => Missouri [51] => North Dakota [52] => Tennessee [53] => Wyoming ) [1] => Array ( [0] => /hospitals-in/Alabama [1] => /hospitals-in/District-of-Columbia [2] => /hospitals-in/Kentucky [3] => /hospitals-in/Montana [4] => /hospitals-in/Ohio [5] => /hospitals-in/Texas [6] => /hospitals-in/Alaska [7] => /hospitals-in/Florida [8] => /hospitals-in/Louisiana [9] => /hospitals-in/Nebraska [10] => /hospitals-in/Oklahoma [11] => /hospitals-in/Utah [12] => /hospitals-in/America-Samoa [13] => /hospitals-in/Georgia [14] => /hospitals-in/Maine [15] => /hospitals-in/Nevada [16] => /hospitals-in/Oregon [17] => /hospitals-in/Vermont [18] => /hospitals-in/Arizona [19] => /hospitals-in/Hawaii [20] => /hospitals-in/Maryland [21] => /hospitals-in/New-Hampshire [22] => /hospitals-in/Pennsylvania [23] => /hospitals-in/Virgin-Islands [24] => /hospitals-in/Arkansas [25] => /hospitals-in/Idaho [26] => /hospitals-in/Massachusetts [27] => /hospitals-in/New-Jersey [28] => /hospitals-in/Puerto-Rico [29] => /hospitals-in/Virginia [30] => /hospitals-in/California [31] => /hospitals-in/Illinois [32] => /hospitals-in/Michigan [33] => /hospitals-in/New-Mexico [34] => /hospitals-in/Rhode-Island [35] => /hospitals-in/Washington [36] => /hospitals-in/Colorado [37] => /hospitals-in/Indiana [38] => /hospitals-in/Minnesota [39] => /hospitals-in/New-York [40] => /hospitals-in/South-Carolina [41] => /hospitals-in/West-Virginia [42] => /hospitals-in/Connecticut [43] => /hospitals-in/Iowa [44] => /hospitals-in/Mississippi [45] => /hospitals-in/North-Carolina [46] => /hospitals-in/South-Dakota [47] => /hospitals-in/Wisconsin [48] => /hospitals-in/Delaware [49] => /hospitals-in/Kansas [50] => /hospitals-in/Missouri [51] => /hospitals-in/North-Dakota [52] => /hospitals-in/Tennessee [53] => /hospitals-in/Wyoming ) [2] => Array ( [0] => Alabama [1] => District of Columbia [2] => Kentucky [3] => Montana [4] => Ohio [5] => Texas [6] => Alaska [7] => Florida [8] => Louisiana [9] => Nebraska [10] => Oklahoma [11] => Utah [12] => America Samoa [13] => Georgia [14] => Maine [15] => Nevada [16] => Oregon [17] => Vermont [18] => Arizona [19] => Hawaii [20] => Maryland [21] => New Hampshire [22] => Pennsylvania [23] => Virgin Islands [24] => Arkansas [25] => Idaho [26] => Massachusetts [27] => New Jersey [28] => Puerto Rico [29] => Virginia [30] => California [31] => Illinois [32] => Michigan [33] => New Mexico [34] => Rhode Island [35] => Washington [36] => Colorado [37] => Indiana [38] => Minnesota [39] => New York [40] => South Carolina [41] => West Virginia [42] => Connecticut [43] => Iowa [44] => Mississippi [45] => North Carolina [46] => South Dakota [47] => Wisconsin [48] => Delaware [49] => Kansas [50] => Missouri [51] => North Dakota [52] => Tennessee [53] => Wyoming ) ) 1 Earlier it was giving an error without if (is_array($link)) { Code: [Select] Fatal error: Cannot use string offset as an array However after adding it, it wont go to /hospitals-in/District-of-Columbia which is $link[1][1]; Can someone please point me my mistake Hi, when I run my script I get the following error message. These are array variables I am passing into the playerAttack function. I can't figure out what is wrong it looks fine to me. Any help greatly appreciated. Thanks. Derek Code: [Select] attack posted Fatal error: Cannot use string offset as an array in C:\wamp\www\SUN_DRAGON_GAME\gamestart.php on line 202 Code: [Select] $currentMonster='octalisk'; ///////////////////////////////////////////////////////////battle//////////////////////////// //function monsterEncounter($echoMonster,$monsterImage) if(!empty($_POST['attack'])) { echo "attack posted"; playerAttack($currentMonster,$player['stats']['playerHitRollLow'],$player['stats']['playerHitRollHigh'], $player['stats']['playerDmgLow'],$player['stats']['playerDmgHigh'],$monsters['Ocean']['octalisk']['defense'],$monster['Ocean']['octalisk']['hp'],$player['faction']['Teardrop_Ocean_Protectors']); $doesItAttack=encounter($monsters['ocean']['octalisk']['seeInvis'],$monsters['ocean']['octalisk']['aggro'],$player['factions']['Teardrop_Ocean_Protectors']); //insert octalisk stats into monsterattack function. if($doesItAttack =='yes') { monsterAttack($currentMonster,$monsters['Ocean']['octalisk']['hitRollLow'],$monsters['Ocean']['octalisk']['hitRollHigh'] , $monsters['Ocean']['octalisk']['dmgLow'],$monsters['Ocean']['octalisk']['dmgHigh'], $player['stats']['playerDefense'],$player['stats']['playerHp'],$monsters['Ocean']['octalisk']['hp']); } else { echo "do nothing"; } } here is the attack function Code: [Select] function playerAttack($currentMonster,$hitRollLow,$hitRollHigh,$dmgLow,$dmgHigh,$monsterDefense, $monsterHp,$playerFaction) { echo "in player attack"; $playerRoll= rand($playerHitRollLow, $playerHitRollHigh); if($playerHitRoll>=$monsterDefense) { global $theMessage; //shit had to make it global $playerDamage= rand($playerDmgLow,$playerDmgHigh); $theMessage = "You have hit a ". $currentMonster." for "."<strong>". $playerDamage."</strong> points of damage!"; $monsterHp= $monsterHp- $playerDamage; $theMessage.=" The ".$currentMonster."'s hp is now ".$monsterHp; if($monsterHp<=0) { if($playerFaction<=0) { $theMessage="Your faction standing with ".$playerFaction. "could not possibly get any worse."; } } $theMessage.=" You have killed the ".$currentMonster. "Your faction standing with ".$playerFaction." is now ".$playerFaction-1; } else { global $theMessage; //WTF i dont know what im doing. $theMessage= " Whoa! You missed the ".$currentMonster; } } Hi, I'll be honest don't have a clue what I am doing but a friend asked me to look into her site, she gets the following error at the top of this page http://www.morairaluxuryvillas.com/rentals/villalist.php Warning: strpos() [function.strpos]: Offset not contained in string in /home/morairal/public_html/rentals/villalist.php on line 85 the code on the line 85 is: $secondfstemp = strpos($block1, ".", $firstfs); I am more than willing to look into but don't know where to start - anyone have any ideas? Thanks for your time:-) Hi, I am new to the forums. I am having an issue with a snippet of code that generates random strings. I have already searched the forums, but the fix that I found is already in my code. I am still receiving the error though and was wondering if there was something else going on that I didn't see. Here is my code: Code: [Select] $Data = 'Ahmet'.md5(mt_rand(0, 123456789)); $length = 30; $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $string = ''; $string2 = ''; for ($a = 0; $a < $length; $a++) { $pos = mt_rand(0, strlen($chars)-1); $string .= $chars{$pos}; $pos2 = mt_rand(0, (strlen($Data))-1); $string2 .= $chars{$pos2}; } I appreciate any help on this, as it is cluttering my system log table. Thanks. In a function of a php script there is the following code line: function convert_mails($source_path, $mail_file = '') { global $output_path; print "sp=$source_path"; // -- parameters must have a trailing backslash -- if ($source_path[strlen($source_path)] != '\\') $source_path .= '\\'; ... When running it yields the following error: sp=D:\storage\AABB.ACT\Archi0.FLD; Notice: Uninitialized string offset: 35 in D:\WAMP\www\test.php on line 67 where line 67 is the line with the "if" statement. So why and where is there an uninitialized string offset? How can I repair the code? Peter Yeah I know one of those questions
Like you guys are lawyers on standby or something.
I just wanted to discuss the idea of creating a website mock up for a business that exists but you researched and they don't have a website yet.
I guess how, is the next question in terms of getting their prices of products... but mainly what I was going to do was following along Google Map's street view and screenshot their business logos which are visible to the public eye.
Then create a mock up of a website to show them on a tablet.
What do you guys think?
Hi Guys, This should be a simple one. I am looking for the best way to ensure that any illegal characters are removed from an input. I have a user registration form and login page. What I want to do is prevent against sql injection and therefore should be limiting the characters that can be entered. For example I want a username to include only letters and numbers so I ideally want to strip out any white space, illegal characters such as " ' ( ) etc... My issue with this is with the password, I would ideally like the user to be able to put as complex a password as they would like, so how would i prevent against illegal characters in this instance?? Cheers Hi all, I'm working on this site which I'll soon ask the guys in the testing forum to have a peek at. It's essentially an online community that was a uni project that has spiraled and grown exponetially. I've spent many many hours in front of books and tutorals etc to put it together and as far as scripting goes, it seems to be fine. The problem i'm having...The tut's that I read / watched were using eregi_replace to protect text fields and this is now unsuported. I want my site to be as secure as it can be, within reason. I've tried using preg_replace instead and have searched for the syntax but i keep getting strang results. I'm working on the "bio" field at the moment and then when that works I can move on and a-ply the same idea to the other fields. This si what I have and what I've changed. if ($_POST['parse_var'] == "bio"){ $bio_body = $_POST['bio_body']; //$bio_body = str_replace("'", "'", $bio_body); (WAS TESTING THIS BUT NO JOY) //$bio_body = str_replace("`", "'", $bio_body); $bio_body = mysql_real_escape_string($bio_body); $bio_body = nl2br(htmlspecialchars($bio_body)); $bio = $_POST['bio']; $bio = eregi_replace("'", "'", $bio); (This works but is not as secure) $bio = eregi_replace("`", "'", $bio); $bio = mysql_real_escape_string($bio); $bio = nl2br(htmlspecialchars($_POST['bio'])); $sqlUpdate = mysql_query("UPDATE members SET bio='$bio' WHERE id='$id'"); and so on....} When I change it to str_replace if I type in don't the whole word is deleted. when I type in preg I get an error. Can someone please give me the correct code / syntax for getting the result I want. I just want to make sure that every single field that has a user input is protected against any malicious attacks. Thanks. Hey I wasn't able to add/edit some text to the mysql database because of some character how can i bypass them should i use the mysql_real_escape_string() ? if yes how do i make it work with the code i got? thaks <?php include "../configdb.php"; $id = $_GET['id']; if(isset($_POST['submit'])) { //global variables $name = $_POST['name']; $footer = $_POST['footer']; //run the query which adds the data gathered from the form into the database $result = mysql_query("UPDATE pages SET name='$name', footer='$footer' WHERE id='$id' ",$connect); echo "<b>Your Page have been edited successfully"; // echo "<meta http-equiv=Refresh content=2;url=index.php>"; } elseif($id) { $result = mysql_query("SELECT * FROM pages WHERE id='$id' ",$connect); while($row = mysql_fetch_assoc($result)) { ?> <h3>::Edit Page</h3> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?php echo $row['id']?>"> <input type="hidden" name="id" value="<?php echo $row['id']?>"> <textarea name="name"><?php echo $row['name']?></textarea> <input name="footer" size="40" maxlength="255" value="<?php echo $row['footer']?>"> <input type="submit" name="submit" value="Submit"> <?php } } ?> I need the following format for dat and time: date("Y-m-d H:i:s"); Now, I know the time offset and want to adjust the above. Let's say the GMT time offset is 1. How do I adjust it using the code above? I tried as an example date("Y-m-d H:i:s",3600); but that adjusted the time by 8 hours! hey guys im in a bit trouble trying to use window offset() function.
basically i have a fixed header and what im trying to accomplish is for when the user scroll past a certain point the header content will change...im not sure if im going about this the right way or even sure if it is possible with a fixed header.
any help would be grateful thank you
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <style type="text/css"> body{ margin:0px; background:#FFFFFF; } .header-cont { width:100%; position:fixed; top:0px; } .header { height:50px; background:#F0F0F0; border:1px solid #CCC; width:960px; margin:0px auto; } .content { width:960px; background: #F0F0F0; border: 1px solid #CCC; height: 2000px; margin: 70px auto; } </style> <script> $(window).scroll(function(){ var position = $('#position').offset().top; if ($(window).scrollTop() > position) { alert('hey'); // Change header content } }); </script> </head> <body> <div class="header-cont"> <div>FIXED HEADER</div> </div> <br /> <div id='position'></div> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> CONTENT HERE! </body> </html> hi... i'm getting an undefined offset for the associative arrays [28-46] in this format. $sql="INSERT INTO tableName (name1, name2, name3, name4... this goes all the way to name46) VALUES ('".$data[0]."', '".$data[1]."', '".$data[2]."', '".$data[3]."' ...this goes all the way to name46)"; $sqlData = mysql_query($sql); i have read that i can prevent the notices by doing the following, but it's not working for me: $sql="INSERT INTO tableName ( 'name1' => "isset(.$data[0].) ? $data[0] : 'default value'", 'name2' => "isset(.$data[1].) ? $data[1] : 'default value'", 'name3' => "isset(.$data[2].) ? $data[2] : 'default value'", 'name4' => "isset(.$data[3].) ? $data[3] : 'default value'", #this goes all the way to name46 )"; $sqlData = mysql_query($sql); can anyone please assist me? instead of js alert displaying the timezone offset, i would like the content of get_time_zone_offset() to be used as a php variable.
<script type="text/javascript"> function get_time_zone_offset( ) { var current_date = new Date(); return -current_date.getTimezoneOffset() / 60; } alert("The local time zone is: GMT " + get_time_zone_offset()); </script> Hello, my script worked great with no errors until I had to migrate to a new server, which is using cpanel/WHM, I have run Apache update and ensured curl is installed but I keep getting this in the error log. Here is part of the code, the error is PHP Notice: Undefined offset: 2 in /home/username/public_html/control/ajax/actions/currently_playing.php on line 59 and here is that section of code (line 59 is labled) Code: [Select] // Diaplays when sever is online but no song title } else { $title = str_replace('\'', '`', $split[6]); $title = str_replace(',', ' ', $title); $title = "$title"; // Diaplays song } } if($title) { $tmp = explode(" - ", $title); $artist = trim(str_replace("`", "'", $tmp[0])); $album = trim(str_replace("`", "'", $tmp[1])); $title = trim(str_replace("`", "'", $tmp[2])); //LINE 59 HERE $request = $this->albumGetInfo($artist, $album); $img = $request["album"]["image"][1]["#text"]; I have an array, $old_array, that looks like this (each line is a different index): 1|1|0|20|0|0 1|2|0|20|0|0 1|3|0|20|0|0 1|4|0|20|0|0 1|5|0|20|0|0 1|6|0|20|0|0 1|7|0|20|0|0 33|3|0|15|0|0 33|4|0|15|0|0 33|5|0|15|0|0 34|1|0|15|0|0 34|2|3|15|0|0 34|3|2|15|0|0 34|4|3|15|0|0 34|5|0|15|0|0 34|6|2|15|0|0 34|7|0|15|0|0 It is an array of strings, which are exploded to create other arrays. Anyways, then I have a foreach loop like this: foreach($old_array as $val) { $check = substr($val, 0, strpos( $val,'|',strpos($val,'|')+1)); $array_temp[ $check ] = TRUE; } I am getting this error (ONLY IN INTERNET EXPLORER!): Warning: strpos() [function.strpos]: Offset not contained in string in /home/pgagnon/public_html/chores_uni.html on line 131 Line 131 is this one: $check = substr($val, 0, strpos( $val,'|',strpos($val,'|')+1)); Why does this work in Firefox, Opera, Safari, Chrome, but not IE?? Microsoft can eat shit until it dies! |