Jump to content

Greywacke

Members
  • Posts

    510
  • Joined

  • Last visited

Everything posted by Greywacke

  1. hi frazto....the file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] ) function as far as i know might suit you better using the FILE_USE_INCLUDE_PATH flag (and according to the documentation on php.net for php 5) - it however only returns the files contents as a string. you would thus need to explode ( string $delimiter , string $string [, int $limit ] ) that string by delimiter - eg "\r\n" in order to have it as an array such as you expect i used this function to read and write the database connection include's contents in an admin site i am working on... $imagearray = explode('\r\n',file_get_contents('backgrounds.inc.php', FILE_USE_INCLUDE_PATH)); remember this include path would be relative thus the backgrounds.inc.php would need to be in the same directory as the file containing the above code. if in an ssi subdirectory from that, simply prefix in the string ssi/ if in an upper directory ../ lots of info in traversing paths from the current document - just for "php path" :)hope that helps
  2. after repairing some minor errors, and updating the code in the above post - the main issue still persists. it is not parsing the array by key but by index instead! :/how can i be sure to parse an array by key and not by index?
  3. hi again.okay...first off below is a function to flatten the array incase multilevel arrays were sent such as with zencart forms...secondly is a function that is supposed to calculate wether it is a page level variable to return or a post variable to request. the $ prefixing inside the string, is the key to a system variable.thirdly is the code. it gets the variables from the database after identifying the form by referer - but unfortunately the printed arrays do not return what is expected. the keys for the form values are numbers as can be seen in the arrays printed below the code.how is this? anybody feel up to the task lending a clearer eye? obviously the translation bit will not occur because this is not a zencart form. and these are the field values as output by the database, but it does not get them! :)obviously the second array printed is empty! ($userarr), but i cannot see why... these variables in the database are set in the admin environment... and do exist along with their types and $ signs...here is the relevant piece of code: function array_flatten($array, $return=array()) { foreach ($array as $key => $value) { if (is_array($value)) { $return = array_flatten($value,$return); } else { if ($value) { $return[] = $value; } } } return $return;}function newpost($key) { if (strstr($key,"$")!===false) { return $GLOBALS[$key]; } else { return $_POST[$key]; }}$referer = $_SERVER["HTTP_REFERER"];$tsql0 = "SELECT * FROM 32_webformconfigs WHERE text_FormWebLocation LIKE \"".$referer."%\";";$tresult0 = mysql_query_errors($tsql0, $conn, __FILE__ , __LINE__ , true );$trow0 = mysql_fetch_array($tresult0);$formid = $trow0["bigint_FormID"];$formname = $trow0["text_FormName"];$pmail = $trow0["text_FormMailerFromAddress"];$tsql1 = "SELECT * FROM 33_webformdetails WHERE bigint_FormID = ".$formid." AND text_DetailDescription = \"TRANS\";";$tresult1 = mysql_query_errors($tsql1, $conn, __FILE__ , __LINE__ , true );//$trow1 = mysql_fetch_array($tresult1);$trans = explode(";",$trow1["text_DetailValue"],7);$tsql2 = "SELECT * FROM 33_webformdetails WHERE bigint_FormID = ".$formid." AND text_DetailDescription = \"VTIGR\";";$tresult2 = mysql_query_errors($tsql2, $conn, __FILE__ , __LINE__ , true );$trow2 = mysql_fetch_array($tresult2);$incl_vtiger = $trow2["text_DetailValue"];$mailadds = array();$mailaddp = array();$mailaddl = array();$attribids = array();$suppliers = array();$supplierp = array();$attribsarr = array();$errmsg = array();$failure = 0;$success = 0;$ffail = 0;$fsucc = 0;$space = " ";$hash = "#";$obracket = "(";$cbracket = ")";$_POST = array_flatten($_POST,array());$dynarr = $_POST;$tsql6 = "SELECT * FROM 33_webformdetails WHERE bigint_FormID = ".$formid." AND text_DetailDescription = \"FIELD\" ORDER BY bigint_DetailID ASC;";$tresult6 = mysql_query_errors($tsql6, $conn, __FILE__ , __LINE__ , true );if ($tresult6) { while ($trow6 = mysql_fetch_array($tresult6)) { $val = explode(";",$trow6["text_DetailValue"]); switch ($val[1]) { case 1: // attributes foreach ($_POST as $key => $value) { if ($trans) { $key = translate($key,1); $value = translate($value,0); } if ($key == $val[0]) { if (str_in_array($key,$attribsarr)) { $attribsarr[$key] .= ", ".(($val[2]=="UPPER CASING")?strtoupper($value):($val[2]=="lower casing")?strtolower($value):($val[2]=="Sentence casing")?sentence_case($value):($val[2]=="Name Casing")?name_case($value):$value); } else { $attribsarr[$key] = (($val[2]=="UPPER CASING")?strtoupper($value):($val[2]=="lower casing")?strtolower($value):($val[2]=="Sentence casing")?sentence_case($value):($val[2]=="Name Casing")?name_case($value):$value); } } } break; case 2: // users foreach ($_POST as $key => $value) { if ($trans) { $key = translate($key,1); $value = translate($value,0); } if ($key == $val[0]) { if (str_in_array($val[3],$userarr)) { $userarr[$val[3]] .= ", ".(($val[2]=="UPPER CASING")?strtoupper($value):($val[2]=="lower casing")?strtolower($value):($val[2]=="Sentence casing")?sentence_case($value):($val[2]=="Name Casing")?name_case($value):$value); } else { $userarr[$val[3]] = (($val[2]=="UPPER CASING")?strtoupper($value):($val[2]=="lower casing")?strtolower($value):($val[2]=="Sentence casing")?sentence_case($value):($val[2]=="Name Casing")?name_case($value):$value); } } } break; case 3: // concat for ($i = 2; $i < count($val); $i++) { $dynarr[$val[0]] .= newpost($val[$i]); } break; default: $dynarr[$val[0]] = newpost($val[0]); } $dynarr[$val[0]] = newpost($val[0]); }}print_r($attribsarr);echo "<br />\n<br />\n";print_r($userarr);echo "<br />\n<br />\n";print_r($dynarr);echo "<br />\n<br />\n"; see it's creating the stored variables but not requesting them. why oh why would it flatten the $_POST array as indexes and no keys? :/ all variables are added to $dynarray - this output is the most informative (the last array)... it seems there is something wrong with the flatten_array function - but what and why? :)here is the admin interface i developed for adding fields/variables to be processed, and choosing a variable type and other values depending on field/variable types.Administrative Interface for Configuring Dynamic Form Handlerplease help meh with some clarity as to resolving this issue!
  4. hi there,this is just a question regarding possible php errors being displayed, wether it would be possible at all to replace the line breaks with \n and remove the html tags - so they can be written to a javascript document to be alerted in the browser instead of viewing source every time?all opinions and beliefs regarding this are welcome... i have tried to on this, and came up with a bunch of useless results! (php error remove line break) :/unfortunately i can't see how changing this would return the results i seek :/
  5. proper spelling was checked over and over and i never noticed i had the wrong db
  6. oh my word! my focus and clarity was not where it should have been :/i was viewing a different db in pma! test instead of production!*writes note to take more ginkgo biloba and highten the water intake* :)this issue is now RESOLVED
  7. yes i do. and even if i request other product codes, it works. it is supposed to limit to 1 in those requests - but looks more like its doing an involuntary limit 0 of sorts. that record exists in the database, as the screenshots prove to the % of the query you can see that was copied and pasted from the pages.unfortunately its bedtime for me, got a meeting first thing in the morning - will respond here when i get back - even if something comes to light :)what puzzles me though, is that it should be selecting the following record:and yet it does not. :/ i cannot see a problem with the mysql queries, however they are compiled...
  8. what i mean by rowcount is the amount of rows in the resultset from the query. there is one when run in PMA, but not from that php document qtpq.php...as can be seen here in these screenshots of Query A and Query B in PMA.and
  9. another interesting note, try request a different part number - such as RON504 instead of PZN65D0005CC with whatever discount value ($n) and it retrieves the values! however - PZN65D0005CC DOES exist in the table! :/Incl VAT - % DiscountorIncl VATfrustrating this is indeed...
  10. yes. for some reason it seems to be getting a rowcount of 0 when there is 1 0o } elseif (mysql_num_rows($result) < 1) {$err = "NOTICE #0500: An empty result set was returned by the query defined in ".$doc." on line ".$line--;} ps: also please note that the partnumber is exactly the same on both requests for price incl vat and price excl vat. it is also spat out by the page, saying it returns no records - however it does return one when tested in PMA.
  11. it spits out the correct query string values, and the correct sql query - when testing in pma it gets the value i am selecting!this is supposed to return the price including vat, from the given product code:Retail Including VATand this is supposed to return the price including var - a % discount:Retail Including - Discountyet when i test the sql queries generated in PMA, it selects the value required!this is the faulty piece of code, and for the life of me - i cannot find the fault. // some irrelevant linesif ($q < 50) {// some more irrelevant lines} else { $tsql = "SELECT CASE ".$q." WHEN 50 THEN # Retail Including VAT (28_pricelists.text_RetailExcluding * 1.14) WHEN 51 THEN # Retail Including VAT + Discount ((28_pricelists.text_RetailExcluding * 1.14) * (1 - ".$n." / 100)) END AS text_Result FROM 28_pricelists WHERE 28_pricelists.text_PartNumber = \"".$p."\" LIMIT 1;"; $result = mysql_query_errors($tsql , $conn , __FILE__ , __LINE__ , true ); if ($result) { if ($row = mysql_fetch_array($result)) { echo number_format(round($row["text_Result"],2),2); } mysql_free_result($result); }}echo "\n\nERROR ".mysql_errno($conn).": ".mysql_error($conn)." (s=".$s."&q=".$q."&d=".$d."&p=".$p."&n=".$n.")\n";echo " <sql>".join("\n",$sql)."</sql>\n";mysql_close($conn);?> the last two echo's print the following text: ERROR 0: (s=141&q=50&d=#&p=PZN65D0005CC&n=0) <sql>SELECT CASE 50 WHEN 50 THEN # Retail Including VAT (28_pricelists.text_RetailExcluding * 1.14) WHEN 51 THEN # Retail Including VAT + Discount ((28_pricelists.text_RetailExcluding * 1.14) * (1 - 0 / 100)) END AS text_Result FROM 28_pricelists WHERE 28_pricelists.text_PartNumber = "PZN65D0005CC" LIMIT 1;NOTICE #0500: An empty result set was returned by the query defined in /home/dwtphovu/public_html/intellisource.co.za/qtpq.php on line 213</sql> and ERROR 0: (s=141&q=51&d=#&p=PZN65D0005CC&n=5) <sql>SELECT CASE 51 WHEN 50 THEN # Retail Including VAT (28_pricelists.text_RetailExcluding * 1.14) WHEN 51 THEN # Retail Including VAT + Discount ((28_pricelists.text_RetailExcluding * 1.14) * (1 - 5 / 100)) END AS text_Result FROM 28_pricelists WHERE 28_pricelists.text_PartNumber = "PZN65D0005CC" LIMIT 1;NOTICE #0500: An empty result set was returned by the query defined in /home/dwtphovu/public_html/intellisource.co.za/qtpq.php on line 213</sql> yet - as mentioned, in PMA it returns 13580.1930 for the first query and 12901.18335000 for the second. i think something might be amiss in my mysql_query_errors function, here it is: function mysql_query_errors($sql, $conn, $doc, $line, $expret = false) { $line--; $err = ""; $result = mysql_query($sql); if (mysql_errno() > 0) { $err = "ERROR #".mysql_errno().": ".mysql_error()." in ".$doc." on Line ".$line; } elseif ($expret) { if (is_null($result)) { $err = "NOTICE #0504: A null value was returned by the query defined in ".$doc." on line ".$line--; } elseif ($result === false) { $err = "NOTICE #0502: A false value was returned by the query defined in ".$doc." on line ".$line--; } elseif ($result === true) { $err = "NOTICE #0501: A true value was returned by the query defined in ".$doc." on line ".$line--; } elseif (mysql_num_rows($result) < 1) { $err = "NOTICE #0500: An empty result set was returned by the query defined in ".$doc." on line ".$line--; } array_push($GLOBALS["sql"],$sql."\n",$err."\n"); } return $result;} i am afraid i cannot see it - does anyone else perhaps see it?
  12. hi there,my last problem on TruckCapXchange.com... the div that is supposed to cover the loading select option, is positioned by the following java script: function setOffset(el) { var _x = 0; var _y = 0; var _w = el.offsetWidth; var _h = el.offsetHeight; el.style.zIndex = 1; while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) { _x += el.offsetLeft - el.scrollLeft; _y += el.offsetTop - el.scrollTop; el = el.parentNode; } document.getElementById("ajaxbg").style.left = _x + "px"; document.getElementById("ajaxbg").style.top = _y + "px"; document.getElementById("ajaxbg").style.width = _w + "px"; document.getElementById("ajaxbg").style.height = _h + "px"; document.getElementById("ajaxbg").style.visibility = "visible"; //alert("Left: "+_x+"px\nTop: "+_y+"px\nWidth: "+_w+"px\nHeight: "+_h+"px");} passing the relative select object to the setOffset function - the correct sizes are retrieved, as shown by the alert - however, it keeps loading the div top left of the page as set by the css file! div#ajaxbg { font-size: 1px; position: absolute; z-index: 998; width: 125px; height: 17px; top: 0px; left: 0px; border: none; background: transparent url("images/ajax-bg.png") top left scroll repeat; text-align: center; vertical-align: middle;}div#ajaxloader { font-size: 1px; position: relative; z-index: 999; width: 16px; height: 16px; top: 1px; left: 54px; border: none; background: transparent url("images/ajax-loader.gif") top left scroll no-repeat; text-align: center; vertical-align: middle;} some direction as to why it is not positioning OVER the select fields in Firefox, would be appreciated if anybody has an inkling... the inline styles for a div should override the styles in the stylesheet - correct? :/note the loader div displaying when you initially load TruckCapXchange.com. it is supposed to position it over the Make div but it leaves it 10px,10px from top left of the document - even in firefox... :/i am at wits end here, PLEASE HELP!
  13. ah ok... i see the mistake now. in the select case of the php xml generator, there were two instances of case 2: !it was supposed to be 3 and continue to 4 - this has now been resolved!
  14. hi there,i have ran into the problem of querystring values, containing a "-", causing requesting this value to retrieve an empty string! :)despite using encodeURIComponent in the javascript, and sending the query string as "?q=3&Year=1999-2007" - Year is retrieved as "" :)the previous 3 requests send perfectly - such as "?q=0" to retrieve makes (which have 0 as parent), "?q=1&Make=FORD" to retrieve models (which have the sent make as parent), "?q=2&Model=F450" to retrieve years (which have the selected model as parent) - it just seems when i try include - in a querystring value for the year values in the database, it cancels the whole value out 0oan example of the compiled query for this is: SELECT * FROM 3_serviceattributes WHERE bigint_AttributeServiceID = 1 AND CONCAT(",",bigint_AttributeParentID,",") LIKE CONCAT("%,",(SELECT bigint_AttributeID FROM 3_serviceattributes WHERE text_AttributeDescription = "CabSize" AND text_AttributeValue = ""),",%") ORDER BY text_AttributeDescription ASC, text_AttributeValue ASC;NOTICE #0500: An empty result set was returned by the query defined in /home/dwtphovu/public_html/truckcapxchange.com/ajax_attribs.php on line 21 the php xml generating code is as follows: <?php/*TRUCKCAPXCHANGE ATTRIBUTE AJAX XML RESPONSEVersion 2.2.5*///set_time_limit(0);include("../intellisource.co.za/prod_5683194816/includes/content/dwtphovu_f3rr37y.php");$q = $_GET["q"];if (is_numeric($q)) { if ($q > 4 || $q < 0) { $q = 0; }} else { $q = 0;}function getrecords($data) { $search = (is_array($data))? "CONCAT(\",\",bigint_AttributeParentID,\",\") LIKE CONCAT(\"%,\",(SELECT bigint_AttributeID FROM 3_serviceattributes WHERE text_AttributeDescription = \"".$data[0]."\" AND text_AttributeValue = \"".$data[1]."\"),\",%\")" : "bigint_AttributeParentID = ".$data; $sql = "SELECT * FROM 3_serviceattributes WHERE bigint_AttributeServiceID = 1 AND ".$search." ORDER BY text_AttributeDescription ASC, text_AttributeValue ASC;"; $result = mysql_query_errors($sql , $conn , __FILE__ , __LINE__ , true ); if ($result) { while ($row = mysql_fetch_array($result)) { echo " <attrib name=\"".$row["text_AttributeDescription"]."\" value=\"".$row["text_AttributeValue"]."\" />\n"; } }}header("Content-type: text/xml; charset=utf-8");echo "<?xml version=\"1.0\"?>\n";echo "<root>\n";switch ($q) { case 1: // load models getrecords(array("Make",$_GET["Make"])); break; case 2: // load years getrecords(array("Model",$_GET["Model"])); break; case 2: // load cabsizes getrecords(array("Year",$_GET["Year"])); break; case 3: // load bedsizes getrecords(array("CabSize",$_GET["CabSize"])); break; default: // load makes getrecords(0);}echo " <sql>".xmlentities( ( (is_array($sql))?join("\n",$sql):$sql ) )."</sql>\n";echo "</root>";mysql_close($conn);?> and the javascript ajaxRequest function is as follows: function ajaxRequest(obj) { var job = obj.name; switch (job) { case "Model": // get models posAjax(obj); var i = document.truckcap.Make.selectedIndex; if (i>0) { var poststr = "?q=1" + "&Make=" + encodeURIComponent(document.truckcap.Make.options[i].text); alert(poststr); return makeRequest("GET", "ajax_attribs.php", poststr); } else { document.getElementById("ajaxbg").style.visibility = "hidden"; return false; } break; case "Year": // get years posAjax(obj); var i = document.truckcap.Model.selectedIndex; if (i>0) { var poststr = "?q=2" + "&Model=" + encodeURIComponent(document.truckcap.Model.options[i].text); alert(poststr); return makeRequest("GET", "ajax_attribs.php", poststr); } else { document.getElementById("ajaxbg").style.visibility = "hidden"; return false; } break; case "CabSize": // get cabsizes posAjax(obj); var i = document.truckcap.Year.selectedIndex; if (i>0) { var poststr = "?q=3" + "&Year=" + encodeURIComponent(document.truckcap.Year.options[i].text); alert(poststr); return makeRequest("GET", "ajax_attribs.php", poststr); } else { document.getElementById("ajaxbg").style.visibility = "hidden"; return false; } break; case "BedSize": // get bedsizes posAjax(obj); var i = document.truckcap.CabSize.selectedIndex; if (i>0) { var poststr = "?q=4" + "&CabSize=" + encodeURIComponent(document.truckcap.CabSize.options[i].text); alert(poststr); return makeRequest("GET", "ajax_attribs.php", poststr); } else { document.getElementById("ajaxbg").style.visibility = "hidden"; return false; } break; default: // get makes posAjax(obj); var poststr = "?q=0"; alert(poststr); return makeRequest("GET", "ajax_attribs.php", poststr); }} i can't seem to find anything googling on this, or how to resolve... any ideas? :/ the xml is generated by php and here whenever i use $_GET["Year"] - a blank value is returned!somebody please help!
  15. ahhhh!!! *kicks my own ######* i found i had missed setting the array sent to the addoptions function decently.it was supposed to be arr[0] and arr[1] not arr[0] and arr[1] :)Pierre.
  16. hi there,please have a look at TruckCapXchange.com. this page is done in html 4.0, annd is not my work - but why would the id="Makes" dropdown not be referenced by the xml returned? i have previewed the xml returned and it should return the object - but does not. somebody please help! the following is the script that adds the options: function addoption(arr) { for (var i = 0; i < arr.length; i++) { var opt = document.createElement('option'); opt.text = arr[i][1]; // attribute value opt.value = arr[i][1]; // attribute parent / value alert(arr[i][0]); var sel = document.getElementById(arr[i][0]); //attribute key try { sel.add(opt, null); // standards compliant; doesn't work in IE } catch(ex) { sel.add(opt); // IE only } }} the xml is being read with the following script: function alertContents(http_request) { if (http_request.readyState == 4) { // filter state changed var success = false; if (http_request.status == 200) { // filter errors var xmldoc = http_request.responseXML; // get response //alert(http_request.responseText); var arr = new Array(); var i = 0; var rows = xmldoc.getElementsByTagName("attrib"); for (var r = 0; r < rows.length; r++) { if (rows[r].attributes) { arr[i] = new Array(); arr[0] = rows[r].attributes.getNamedItem("name").nodeValue; arr[1] = rows[r].attributes.getNamedItem("value").nodeValue; } i++; } if (arr) addoption(arr); // mysql queries / failures if (xmldoc.getElementsByTagName("sql")[0]) { if (xmldoc.getElementsByTagName("sql")[0].firstChild) { var sql = xmldoc.getElementsByTagName("sql")[0].firstChild.data; if (sql != undefined) { alert(sql); } } } success = true; } else { success = false; alert('HTTP' + http_request.status + ': There was a problem with the request.'); } ajaxloading--; if (ajaxloading <= 0) document.getElementById("ajaxbg").style.visibility = "hidden"; return success; }} somebody please help!!!
  17. ahhh success at last ^^ decided to rather go with str_replace, matching and replacing on the enclosing quotes to be safe. also, i looked at the returned array via print_r - and it was not as expected at all. also added retrieval and setting of server and timezone, along with the user, pass and db from this connection include function strenclose($str, $chars) { return $chars.$str.$chars;}function putdbconfig($file = "") { //if ($_SERVER['HTTPS'] == "on") { $pattern = '/^\$conn = mysql_connect\("([a-zA-Z._0-9\-]+)", "([a-zA-Z_0-9]+)", "([a-zA-Z_0-9]+)"\);$'. '|^mysql_select_db\("([a-zA-Z_0-9]+)", \$conn\);$'. '|^date_default_timezone_set\([\'"]([A-Za-z0-9\/+-]+)[\'"]\);$/m'; $connstr = file_get_contents($file, FILE_USE_INCLUDE_PATH); //echo "<test>".$connstr."</test>\n"; // get data to be replaced preg_match_all($pattern,$connstr,$arr,PREG_PATTERN_ORDER); // replace the data in $arr[1] with the following posted array $arrget = array( strenclose($arr[1][0],"\""), // old dbsrvr strenclose($arr[4][1],"\""), // old dbname strenclose($arr[2][0],"\""), // old dbuser strenclose($arr[3][0],"\""), // old dbpass strenclose($arr[5][2],"\"") // old php_tz ); $arrput = array( strenclose($_POST["text_dbsrvr"],"\""), // new dbsrvr strenclose($_POST["text_dbname"],"\""), // new dbname strenclose($_POST["text_dbuser"],"\""), // new dbuser strenclose($_POST["text_dbpass"],"\""), // new dbpass strenclose($_POST["text_php_tz"],"\"") // new php_tz ); $connstr = str_replace($arrget,$arrput,$connstr); // overwrite $file with replaced data $ret = file_put_contents($file, $connstr, FILE_USE_INCLUDE_PATH | LOCK_EX); //echo "<test>".$ret."</test>\n"; $connstr = file_get_contents($file, FILE_USE_INCLUDE_PATH); // write data that was written below: if (preg_match_all($pattern,$connstr,$arr,PREG_PATTERN_ORDER)) { echo "<test>"; print_r($arr); echo "</test>\n"; echo " <conn dbsrvr=\"".$arr[1][0]."\" dbname=\"".$arr[4][1]."\" user=\"".$arr[2][0]."\" pass=\"".$arr[3][0]."\" php_tz=\"".$arr[5][2]."\" />\n"; } //}}function getdbconfig($file = "") { //if ($_SERVER['HTTPS'] == "on") { $pattern = '/^\$conn = mysql_connect\("([a-zA-Z._0-9\-]+)", "([a-zA-Z_0-9]+)", "([a-zA-Z_0-9]+)"\);$'. '|^mysql_select_db\("([a-zA-Z_0-9]+)", \$conn\);$'. '|^date_default_timezone_set\([\'"]([A-Za-z0-9\/+\-]+)[\'"]\);$/m'; $connstr = file_get_contents($file, FILE_USE_INCLUDE_PATH); //echo "<test>".$connstr."</test>\n"; if (preg_match_all($pattern,$connstr,$arr,PREG_PATTERN_ORDER)) { echo "<test>"; print_r($arr); echo "</test>\n"; echo " <conn dbsrvr=\"".$arr[1][0]."\" dbname=\"".$arr[4][1]."\" user=\"".$arr[2][0]."\" pass=\"".$arr[3][0]."\" php_tz=\"".$arr[5][2]."\" />\n"; } //}} this issue has now been RESOLVED (google is prolly tired of my regex searches by now tee hee)
  18. ok i have modified the $pattern to read as follows. $pattern = '/^\$conn = mysql_connect\("[a-zA-Z._0-9\-]+", "([a-zA-Z_0-9]+)", "([a-zA-Z_0-9]+)"\);$|^mysql_select_db\("([a-zA-Z_0-9]+)", \$conn\);$/m'; but unfortunately it still only returns the database user! <conn dbname="" user="testuser" pass="" /> regular expressions are giving me a headache again! :/
  19. would it not be possible to match two sets of strings inside a single php document's contents in one try? i tried using what i thought to be the OR clause in perl regular expressions (|). "/[color="#9ACD32"][\r\n]+[/color]mysql_select_db\(\"([^\"]*)\", \$conn\);[color="#FF8C00"][\r\n]+[/color][color="#FF0000"]|[/color][color="#9ACD32"][\r\n]+[/color]\$conn = mysql_connect\(\"[^\"]*\", \"([^\"]*)\", \"([^\"]*)\"\);[color="#FF8C00"][\r\n]+[/color]/" how would i match the connection details that exist in these two seperate places - stipulated below (the db user, db password and db name).somebody please help! has been pretty useless in finding this - as it keeps returning articles on pregnant girls - even searching preg_ :)the typical contents of the page that is loaded into $connstr, is as follows: <?php...//$conn = mysql_connect("localhost", "root", "");line 7: $conn = mysql_connect("localhost", "[b]testuser[/b]", "[b]testpassword[/b]");...line 361: mysql_select_db("[b]rootuser_5683194816_prod[/b]", $conn);...?> hence selecting [\n\r]+ as beginning and end of lines - as there are almost duplicate lines that are commented out (preceeded by //). but this does not match on either of these ... = other arbitrary code to the purpose of what we are dealing with here.somebody please help! :(it is still in connection with the putdbconfig and getdbconfig functions, but i cannot seem to find the problem - even on gingko giloba with an influx of water 0o really frustrating this :/ function putdbconfig($file = "") { //if ($_SERVER['HTTPS'] == "on") { $pattern = "/[color="#9ACD32"][\r\n]+[/color]mysql_select_db\(\"([^\"]*)\", \$conn\);[color="#FF8C00"][\r\n]+[/color][color="#FF0000"]|[/color][color="#9ACD32"][\r\n]+[/color]\$conn = mysql_connect\(\"[^\"]*\", \"([^\"]*)\", \"([^\"]*)\"\);[color="#FF8C00"][\r\n]+[/color]/"; $connstr = file_get_contents($file, FILE_USE_INCLUDE_PATH); echo "<test>".$connstr."</test>\n"; // get data to be replaced preg_match_all($pattern,$connstr,$arr,PREG_PATTERN_ORDER); // replace the data in $arr[1] with the following posted array $arr[0][0] = $_POST["text_dbuser"]; $arr[0][1] = $_POST["text_dbpass"]; $arr[0][2] = $_POST["text_dbname"]; preg_replace(preg_prepare($arr[1]),$arr[0],$connstr); // overwrite $file with replaced data file_put_contents($file, $connstr, FILE_USE_INCLUDE_PATH); // write data that was written below: if (preg_match_all($pattern,$connstr,$arr,PREG_PATTERN_ORDER)) { echo " <conn dbname=\"".$arr[1][2]."\" user=\"".$arr[1][0]."\" pass=\"".$arr[1][1]."\" />\n"; } //}}function getdbconfig($file = "") { //if ($_SERVER['HTTPS'] == "on") { $pattern = "/[color="#9ACD32"][\r\n]+[/color]mysql_select_db\(\"([^\"]*)\", \$conn\);[color="#FF8C00"][\r\n]+[/color][color="#FF0000"]|[/color][color="#9ACD32"][\r\n]+[/color]\$conn = mysql_connect\(\"[^\"]*\", \"([^\"]*)\", \"([^\"]*)\"\);[color="#FF8C00"][\r\n]+[/color]/"; $connstr = file_get_contents($file, FILE_USE_INCLUDE_PATH); echo "<test>".$connstr."</test>\n"; if (preg_match_all($pattern,$connstr,$arr,PREG_PATTERN_ORDER)) { echo " <conn dbname=\"".$arr[1][2]."\" user=\"".$arr[1][0]."\" pass=\"".$arr[1][1]."\" />\n"; } //}} i have printed the $connstr string - and it is the full content of the connection include. why will preg_match_all not work? <_<ps: the commented checking for https is while the isp sort out the configuration on the domain.
  20. DEPRECATED - PLEASE READ NEXT POSTokay *blushes*preg_match_all does not support use of arrays, so therefore i have updated the functions as follows: function putdbconfig($file = "") { //if ($_SERVER['HTTPS'] == "on") { $connstr = file_get_contents($file); // get data to be replaced preg_match_all("/$mysql_select_db\(\"([^\"]*)\", \$conn\);|$\$conn = mysql_connect(\"[^\"]*\", \"([^\"]*)\", \"([^\"]*)\");/",$connstr,$arr); // replace the data in $arr[1] with the following posted array $arr[0][0] = $_POST["text_dbuser"]; $arr[0][1] = $_POST["text_dbpass"]; $arr[0][2] = $_POST["text_dbname"]; preg_replace($arr[1],$arr[0],$connstr); // overwrite $file with replaced data file_put_contents($file, $connstr, FILE_USE_INCLUDE_PATH); // write data that was written below: if (preg_match_all("/$mysql_select_db\(\"([^\"]*)\", \$conn\);|$\$conn = mysql_connect(\"[^\"]*\", \"([^\"]*)\", \"([^\"]*)\");/",$connstr,$arr)) { echo " <conn dbname=\"".$arr[1][2]."\" user=\"".$arr[1][0]."\" pass=\"".$arr[1][1]."\" />\n"; } //}}function getdbconfig($file = "") { //if ($_SERVER['HTTPS'] == "on") { $connstr = file_get_contents($file, FILE_USE_INCLUDE_PATH); if (preg_match_all("/$mysql_select_db\(\"([^\"]*)\", \$conn\);|$\$conn = mysql_connect(\"[^\"]*\", \"([^\"]*)\", \"([^\"]*)\");/",$connstr,$arr)) { echo " <conn dbname=\"".$arr[1][2]."\" user=\"".$arr[1][0]."\" pass=\"".$arr[1][1]."\" />\n"; } //}} only question now, is how to enclose the individual returned array element strings in / - this is a perl regular expression (preg). any help here? sure in arr[0] it's easy - just concat a "/". around the posted values, but as far as i know it is not required in the replacement - only in the match - eg $arr[1]. the normal way to do it just seems awefully long winded. maybe i should write a function to go through an array and set them...
  21. DEPRECATED - PLEASE READ NEXT POSToops - i realised that the server was the same for wherever. it was the db that is connected to that differs across sites, not the server - and this is on line 361 of the include. mysql_select_db("dbowner_5683194816_prod", $conn); therefore i have changed the php functions as follows: function putdbconfig($file = "") { if ($_SERVER['HTTPS'] == "on") { $connstr = file_get_contents($file); // get data to be replaced preg_match_all(array("/$mysql_select_db\(\"([^\"]*)\", \$conn\);/","/$\$conn = mysql_connect(\"[^\"]*\", \"([^\"]*)\", \"([^\"]*)\");/"),$connstr,$arr); // replace the data in $arr[1] with the following posted array $arr[0][0] = $_POST["text_dbname"]; $arr[0][1] = $_POST["text_dbuser"]; $arr[0][2] = $_POST["text_dbpass"]; preg_replace($arr[1],$arr[0],$connstr); // overwrite $file with replaced data file_put_contents($file, $connstr, FILE_USE_INCLUDE_PATH); // write data that was written below: if (preg_match_all(array("/$mysql_select_db\(\"([^\"]*)\", \$conn\);/","/$\$conn = mysql_connect(\"[^\"]*\", \"([^\"]*)\", \"([^\"]*)\");/"),$connstr,$arr)) { echo " <conn dbname=\"".$arr[1][0]."\" user=\"".$arr[1][1]."\" pass=\"".$arr[1][2]."\" />\n"; } }}function getdbconfig($file = "") { if ($_SERVER['HTTPS'] == "on") { $connstr = file_get_contents($file, FILE_USE_INCLUDE_PATH); if (preg_match_all(array("/$mysql_select_db\(\"([^\"]*)\", \$conn\);/","/$\$conn = mysql_connect(\"[^\"]*\", \"([^\"]*)\", \"([^\"]*)\");/"),$connstr,$arr)) { echo " <conn dbname=\"".$arr[1][0]."\" user=\"".$arr[1][1]."\" pass=\"".$arr[1][2]."\" />\n"; } }} i'm thinking i need to replace all the elements in the arrays with / beginning and / ending within the strings, if i am to use preg_replace. any recommendations?
  22. DEPRECATED - PLEASE READ NEXT POSThi there,i have an idea more or less of how this can be done... but the finer details puzzle me slightly, i have - for the following first 7 lines of the include: <?php/*MYSQL CONNECTION INCLUDEVersion 2.2.5*///$conn = mysql_connect("localhost", "root", "");$conn = mysql_connect("fakeserver", "fakeusername", "fakepassword"); sofar written a rough draft of the following two functions, both to return the data set in the file and the data retrieved from the file, the first function to write to the file with the new data posted. function putdbconfig($file = "") { if ($_SERVER['HTTPS'] == "on") { $connstr = file_get_contents($file); // get data to be replaced preg_match_all("/$\$conn = mysql_connect\((\"[^\"]*\"), (\"[^\"]*\"), (\"[^\"]*\")\);/",$connstr,$arr); // replace the data in $arr[0] with the following requested connection data $arr[0][0] = "\"".$_POST["svr"]."\""; $arr[0][1] = "\"".$_POST["usr"]."\""; $arr[0][2] = "\"".$_POST["pwd"]."\""; // replace existing connection data with requested connection data preg_replace($arr[1],$arr[0],$connstr); // overwrite $file with replaced connection data file_put_contents($file, $connstr); // write data that was written to xml: if (preg_match_all("/$\$conn = mysql_connect(\"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\");/",$connstr,$arr)) { echo " <conn server=\"".$arr[1][0]."\" user=\"".$arr[1][1]."\" pass=\"".$arr[1][2]."\" />\n"; } }}function getdbconfig($file = "") { if ($_SERVER['HTTPS'] == "on") { $connstr = file_get_contents($file); if (preg_match_all("/$\$conn = mysql_connect(\"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\");/",$connstr,$arr)) { echo " <conn server=\"".$arr[1][0]."\" user=\"".$arr[1][1]."\" pass=\"".$arr[1][2]."\" />\n"; } }} the end goal is to allow only via an ssl/tls ajax query (thus only making accessible to ssl ajax requests), the retrieval of the database connection settings - also allowing setting of it via the admin interface developed.is this a good idea? am i going about it in a feasible fashion? i do struggle somewhat with regular expressions... any opinions, suggestions, ideas etc (feedback) is 100% welcome.
  23. hi there,unfortunately i cannot find all the possible values for setting this to on a mysql 5.0.91 server... i find no reference to it! the reason why i ask is because timezones are given in various formats and so forth world wide - and i need to set the timezone on the page for the location the site installation is made for. does anybody know where i could get this? in the timezone conversion class, the possible timezones are set in the php documents - but i have no idea what the possible time_zone values for the page scope would be.
  24. well unfortunately this section of the project has been parked for now. i will get back with the function when i have done it
  25. well unfortunately this section of the project has been parked for now. i will get back with the function when i have done it
×
×
  • Create New...