-
Posts
250 -
Joined
-
Last visited
Everything posted by greenace92
-
This is great, I opened up that PSR-1 and PSR-2 link, thanks guys will refer to these posts for future projects and hopefully ingrain them into my own coding process. ginerjm This is what I took down from your post, I'm not used to placing the initial bracket after one linebreak after the closing parenthesis I do this: function name() { } as maxxd shows maxxd I like the commenting style which shows how far the comments go down by the asterisks on the left side It's weird but I haven't used classes in PHP at all... not sure if that is a bad thing. Why did you write the following: public $notAGoodIdea; Ahh man there is a lot here, nice. Will refer back to this thread.
-
Safe input using parameterized binding and escaping / other methods?
greenace92 replied to greenace92's topic in MySQL Help
Oh man, Thank you very much Jacques1, bookmarked! Going to implement these standards you mentioned for future projects. How would I know if an input is not emulated? I see this Will have to re-read thoroughly -
This is probably a problem, I changed the first array value from 8 to 3, and the output was Not a magical square not a magical square this 2D array is a magical array The last one that compares everything should not have passed so resulting in "...is a magical square"... ahhh Yeap... if one passes, they all pass oh... I guess I just had to change the && to || Well, this is my stab at this for now... Have to improve by using significantly less code and scalability
-
It's pretty sad to think that I've worked on this magic square for several hours over the course of three days. With sleep deprivation mind you. I realize that this is super long. I don't know how the "Magic Square" would be given to me, but in this scenario I simply included an existing magic square. Side note, I realized this is what Sudoko is right? Crazy... Anyway, I also realize that I could have done this much shorter, like any iteration of the same function where I incremented the $i value or any value by 1, I could have passed a function argument variable or list, and incremented that by one when calling the function. I tried that, I'm not sure why this doesn't work: <?php function rowSum($inc_row) { $GLOBALS['vertical_sum'] = 0; $vsum = $GLOBALS['vertical_sum']; for($i=0; $i<=2; $i++){ $convert = (int)$string_parts[$i+$inc_row]; $vsum = $vsum+$convert; return $vsum; echo $vsum; } } rowSum(0); ?> At any rate, this is what I created that does work, this is a perfect example of "blunt-force engineering" just a random term I thought of a while ago where I kept trying by smashing things together without actually figuring out what was wrong until it worked. Lost a lot of RC parts that way... Yeah I'm really going about this the dumb way, there are several things that I could easily get rid of by "smart coding" eg. coding efficiency. For example, comparing every value, I realize that it works off the function n(n-1) where n is the number of things being compared to each other. So 8 variant rows being compared is 8*7 = 56 comparisons = dumb Wait I think I found a solution (writing into response page while trying to finish code) This doesn't work, but I found out about in_array <?PHP $a = 2; $b = 3; $c = 4; $d = 5; if($a!=$b!=$c!=$d){ echo "not equal"; }else{ echo "comparison failed"; } ?> Actually I don't think this in_array will work "Transitive relation" I'm not sure if it is testing from left to right or if all have to be true in order to pass... as in the outer left most compares to the outer right most. Ahh man... it just occurred to me this test is not scalable to different size 2D arrays... it's only designed for 3x3 and not even 2x2. Wow... alright have to learn how to make perhaps even a single row iterating function, and a single summing function to do this and have it scale to whatever input. This is only designed for one array size. Funny you can't even tell what is going on when you run it, it just says "This 2D array is a magical square" <?PHP ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); // build sample array $array = array(); // bottom row $array[0][0] = 8; $array[1][0] = 1; $array[2][0] = 6; // middle row $array[0][1] = 3; $array[1][1] = 5; $array[2][1] = 7; // top row $array[0][2] = 4; $array[1][2] = 9; $array[2][2] = 2; // access array and store into string to be split $GLOBALS['value-chain'] = ""; foreach ($array as $x) { foreach ($x as $y) { $GLOBALS['value-chain'] = $GLOBALS['value-chain'].$y; $short = $GLOBALS['value-chain']; } } // perform preliminary test of diagonal direction-up and down sum, // one vertical row, and one horizontal row, // if pass continue to full test // change order of string // first three horizontal, could sum while I'm at it $horizontal_string = ""; $string_parts = str_split($short); $new_i = 0; for ($i=0; $i<=2; $i++) { if($i!=0){ $new_i = $new_i+3; $horizontal_string = $horizontal_string.$string_parts[$new_i]; }else { $horizontal_string = $horizontal_string.$string_parts[$i]; } } // second three horizontal $new_i_2 = 1; for ($i=1; $i<=3; $i++) { if($i!=1){ $new_i_2 = $new_i_2+3; $horizontal_string = $horizontal_string.$string_parts[$new_i_2]; }else { $horizontal_string = $horizontal_string.$string_parts[$i]; } } // last three horizontal $new_i_3 = 2; for ($i=2; $i<=4; $i++) { if($i!=2){ $new_i_3 = $new_i_3+3; $horizontal_string = $horizontal_string.$string_parts[$new_i_3]; }else { $horizontal_string = $horizontal_string.$string_parts[$i]; } } // horizontal string now exists // echo '<br>'.'horizontal string'.$horizontal_string; // diagonal up-direction $string_parts_h = str_split($horizontal_string); $dsumu = ((int)$string_parts_h[0])+((int)$string_parts_h[4])+((int)$string_parts_h[8]); // diagonal down-direction $dsumd = ((int)$string_parts_h[6])+((int)$string_parts_h[4])+((int)$string_parts_h[2]); // compare if(($dsumu != $dsumd)){ echo "Not a magical square"; } // continue to vertical test // vertical sum left $string_parts = str_split($short); $GLOBALS['vertical_sum_1'] = 0; $vsum1 = $GLOBALS['vertical_sum_1']; for($i=0; $i<=2; $i++){ $convert = (int)$string_parts[$i]; $vsum1 = $vsum1+$convert; } // echo '<br>'.'<br>'.$vsum1; // compare 2 if(($dsumu != $dsumd) && ($dsumd != $vsum1)){ echo "Not a magical square"; } // continue to horizontal test // sum horizontal bottom $string_parts_h = str_split($horizontal_string); $GLOBALS['horizontal_sum_1'] = 0; $hsum1 = $GLOBALS['horizontal_sum_1']; for($i=0; $i<=2; $i++){ $convert_h1 = (int)$string_parts_h[$i]; $hsum1 = $hsum1+$convert_h1; } // echo '<br>'.'this is horizontal sum '.' '.$hsum1; // compare 3 if(($dsumu != $dsumd) && ($dsumd != $vsum1) && ($vsum1 != $hsum1)){ echo "Not a magical square"; } // full test // rest of vertical // vertical sum middle $GLOBALS['vertical_sum_2'] = 0; $vsum2 = $GLOBALS['vertical_sum_2']; for($i=0; $i<=2; $i++){ $convert2 = (int)$string_parts[$i+3]; // +3 shifts string array position $vsum2 = $vsum2+$convert2; } // compare 4 if(($dsumu != $dsumd) && ($dsumd != $vsum1) && ($vsum1 != $hsum1) && ($hsum1 != $vsum2)){ echo "Not a magical square"; } // vertical sum right $GLOBALS['vertical_sum_3'] = 0; $vsum3 = $GLOBALS['vertical_sum_3']; for($i=0; $i<=2; $i++){ $convert3 = (int)$string_parts[$i+6]; // +6 shifts string array position $vsum3 = $vsum3+$convert3; } // compare 5 if(($dsumu != $dsumd) && ($dsumd != $vsum1) && ($vsum1 != $hsum1) && ($hsum1 != $vsum2) && ($vsum2 != $vsum3)){ echo "Not a magical square"; } // rest of horizontal // sum horizontal middle $GLOBALS['horizontal_sum_2'] = 0; $hsum2 = $GLOBALS['horizontal_sum_2']; for($i=0; $i<=2; $i++){ $convert_h2 = (int)$string_parts_h[$i+3]; // +3 shifts string array position $hsum2 = $hsum2+$convert_h2; } // compare 6 if(($dsumu != $dsumd) && ($dsumd != $vsum1) && ($vsum1 != $hsum1) && ($hsum1 != $vsum2) && ($vsum2 != $vsum3) && ($vsum3 != $hsum2)){ echo "Not a magical square"; } // sum horizontal top $GLOBALS['horizontal_sum_3'] = 0; $hsum3 = $GLOBALS['horizontal_sum_3']; for($i=0; $i<=2; $i++){ $convert_h3 = (int)$string_parts_h[$i+6]; // +6 shifts string array position $hsum3 = $hsum3+$convert_h3; } // compare 7 if(($dsumu != $dsumd) && ($dsumd != $vsum1) && ($vsum1 != $hsum1) && ($hsum1 != $vsum2) && ($vsum2 != $vsum3) && ($vsum3 != $hsum3)){ echo "Not a magical square"; }else { echo "This 2D array is a magical square"; } ?>
-
I apologize ahead of time if this post is redundant, please delete if redundant. While searching or results regarding "Programming test questions" I came across a response that basically said "If your code looks bad, you are immediately overlooked." So, when programming PHP, and most web develop languages, how do you indent properly? I use Kate and Gedit... I don't think they auto-indent properly. What about bracket placement, and spacing between argument lists/ parameters? Thanks for any help
-
What I am trying to do is to look up an ip-address automatically via the website ip-lookup.net for example. To do this manually, I look at my ip-grabbing log of vistiors, I copy an ip-address, then I paste it into ip-lookup.net, hit search and they spit out some information. I'm not denying that this could be a false result. I'm also not sure if I can discern between a "company" versus a private computer... usually I see a Network provider or something like that. At any rate... I want this done automatically. I began to work with web scraping a while back and I could target the input and submit button... or perhaps just do a submission but how can I access their site remotely through my website or from php? I would have to: Go to site Target input field, paste ip Search Target result field, get info Insert into database with ip-address Any thoughts would be appreciated.
-
Writing a lot, I apologize. I do want to thank this forum and the members that make up phpfreaks(forums) I've learned a lot here. I've learned a lot from other sites as well.
-
I just took the test... wow I learned a lot though, from this brief exercise in life. I always had this thought of "I'm going to run away to California and everything will be great!" Standing there waiting for a cab, I reliazed how I take my data entry job for granted and taking the bus and life... well basically I feel domesticated. The test was alright although I can't say that I answered everything 100%. They gave me the option to choose from programming languages, PHP was an option and the job is for PHP developing. I couldn't remember the SQL queries verbatum but I wrote them as best as I could... Sadly I was not able to write three inherent principles of Object Oriented Programming... I said that objects are created from classes, children inherit properties from parents, variables to properties, functions to methods... efficient coding due to less code I don't know haha, I didn't do that great I mean... there was a question about opening a sample.txt file and I only ever did that with C++ through command line like 3 years ago, and perhaps I did it with PHP for like a day but could not remember. I do feel dumb haha. How can you tell if a database is empty? haha I was like "Look at PHPMyAdmin?" Query the row see if there is a result. There was question on iterating through an array without built-in-array function. I used a for loop and the $i as the counter... There was something as simple as take 99-999999 and for any given value, replace the first 99, with the letters of the abc ranging from 01 to 26... I could not recall the exact way to use explode but I was like "separate by the - and then run a loop through an array to compare 01 to 26 to the two characters" at any rate... it was an interesting experience, I haven't taken a programmer competency test (as it was called) Thanks for the replies and supportive words. I will still be working on my own stuff regardless of being hired but I also learned how unprepared I am for life. Recruiter: "Do you have a reliable form of transportation?" Me: "Uhh... yeah... bus, bicyle...." Recruiter: "You sort of broke up there, what did you say?" Me: "No car". I've been taking for granted that I spend $64.00 a month for transportation that returns a range of $1,600.00 to $2,400.00 a month. I used to have a car that cost me at least $116.00 a month plus gas. At any rate... thanks I apologize if the material I added to this forum is irrelevant. I spent $70.00 or more on this "potential interview" I get that it could result in a new job which pays more than my current job... it was so stupid of me... I wrote this instructions because I thought "I don't need to pay for a data plan, I have WiFi all the time." I got lost, had to hire a taxi to take me, then pick up my bike and go home... ahh life
-
Well I had to brush up on arrays, have never actually used them but knew of them in my applications... I did solve this one here called "Fizz Buzz" PHP is a "scripting" language right? But I feel like I can program with it... is there a difference aside from not comparing to C for example for memory and cpu... lower level See right here, perfect example of this "You think you know more than you do." There was this php test that pretty much told you that you were an idiot when not guessing correctly how many questions you got wrong. It was also outdated too I realized as I solved each problem. But I agree though I fall in that category of "knows some, not really sure what he's doing." "Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”." This is what I wrote <?php for ($i = 1; $i <= 100 ; $i++) { if((($i % 3)==0) && (($i % 5)==0)){ echo "#".$i." "."Fizz Buzz".'<br>'; }else if($i % 3 == 0){ echo "#".$i." "."Fizz".'<br>'; }else if($i % 5 == 0){ echo "#".$i." "."Buzz".'<br>'; }else { echo "#".$i.'<br>'; } } ?> Output is crazy long
-
Yeah I don't know why I'm having trouble wrapping my head around this... Say there is a simple 2 x 2 array, with values for x, 1, 1 and y, 1, 1 this works. So when I iterate for a horizontal test, how do I arbitrarily identify the key-value pair? As in, [2,2] 1,0 = 1 2,0 = 1 1+1 = 2 1,1 = 1 2,2 = 1 1+1 = 2 the foreach loop uses foreach ($arr as $value) { } I'm going to work on this for a bit, this seems so simple I just have to translate to php Actually, I will use this "Lo Shu" magic square as my reference to test if my function works as I know the values for that and it is 3,3 versus 2,2. Oh wait... yeah, this is still two dimensional, doesn't have depth Already lost, starts at 0, so 3x3 is [2,2] right? ehh... not looking good side note: It's not the money that I'm really after. This would be my first actual job related to web development which I could build upon for future jobs. "Gets my foot in the door" so to speak.
-
First I'm not asking for the answer, this isn't a homework assignment or something. I have this programming test thing tomorrow for a potential job, as an entry php developer. I looked up "entry level program test for job" and I came across a thread and a guy was saying that he was asked these three questions, first one is regarding the magic square. I didn't know what that is, read about it... side note, in a Java class I took we created a four-square game so I imagine the principle is the same, but I would like to solve it with php but any way. I'm not sure about the question quoted here: I am initally inclined to say I can throw out non-square two-dimensional arrays right? Since for the diagonal test, the length has to be the same as the height/width of the square? From a graphic found on the link in that quote, the diagnoal test was only one diagnoal although probably rotated 90 degrees to check the other direction. The other question was that the associated values of the indexes of each array is arbitrary right? So when I test this function myself, I would have to set the values to a known-magic square? I get that the idea is to enter arbitrary values into each arrary "coordinate?" what do you call that? Dimension... So a 2D array of [2,2] could have for x, x0 = 1, x1 = 1 and y, y0 = 1, y1 = 1, that would work... but for example if x0 = 2 and y1 = 5 then it wouldnt' work... so... probably a bad sign that I'm having this much difficulty solving this or thinking too much about it and not just solving, at any rate it is a good review. The job is for entry level, pays at 35K a year, which is a step up for me. Would be pretty happy to get this job. I've been working with php for about a year and there seems to be concern for Object Oriented Programming and Model View Controller... I believe the purpose of the test is to see how you think and solve problems, but actually solving the problem would be nice.
-
This is always bothering me as I'm not sure if I am using safe/secure methods of accepting input. All of my php-inserts are parameterized but I am wondering if I still should escape / use filter function. Can someone clear this up? I've looked at a few sites and a couple posts have said "Prepared statements only way to guarantee against SQL Injection." So if I use prepared statements, is that it then, am I okay? Or should I still perform the escaping/filtering? Thanks for any help http://stackoverflow.com/questions/2009910/basic-mysql-php-filtering http://stackoverflow.com/questions/1290975/how-to-create-a-secure-mysql-prepared-statement-in-php http://php.net/manual/de/ref.filter.php http://stackoverflow.com/questions/129677/whats-the-best-method-for-sanitizing-user-input-with-php
-
Is anyone here an "overall developer" ?
greenace92 replied to greenace92's topic in Application Design
This is a lot to take in. I have to actually make soemthing then come back with my results. Thank you for your time and the information. -
I just made up that term but what I mean by it is a person who can develop application/software for both computers and mobile... specifically joining an android application wtih a desktop (linux and windows) program that both have access to a mysql database. I have picked up the term RESTful and SOAP as potential solutions to the phone and server part... C,C++,C#,VB,XML for the desktop app part. The basic requiremetn is read/write from a MySQL server from both devices. I've recently started to work on Android Studio but am pretty far... does anyone want to take a stab at a basic read/write interface for both parts. Bare bones simple window/box UI, black and white... This is a pretty time consuming thing for me... a lot to learn I'm essentially looking for a crash course introduction if anyone is up for it.
-
Is an SSL encryption with session based redirect secure enough?
greenace92 replied to greenace92's topic in PHP Coding Help
Hello scootstah, Thank you for your response. I apologize that it's been a while. This is what I have been using, I made this a while ago, it is really messy. I'm not sure if it is correct. It works as far as setting the session and with exit but it's sort of sporadic. This is test_input something I picked up from W3Schools I think I have been told not to use some of the filters because of special characters that users may enter, I'll have to see what each one does. function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } The triple-s password is to discern from the password to access the database where users are stored, this was before I adopted including a database login file. if (empty($errors)){ $company_name = test_input($_POST['company_name']); $passsword = $_POST['passsword']; $hash = password_hash($passsword, PASSWORD_BCRYPT, array("cost" => 9)); $stmt = $link->prepare('SELECT company,hash FROM companies where company=?'); $stmt->bind_param('s',$company_name); if($stmt->execute()) { $stmt->bind_result($company_name_from_db,$hash_from_db); if($stmt->fetch()) { if ($company_name_from_db==$company_name){ if (password_verify($passsword, $hash_from_db)) { $_SESSION['company'] = $company_name_from_db; function Redirect($url, $permanent = false) { if (headers_sent() === false) { header('Location: ' . $url, true, ($permanent === true) ? 301 : 302); } exit(); } Redirect('site_url', false); } else { $errors['password']="error"; $errors['company_name']="error"; } } else { $errors['password']="error"; $errors['company_name']="error"; } }else { $errors['password']="error"; $errors['company_name']="error"; } $link->close(); }else { $errors['password']="error"; $errors['company_name']="error"; } $host = $_SERVER['HTTP_HOST']; $uri = $_SERVER['REQUEST_URI']; header("Location: http://$host$uri"); exit; $link->close(); } -
Hello, I'm not really sure where else to post this question, stack overflow would have denied it due to having too many possible answers. I am interested in a multitude of answers / general consensus if any. I'm trying to get a good idea of an appropriate resume design for a person who works with web development / servers / programming and the like. If you happen to be employed in these fields (thereby assuming your resume was successful) I would like your input on a good resume layout. What it should accomplish, what immediately hits the eyes, general flow of the page, etc... I am halfway through a bachelors degree (was in Physics) but I'm wondering if I should pursue a COMPTIA certification or something... I mean really any work regarding computers, whether fixing them, maintaining them, web development, etc... would be a step up for me. Often minimum requirements are a 4 year degree in such fields or 3 to 5 years experience etc... So given my situation with time and finances I'm not exactly sure which direction to go, I work over full time per week so I probably could only do one class at a time. I have about 9 months or so at my current job, I'm an entry level data entry operator (best job I've had for no skills at $11.00/hr) and I need to progress with life / have a future. I don't want to do more than a year as a data entry operator, I'm amazed I have lasted this long. It's such a mind numbing job and I don't learn / gain more skills to apply to future jobs but it is paying the bills although I can't really grow from this position. I have tried free lancing and it is a tough market. I am not an expert in the fields that I have dabbled in but would like to mention my works in said fields. This brings around a portfolio which I thought about designing my own site using a time line - oriented design. I'm wondering if that's too much. Maybe just a simple list and direct links to the examples, I don't know... I would like to improve my resume and generally how I am viewed by potential employers. Perhaps I won't get far without any sort of certification or education as I mentioned above but if I can get the resume covered, that's a step in the right direction. I'd appreciate any help or thoughts. Thank you
-
I'm working on a project manager site where I can show project files to authorized users, those being members of the site. So far the pages have a basic if empty session redirect but I wonder if that is safe enough? I want to have the photos/text not accessible to the public. Where should I look for this?
-
What do you call the text that web developers work with?
greenace92 replied to greenace92's topic in Miscellaneous
I see, thanks scootstah -
It isn't technically "code" is it? I mean code implies programming like at a systems level ? Or does scripting count as "code"? I don't know why I can't think of what word or string of words to call like for example: <img src... > that stuff I mean HTML CSS , jQuery, Javascript, etc... but what do you call that? Can you call it "code" ? I mean you can call it what you want but what is the proper technical way to say or classify that "language" or...
-
Alright, thanks as always for responding to my posts.
-
How can I get the data of individual pixels?
greenace92 replied to greenace92's topic in Application Design
Thanks for your response. This was a random thought. I mean that is a php function which would could be independent on their website right? Depending on windows server vs. linux? Although when I think about it, the page has to be parsed on my end in order for me to "do something with it" eg. see it. I don't know... anyway thanks for your input. I'll look that over. -
There are these tasks on a website, and it involves using your eyes, recognition, I guess they don't have OCR or some sort of software that can identify objects... See attached photo as an example where your job is to write what you see on a receipt. So... I was thinking... each one of these pays $0.08 and if I can automate that job, then I could make money while I was working my real job. So I would think about how I understand letters (my own brain) and then figure out how to write the algorithm (is that right?) top down for example, a block is a sentence, then a smaller block is a word, then a smaller block is a letter, then the smallest detail would be the pixels comprising the block comprising the letter.... Anyway, can I get the data of a pixel? I read in this post that you can't. Why? Who said no? http://stackoverflow.com/questions/14202476/how-can-i-get-the-color-of-any-specified-pixel-on-a-web-page Does the browser take over the display on a computer and thus defines what you see or does the computer do anything with the display so that in this case my application would run on my end or perhaps a server...
-
I was asking "What can happen" I realize I also may have asked how... I am concerned regarding intentional bad user intent... So if a person embedded a link which if clicked, executed some function... I suppose a target is always a risk as you would have to somehow know what the words mean or something... but I'm talking filtering. For instance when processing a form, you usually do stuff like escape, or replace characters, etc... what similar rules apply to links?
-
Hi Scootstah, This is very good information to know. Would you happen to know off hand as far as php.ini goes, what keywords applies to these limitations? Isn't there a limit like 1000 request an instant or something like that? That's not the exact words but... There was something like you could have 1,000,000 users connected but only 1,000 could post a comment at the same time