premiso
Members-
Posts
6,951 -
Joined
-
Last visited
-
Days Won
2
Everything posted by premiso
-
foreach is the key: $state[1]="Alabama"; $state[2]="Alaska"; $state[3]="Arizona"; $state[4]="Arkansas"; $state[5]="California"; $state[6]="Colorado"; $state[7]="Connecticut"; $state[8]="Delaware"; $state[9]="Florida"; $state[10]="Georgia"; $state[11]="Hawaii"; $state[12]="Idaho"; foreach ($state as $num => $stateName) { echo "The number $num state alphabetically is: $stateName<br />"; } Basically that loops through the array $state and goes through each element and assigns the $num equal to the current number and $statename equal to the current value located at index of the current number.
-
isset returns a boolean, if you want to check the data in a cookie do this: if(isset($_COOKIE['skinid']) && $_COOKIE['skinid'] == "heelo") Will work, as it first checks if the cookie isset if it is then it tests the data in that cookie.
-
Well what are you planning on storing? As far as I know there is a 4kb limit on cookie lengths, a better alternative is storing the data in a database then having an access hash stored in the cookie and using that to pull the data out.
-
Just to fix his code: function findState($number, $state=array()) echo $state[$number]; } // pull index 1 out of state array. echo findState(1, $state);
-
You would have to do a check on the input string, if you only want a certain length use strlen. If that is not what you are after, please elaborate.
-
foreach may help you out, but if you are required to use a function as well as a loop, you need to revise your function and incorporate a for loop. The gist of arrays is they are access by the index, so $state[1] will pull Alabama out. So given that you can use a variable such as $i which is commonly used in a for loop as the counter to pull $state[$i] which will pull out whatever item is at index $i. Hopefully that helps. Are you taking this class to learn programming? Or just taking cause your major requires a Computer Science class?
-
Can php readfile a file in an htaccess pw protected directory?
premiso replied to rondog's topic in PHP Coding Help
Yes, as long as you are not trying to access that directory by curl. .htaccess only effects how it is accessed via the Webserver, not the server itself. (I probably worded that wrong but yea). -
Retrieve images (not just display them on the web page) from Blob
premiso replied to mosh's topic in PHP Coding Help
Using header's this can be accomplished: mysql_select_db("media",$link); $que="select imageBlob from images where imageId=10"; //imageBlob- name of the blob data type field in mysql. $ret=mysql_query($que)or die("Invalid query: " . mysql_error()); header("Content-type: image/jpeg"); header('Content-Disposition: attachment; filename="image.jpg"'); echo mysql_result($ret, 0); mysql_close($link); ?> Give that a shot and see if it does it how you want, you will have to accept the download. Another option is to save the image as a file on the host then after all files are saved you can zip up that directory etc, but yea hopefully you want to just save it -
how to copy a string to clipboard(thats been highlight_string() 'd)
premiso replied to emopoops's topic in PHP Coding Help
Honestly, I would mosey on over to the Javascript forum and ask the new question of what you would want to do, as it has turned into a javascript problem and they will probably know more than I would -
[function.file]: failed to open stream: No such file or directory
premiso replied to travelkind's topic in PHP Coding Help
Well the error is obvious, it cannot find the file. So you need to figure out the right path: $fcontents = file ('/html/beer/uploads/filename.csv'); Try that and see if it works. given that /html/beer etc is your webserver path. If it is not you need to fix that portion. -
search a string within a string and then add another string
premiso replied to oldtimer's topic in PHP Coding Help
They have not re-implemented that system yet -
You can change how long the session cookie is stored on the users computer through php.ini I believe. You extend that to infinite and yea, but that still does not account for the user not clicking the logout button. The problem here lies with the user, they do not have to click "logout", they can simple browse away or close the browser. So in order for this to work you have to do the leg work and make an inactive timeout essentially. Unfortunately you cannot force a user to logout without an automated job set to run at intervals to continually check if the user has been active or not for a period of time.
-
how to copy a string to clipboard(thats been highlight_string() 'd)
premiso replied to emopoops's topic in PHP Coding Help
You can find a smaller way to mimic PHP's htmlentities_decode that will work just fine. But you have to decode the string in order for it to copy correctly, unfortunately. -
Well first things first, $state is not in the scope of the function, you either need to make that a global or add it inside the function tags or else you cannot access it. Number 2, you never call an index of the state array and you never use sname, which I am not sure what it is suppose to do. Number 3, your findstate function does not give a number as the first argument it gives a string and the second argument seems to give nothing either (unless you just wrote those in there for an example). If you need help I would read up on variable scope and array's as they both will help you and once you get the basic function working with static values, you can then look into use a for loop to loop through and display the output like you want. The reason for me not giving any code is this seems like homework and you will not learn if I did it for you
-
strstr else if($submit && (empty($ContactEmail) || strstr('@', $ContactEmail))) { echo "<h4>You need to enter Email</h4> <br /> <a href=\"javascript:history.go(-1)\" onMouseOver=\"self.status=document.referrer;return true\">BACK</a> "; You also had some logic issues, cause I take it you were seeing if the email was valid as well, doing the if $submit and contactemail is empty or contactemail does not contain an @ then error out Hopefully that is what you were trying to get at.
-
User's online is often a hard thing to do. If you have access to CRON, you can create a php cron job and add a new column to your online table that says "last_activity" if that last activity is past x minutes then delete them from the table. I believe that is the only sure fire way to do it, as any useronline script you will find online does the same thing. You just have to remember to update the online table each page call the users make to keep them showing as active.
-
populate a $_REQUEST variable value from database record - how?
premiso replied to kelsofield's topic in PHP Coding Help
Was my instructions/logic not clear? <select name='dbs_<? echo $prod_prop_title?>'>[code] Is the only change you would need to do, adding that prefix will allow you to know which item in the request array you want to access on the next page. Then you would use the code I posted above to pull it out on the next page. -
how to copy a string to clipboard(thats been highlight_string() 'd)
premiso replied to emopoops's topic in PHP Coding Help
Interesting, well if it does not have to be put into an input or text area here is one option of doing it: <?php $string = highlight_string('<?php phpinfo(); ?><style> body{background:black;color:pink} </style>', true); //$string = htmlentities($string); ?> <SPAN ID="copytext" STYLE="height:150;width:162;background-color:pink"> <?php echo $string; ?> </SPAN> <TEXTAREA ID="holdtext" STYLE="display:none;"> </TEXTAREA> <BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON> <script type="text/javascript"> function ClipBoard() { var text = copytext.innerHTML; text = decoded = Encoder.htmlDecode(text.toString()); holdtext.innerText = text; Copied = holdtext.createTextRange(); Copied.execCommand("RemoveFormat"); Copied.execCommand("Copy"); } Encoder = { // When encoding do we convert characters into html or numerical entities EncodeType : "entity", // entity OR numerical isEmpty : function(val){ if(val){ return ((val===null) || val.length==0 || /^\s+$/.test(val)); }else{ return true; } }, // Convert HTML entities into numerical entities HTML2Numerical : function(s){ var arr1 = new Array(' ','¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','','®','¯','°','±','²','³','´','µ','¶','·','¸','¹','º','»','¼','½','¾','¿','à','á','â','ã','Ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','Ö','×','ø','ù','ú','û','Ü','ý','þ','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú','û','ü','ý','þ','ÿ','"','&','<','>','œ','œ','š','š','ÿ','ˆ','˜',' ',' ',' ','','','','','–','—','‘','’','‚','“','”','„','†','†','‰','‹','›','€','ƒ','α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ','σ','τ','υ','φ','χ','ψ','ω','α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ','ς','σ','τ','υ','φ','χ','ψ','ω','ϑ','ϒ','ϖ','•','…','′','′','‾','⁄','℘','ℑ','ℜ','™','ℵ','←','↑','→','↓','↔','↵','←','↑','→','↓','↔','∀','∂','∃','∅','∇','∈','∉','∋','∏','∑','−','∗','√','∝','∞','∠','∧','∨','∩','∪','∫','∴','∼','≅','≈','≠','≡','≤','≥','⊂','⊃','⊄','⊆','⊇','⊕','⊗','⊥','⋅','⌈','⌉','⌊','⌋','〈','〉','◊','♠','♣','♥','♦'); var arr2 = new Array(' ','¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','','®','¯','°','±','²','³','´','µ','¶','·','¸','¹','º','»','¼','½','¾','¿','À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','×','Ø','Ù','Ú','Û','Ü','Ý','Þ','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú','û','ü','ý','þ','ÿ','"','&','<','>','Œ','œ','Š','š','Ÿ','ˆ','˜',' ',' ',' ','','','','','–','—','‘','’','‚','“','”','„','†','‡','‰','‹','›','€','ƒ','Α','Β','Γ','Δ','Ε','Ζ','Η','Θ','Ι','Κ','Λ','Μ','Ν','Ξ','Ο','Π','Ρ','Σ','Τ','Υ','Φ','Χ','Ψ','Ω','α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ','ς','σ','τ','υ','φ','χ','ψ','ω','ϑ','ϒ','ϖ','•','…','′','″','‾','⁄','℘','ℑ','ℜ','™','ℵ','←','↑','→','↓','↔','↵','⇐','⇑','⇒','⇓','⇔','∀','∂','∃','∅','∇','∈','∉','∋','∏','∑','−','∗','√','∝','∞','∠','∧','∨','∩','∪','∫','∴','∼','≅','≈','≠','≡','≤','≥','⊂','⊃','⊄','⊆','⊇','⊕','⊗','⊥','⋅','⌈','⌉','⌊','⌋','〈','〉','◊','♠','♣','♥','♦'); return this.swapArrayVals(s,arr1,arr2); }, // Convert Numerical entities into HTML entities NumericalToHTML : function(s){ var arr1 = new Array(' ','¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','','®','¯','°','±','²','³','´','µ','¶','·','¸','¹','º','»','¼','½','¾','¿','À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','×','Ø','Ù','Ú','Û','Ü','Ý','Þ','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú','û','ü','ý','þ','ÿ','"','&','<','>','Œ','œ','Š','š','Ÿ','ˆ','˜',' ',' ',' ','','','','','–','—','‘','’','‚','“','”','„','†','‡','‰','‹','›','€','ƒ','Α','Β','Γ','Δ','Ε','Ζ','Η','Θ','Ι','Κ','Λ','Μ','Ν','Ξ','Ο','Π','Ρ','Σ','Τ','Υ','Φ','Χ','Ψ','Ω','α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ','ς','σ','τ','υ','φ','χ','ψ','ω','ϑ','ϒ','ϖ','•','…','′','″','‾','⁄','℘','ℑ','ℜ','™','ℵ','←','↑','→','↓','↔','↵','⇐','⇑','⇒','⇓','⇔','∀','∂','∃','∅','∇','∈','∉','∋','∏','∑','−','∗','√','∝','∞','∠','∧','∨','∩','∪','∫','∴','∼','≅','≈','≠','≡','≤','≥','⊂','⊃','⊄','⊆','⊇','⊕','⊗','⊥','⋅','⌈','⌉','⌊','⌋','〈','〉','◊','♠','♣','♥','♦'); var arr2 = new Array(' ','¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','','®','¯','°','±','²','³','´','µ','¶','·','¸','¹','º','»','¼','½','¾','¿','à','á','â','ã','Ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','Ö','×','ø','ù','ú','û','Ü','ý','þ','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú','û','ü','ý','þ','ÿ','"','&','<','>','œ','œ','š','š','ÿ','ˆ','˜',' ',' ',' ','','','','','–','—','‘','’','‚','“','”','„','†','†','‰','‹','›','€','ƒ','α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ','σ','τ','υ','φ','χ','ψ','ω','α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ','ς','σ','τ','υ','φ','χ','ψ','ω','ϑ','ϒ','ϖ','•','…','′','′','‾','⁄','℘','ℑ','ℜ','™','ℵ','←','↑','→','↓','↔','↵','←','↑','→','↓','↔','∀','∂','∃','∅','∇','∈','∉','∋','∏','∑','−','∗','√','∝','∞','∠','∧','∨','∩','∪','∫','∴','∼','≅','≈','≠','≡','≤','≥','⊂','⊃','⊄','⊆','⊇','⊕','⊗','⊥','⋅','⌈','⌉','⌊','⌋','〈','〉','◊','♠','♣','♥','♦'); return this.swapArrayVals(s,arr1,arr2); }, // Numerically encodes all unicode characters numEncode : function(s){ if(this.isEmpty(s)) return ""; var e = ""; for (var i = 0; i < s.length; i++) { var c = s.charAt(i); if (c < " " || c > "~") { c = "&#" + c.charCodeAt() + ";"; } e += c; } return e; }, // HTML Decode numerical and HTML entities back to original values htmlDecode : function(s){ var c,m,d = s; if(this.isEmpty(d)) return ""; // convert HTML entites back to numerical entites first d = this.HTML2Numerical(d); // look for numerical entities " arr=d.match(/&#[0-9]{1,5};/g); // if no matches found in string then skip if(arr!=null){ for(var x=0;x<arr.length;x++){ m = arr[x]; c = m.substring(2,m.length-1); //get numeric part which is refernce to unicode character // if its a valid number we can decode if(c >= -32768 && c <= 65535){ // decode every single match within string d = d.replace(m, String.fromCharCode(c)); }else{ d = d.replace(m, ""); //invalid so replace with nada } } } return d; }, // encode an input string into either numerical or HTML entities htmlEncode : function(s,dbl){ if(this.isEmpty(s)) return ""; // do we allow double encoding? E.g will & be turned into & dbl = dbl | false; //default to prevent double encoding // if allowing double encoding we do ampersands first if(dbl){ if(this.EncodeType=="numerical"){ s = s.replace(/&/g, "&"); }else{ s = s.replace(/&/g, "&"); } } // convert the xss chars to numerical entities ' " < > s = this.XSSEncode(s,false); if(this.EncodeType=="numerical" || !dbl){ // Now call function that will convert any HTML entities to numerical codes s = this.HTML2Numerical(s); } // Now encode all chars above 127 e.g unicode s = this.numEncode(s); // now we know anything that needs to be encoded has been converted to numerical entities we // can encode any ampersands & that are not part of encoded entities // to handle the fact that I need to do a negative check and handle multiple ampersands &&& // I am going to use a placeholder // if we don't want double encoded entities we ignore the & in existing entities if(!dbl){ s = s.replace(/&#/g,"##AMPHASH##"); if(this.EncodeType=="numerical"){ s = s.replace(/&/g, "&"); }else{ s = s.replace(/&/g, "&"); } s = s.replace(/##AMPHASH##/g,"&#"); } // replace any malformed entities s = s.replace(/&#\d*([^\d;]|$)/g, "$1"); if(!dbl){ // safety check to correct any double encoded & s = this.correctEncoding(s); } // now do we need to convert our numerical encoded string into entities if(this.EncodeType=="entity"){ s = this.NumericalToHTML(s); } return s; }, // Encodes the basic 4 characters used to malform HTML in XSS hacks XSSEncode : function(s,en){ if(!this.isEmpty(s)){ en = en || true; // do we convert to numerical or html entity? if(en){ s = s.replace(/\'/g,"'"); //no HTML equivalent as &apos is not cross browser supported s = s.replace(/\"/g,"""); s = s.replace(/</g,"<"); s = s.replace(/>/g,">"); }else{ s = s.replace(/\'/g,"'"); //no HTML equivalent as &apos is not cross browser supported s = s.replace(/\"/g,"""); s = s.replace(/</g,"<"); s = s.replace(/>/g,">"); } return s; }else{ return ""; } }, // returns true if a string contains html or numerical encoded entities hasEncoded : function(s){ if(/&#[0-9]{1,5};/g.test(s)){ return true; }else if(/&[A-Z]{2,6};/gi.test(s)){ return true; }else{ return false; } }, // will remove any unicode characters stripUnicode : function(s){ return s.replace(/[^\x20-\x7E]/g,""); }, // corrects any double encoded & entities e.g & correctEncoding : function(s){ return s.replace(/(&)(amp;)+/,"$1"); }, // Function to loop through an array swaping each item with the value from another array e.g swap HTML entities with Numericals swapArrayVals : function(s,arr1,arr2){ if(this.isEmpty(s)) return ""; var re; if(arr1 && arr2){ //ShowDebug("in swapArrayVals arr1.length = " + arr1.length + " arr2.length = " + arr2.length) // array lengths must match if(arr1.length == arr2.length){ for(var x=0,i=arr1.length;x<i;x++){ re = new RegExp(arr1[x], 'g'); s = s.replace(re,arr2[x]); //swap arr1 item with matching item from arr2 } } } return s; }, inArray : function( item, arr ) { for ( var i = 0, x = arr.length; i < x; i++ ){ if ( arr[i] === item ){ return i; } } return -1; } } </script> Notice I added an htmlEncode/Decode class which I found here: http://www.strictly-software.com/htmlencode Seems to work fine on my end. If you want what is being copied to be hidden, simple set the <span style="display:none;"> Hope that helps a bit EDIT: On a side note, if you wanted to use the php's htmlentities to put it into a textarea etc, the following would work: <?php $string = highlight_string('<?php phpinfo(); ?><style> body{background:black;color:pink} </style>', true); $string = htmlentities($string); ?> <SPAN ID="copytext" STYLE="height:150;width:162;background-color:pink"> <?php echo $string; ?> </SPAN> <TEXTAREA ID="holdtext" STYLE="display:none;"> </TEXTAREA> <BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON> <script type="text/javascript"> function ClipBoard() { var text = copytext.innerHTML; text = decoded = Encoder.htmlDecode(Encoder.htmlDecode(text.toString())); holdtext.innerText = text; Copied = holdtext.createTextRange(); Copied.execCommand("RemoveFormat"); Copied.execCommand("Copy"); } (For space sake I removed the htmlencode/decode functions, they will be needed for that to work). What I changed was basically in the copy clipboard javascript I decoded the innerText twice, which seemed to work. -
populate a $_REQUEST variable value from database record - how?
premiso replied to kelsofield's topic in PHP Coding Help
Well how about this, do you create the select dropdown menu or do you have access to that code? If you do, why not add a dbs_ before the name of the select, then you can easily access it using a foreach loop: <?php foreach ($_REQUEST as $key => $val) { if (strstr($key, "dbs_")) { $value = $val; break; } } echo "The key used was $key which contained $value for a value."; ?> If you can do it that way, much easier and way more efficient -
how to copy a string to clipboard(thats been highlight_string() 'd)
premiso replied to emopoops's topic in PHP Coding Help
Well, my bet is that the html is parsing the < > and thinking that is actual html code. <?php $string = highlight_string('<?php phpinfo(); ?><style> body{background:black;color:pink} </style>', true); $string = htmlentities($string); ?> <textarea><?php echo $string; ?></textarea> That should be what you are looking for: htmlentities -
Well where is the chat file located? It seems to me to be under: /home/nzmotorh/public_html/NZMotorhomeChat/src/pfcinfo.class.php Now that may not be the correct path, as you will have to actually go into your ftp client and see where it is. If there is no file there that is the wrong path go up some directories and continue looking.
-
how to copy a string to clipboard(thats been highlight_string() 'd)
premiso replied to emopoops's topic in PHP Coding Help
To highlight the string you have to copy it to a variable: <?php $string = highlight_string('<?php phpinfo(); ?><style> body{background:black;color:pink} </style>'); ?> To Copy it to the clipboard you will need JavaScript to do so, as PHP is server side it has no control what is copied to the client's clipboard. -
Just a question, is register_globals turned on?
-
SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.personid WHERE table1.age IN(18, 19, 23,9) ORDER BY table1.age Simple as that.
-
Either code all the checkboxes and use CSS to hide them, then onChange show the boxes or use AJAX to make a call back to the server and pull the data then display it on the page. Given that this is not really PHP related, moving to the Javascript forum.