Your function IsValidEmail does not return anything, and your application of it expects a boolean.
If your regex test validates true, you should return true. If it doesn't validate, return false.
Your function IsValidEmail does not return anything, and your application of it expects a boolean.
If your regex test validates true, you should return true. If it doesn't validate, return false.
The best way I had machine learning explained to me was similar to this:
Lets say you want a computer to identify a color. Lets take "Red", or 255, 0, 0 (or some threshold of).
(NOTE: Of course, what you would write is an algorithm that looks at color and a specific threshold (say... "red") not always "red"... because that would just be silly, right?)
You write an algorithm that looks at pixel data, and returns a 1 or a 0: 1 being "YES! It's RED!" and 0 being "NO!" (or Yes! It's a thing, or no it's not!)
You then "train" your algorithm by giving it lots of variations on the color "RED" to include "Like Red" (again, to some threshold of)
You put this training system into separate computers, all of which take an input (your color) and an output (1 or 0)
You then make a program that takes in your color, sends the color randomly to a random number of these computers, and gives you the weighted average of their deduction of if the value is 1 or 0.
You can, then, make adjustments to how to "train" your machines by either letting them figure out variants on their own (by programming that in by giving it the ability to make assumptions, or some memory/database) or by manually saying "You got it right!" or "You got it wrong!" and giving it guided teaching (which it stores those responses instead of making its own …
Its possible. It's also possible that my original thought is true as well - consumers have been trained to just accept "I need a new one" and that's that.
Who knows. I hear your frustration... but... if it keeps you in business and it makes the world go round... why complain? If you can take their broken parts and make them work for someone else, donate those machines and give someone who otherwise wouldn't have access to a computer a chance to be part of the internet and world at large...
I don't know what the laws are for re-using old parts for new builds or donating, etc... but it's something you can look in to for sure, and then you won't have a bunch of eWaste just burning a hole in a landfill somewhere.
...I dislike your analogy... if the tire is flat, there is a reason. If it was fine yesterday, tires don't tend to spontaneusly deflate with the sole need being more air (rapid temperature changes aside, but then you have tire pressure to worry about)...
A mechanic will be better suited to figure out if the tire has a puncture (because the nail/object was ejected and now there is an invisible hole), the wheel rim is bent, or the leak is caused by some other malfunction - and yes, as a service, a mechanic will know more about what to look for immediately while I (or the masses) will have to research it or gain that knowledge from first hand experience. Remember - not all IT staff are made equally; you and I seem to have a similar skillset: I program for a living, but there was a time when I built custom gaming rigs and sold them. Having access to that kind of experience is not afforded to the guy who writes JavaScript/CSS all day, who has never seen a motherboard because he works exclusively on Apple products except for his one test PC that is having a mobo failure.
Maybe if it didn't cost $75 to use a voltimiter (but again, you are charging for your experience using a tool to diagnose, and charging for your expertise, not the activity) you would get people more willing to allow you to try less aggressive measures - like I said, the …
By people do you mean the general unwashed masses? If so - it's because they are intimidated, or unsure of their ability to diagnose. It's something so small and trivial to you, but remember - 10 years ago or so something that is trivial to you today may have been daunting or frustrating to you.
It can also be a policy thing - does the cost of a new mobo + installation compare against the cost of that same person doing a full sweep hardware test just to find out they need new hardware? Is it worthwhile to invest in new hardware to leverage potential future upgrades?
It's also cultural - for a good portion of the world (thanks to Apple, and Co.) planned obsolesence is a thing - and people have just gotten used to their hardware breaking and figuring it's time for new hardware because that's just how it is.
Of course, this is all conjecture... some people are just lazy :-/
Your question is incredibly vague...
If you plan on taking payments online, there are standards to follow. Most gateways will provide you with an API to integrate with, or pre-cooked up scripts for you to call. If you want to add additional security to your payment process, that's on you - but at the end of the day it comes down to encryption (which you likely won't be writing, but instead you will implement someone elses), and using SSL to send data over to the processor/gateway.
Is there a specific problem you are having with getting started? Do you have code written already and you are stuck somewhere?
define "biometric process"
If you are talking about processing a thumbprint or facial recognition, then it's the job of the hardware to give you a usable data representation that you can process in any language. It's likely that the hardware makes certain assumptions and turns physical/analog data into a hash, and then you actually process said hash. If not, and you are getting raw data, then sure - nothing stops php from working on a byte stream.
As pointed out here: https://stackoverflow.com/a/6678359
the PHP string is equivalent to a Java byte array.
--> No ram installed yet
Found your problem.
It's likely the BIOS prevents boot/access without RAM installed (otherwise, what's the point, right?)
also, for your file input on the html you may want to look into the accept attribute:
<form action="/action_page.php">
<input type="file" name="pic" accept="image/*">
<input type="submit">
</form>
https://www.w3schools.com/tags/att_input_accept.asp
Again, this is meant as a helpful filter, and will not prevent them from changing the type. It also does not limit file size.
If you want to stop it client side (to prevent the form from submitting at all), you can look at the input data's type (which should give you the mime type) and you are looking for "image/" if the mime-type doesn't match, return false from the form (otherwise it will still submit).
If you want to do this server side, this page can be of help -- https://www.saotn.org/validate-mime-types-with-php-fileinfo/
Either look at the file name with a regex (bad), look at the file data directly for the mime type (better), or if you have fileinfo extension, use that for mime type comparison.
please note, client side "validation" is meant to make things easier UX/UI wise for your user - it is always good to validate both client and server side, with a minimum being the server side (otherwise, people can just send trash data at you).
Hope that helps,
Ryan
between lines 49 - 52 you are redeclaring $headers. You need to concat that stuff :) (like what you did on line 50)
You need to escape your slashes in string literals.
'C:\Users\mchalla\PycharmProjects\837_unzip\venv\SampleUnzipFiles\DelimitedFiles'
should be
'C:\\Users\\mchalla\\PycharmProjects\\837_unzip\\venv\\SampleUnzipFiles\\DelimitedFiles'
or, you know.. be consistent and just flag it also as a raw string :-P
r'C:\Users\mchalla\PycharmProjects\837_unzip\venv\SampleUnzipFiles\DelimitedFiles'
The error you are getting is from \U telling Python that the next series of values represents a unicode value (in your case "sers" which, FAIK, converts to the ascii values and then tries to high-bit/low-bit them and errors out).
//More info!
from: https://docs.python.org/3/reference/lexical_analysis.html
Escape sequences only recognized in string literals are:
Escape Sequence Meaning Notes
\N{name} Character named name in the Unicode database (4)
\uxxxx Character with 16-bit hex value xxxx (5)
\Uxxxxxxxx Character with 32-bit hex value xxxxxxxx (6)
so I wasn't far off... it didnt high-bit/low-bit it just straight up tried to convert them to a 32 bit value and puked on itself because it was out of bounds.
TL;DR: Focus first on where your code is stalling requests. Fix them. If you can't possibly change your code, then invest in hardware. Set it up yourself or by someone you trust / hire / contract (and after they do it, learn as much as you can to support it in case they leave or do something wrong, or you ever need to scale again).
Anything is possible. However, once you set up an infrastucture and investment, do you really want some random person who you paid a minimum bid being the one responsible for controlling your network? IMO that's asking for trouble - especially if your site does become very sucessful and you have to scale and are then faced with trying to find someone who had the same frame of mind and expertise as the person who set it up, as well as taking on all security risks associated with random implementations.
A single VPS/Dedicated Server should not be limited to 150 - 200 concurrent requests / sec. The "theoretical" hard limit is ~65,000 requests on TCP (which is what HTTP requests are based on) and seeing how those should be open and closed as fast as possible, you should be able to handle the kind of traffic you are seeing. If you arent, there is likely a code bottleneck somewhere - and when you find it and alleviate it, you can then look at how to best start scaling upward and outward. (NOTE / DISCLAIMER: Im not …
So...
I see your check for existence SQL, and your actual insert... I don't, however, see your attempt to save the file data to the database. Am I misunderstanding your question? The reason it wouldn't be in your database is because you're not even trying to put it in there :-/
Are the images available in the directory you make with $target_file = $target_dir . basename($_FILES["image"]["name"]);
Also, in general, you don't want to put the image data in the database - that's slow, especially for large image files - you should do as you are (move the image to a directory), and in the database keep the path to the image for use later.
So, if you return false you don't have an array - hence your error. You should first check to see if you have an result before you run count.
You can do that with something like if ($list && count($list) > 0) -- and the first clause will short circuit and not try to run the count.
Any number of possibilities. Your office network may block or blacklist certain web requests, or the firewall blocks them. If that's the case, you may end up getting a malformed JSON string and then you cannot log in due to JS errors.
If you own the site, you can look at the logs and see if things are happening in the order you expect. If not, the best you can do is look at your profiler and see if you get any 400+ or 500+ calls and see what's failing.
Good luck!
Ryan
what does this do?
$list = getListed(array('EducationID' => 'Id', 'L1Education' => 'L1Value', 'L2Education' => 'L2Value'), array($table_prefix.'educations', 'Id'));
if the answer isnt "it RETURNS an array" then you found your problem.
So, turns out the sockets were a red herring. I had a "reader" thread that basically shot through a linked list of "message" objects, and if that list was empty the thread was spinning like mad.
So.. future folks looking for help with threads - even when you check all your while loops and put testing in, go ahead and do it twice :-/ You missed one.
That whole thread is about using Sleep() or Event Objects to work as a shared handle for signaling. :-P
Unless I missed something else in there that you would like to point out.
If that's the answer then so be it - event driven programming is fine. I do it in JS all the time... was just thinking there was something more effective in C++ (or, rather, I assumed it would be different....)
It's just a test VM so I can practice. I spend most of my day writing JS/SQL/CSS and we use a propretary C++ backend, and I want to contribute more to what my company does - in order to do so, I am trying to improve my skills with C++ and programming in general by writing applications and filling in knowledge gaps.
Why the single core VM? Was the best price I could find.
IIS runs on the machine and it idles at 3%. Socket programming cant possible be that heavy that I can't replicate what IIS does. I get that I don't have the development power of Microsoft nor the inner workings of the OS at my disposal, but I would think that 100% is a bit obnoxious :-/
Hi all,
So before I went and posted ~800 lines of code, I have 2 questions:
1: What is the preferred way for us to post "complex" C++ (of course, this is just a .h, .cpp, and main cpp but it's still a lot of lines) that wont just be obnoxious to read/debug? (I guess.. what is the proper etiquette here?)
2: Maybe I don't have to post it, and I can get theory help - I have a socket server that spawns threads with mutexes to control everything as needed (I think I am doing it right). When I run on my dev machine (4 cores), I get about 22% usage spikes every 5 seconds on 2 of the cores. When I put it on my "server" it's a single core, and it spikes to 100%.
I have put std::cout
s in all the while loops and none of them run more than the initial entry (recv/accept are blocking, all the other mutexes hold just fine). Is there a better approach to debugging this, or are accept/recv just that cpu intensive?
I am not yet doing event driven threads (and I am not using select, but if I have to I will refactor, but I would like to understand how to do it "right" without it as part of the learning exercise).
For reference: Windows server 2012 R2, Single Core 2Ghz, 1Gb RAM. IIS is running, the server is fairly locked down and all security updates/patches are installed. I …
Also, since you're passing through PDO I assume you migrated machines or something like that - are you sure your PDO vars are being set correctly? If you pass in an err val for one of the parse vars, it's possible that would explain the empty value as well.
First: Have you tried it? Does it do what you expect?
Second: If you're gonna short circuit a process ( if (num === 0) .... ) then do it before the work starts. Why wait until after you try to do work to stop work that is almost done?
Really, there is nothing wrong with your solution - but there are other ways to do what you are trying to do. For starters - you can optimize by starting i = num, and then count backwards with i-- instead of i++. This way you can save a process on the subtraction from num.
Also, your attachment for the onlick is not very "javascript" like. Most people would do oBtn.addEventListener("click", fnPointer); But for your simple case, what you did was fine.
Good job and keep up the good work!
Ryan
I did look into the idea of writing a php extension, but it seems it's fairly difficult to do so on a windows system. Right now, I have done a reverse proxy through IIS, however it still has some issues...
I don't think I want to use PHP has a socket controller, as there is a lot of overhead with PHP and I am looking at doing something that requires high performance. If I am forced to work in PHP, then I will.. if I can find a way to do with through the reverse proxy, then Ill share my results and process when I figure it all out.
Thanks for the link, though!
when you say blank, do you mean null or an empty string?
Also, have you tried just running a hash by itself and seeing what the output is? (ie, select AES_ENCRYPT("string", "foo"); )
So first, you have no reason to check the length of the files uploaded other than if it's greater than 0.. and even then ... meh. Let the logical loop do the work for you.
In the process of doing this, you will notice immediately that your single file upload process is incredibly different than your multi-file upload. This is, in my experience, poor code design (and poor logical design). The first rule that most programmers pick up on and figure out quick is "Don't Repeat Yourself" (many will call it the DRY principle). It is problems like your that make this very evident - if both paths went through the same function, you would know quickly if it is working or not; and you would not be updating mutliple logical paths that do the same exact thing.
TL;DR: Refactor your code to something like this:
for ($i = 0; $i < count($file['images']['name']); $i++) {//loop to get individual element from the array
someFunctionThatProcessesYourInput($file['images'][$i]); // do the move_file and sql update and validation stuff in here...
}
This should catch all cases except there not being any files at all, in which case you probably want to skip it anyway :-P
I hope that helps!
Good luck!
Ryan
based on your table structure, you insert 2 records into your image table, both of them with the same productID value.
Is this what you're talking about?
as noted here:
https://stackoverflow.com/questions/13713912/mysql-query-returns-blank-field-with-aes-encrypt
If it's not a blob type data field, you may get blank. If it contains invalid data, it may also return blank.
JP, uhh... maybe open your own thread on this.. been dead for over 4 years.
The short answer is wat anas.man suggested; Use that, get multiple images in the file input, post to your server and var_dump($_POST) and see what's in there.
So lets be clear - no one is going to do the work for you without compensation - that said, I will try to give you some ideas on how to solve your problem as a "programmer" would.
1 - Identify what you need
-- Table for Personnel
-- Either a related table for datetime information for activity or a column in this table for when the user was inserted (mySQL now() function)
-- a PHP script or mysql stored proceedure that will check if TODAY is >= 6 months from the user's join date (or, just the proc to add them or check eligability or.... so many ways to do this, it depends on the business logic)
-- a Table for classes/courses
-- a Table for registered users mapped to courses
-- Im sure you will need more administrative stuff too...
--------- in short -> this area is where you assess HOW you can solve a problem given your best understanding of data and the problem you are trying to solve.
2 - Start with what you know.
-- if you know PHP, start there and build the pages to look and function the way you want/expect, and try to keep in mind what your data will look like.
-- if you know SQL, start with your table structures and data management.
-- if you only know HTML and CSS, make it pretty, and use them as templates when you get into PHP
-- .. if you haven't gotten …
Im not sure what a "software load balancer" would do other than put up a cache state for repeat requests... but that's just because I can't conceptualize it.
However, the suggestions for looking at your SQL and how to find slow queries from everyone else is spot on and it is likely a good place to start in terms of optimization. Before you HAVE to spend money, see if you can just fix the stuff yourself :)
+1 pty - never knew mySQL had that available. Been livin in a TSQL world (with a profiler) for so long I never really had to look that up :)
is that 150 per second?
If not, then you have something seriously weird happening that is taking a long time to complete. Are these persistent connections (like sockets)?
You also have to consider your hardware and bandwidth (or if there are caps from your provider).
So many things to consider that all come with a cost/benefit analysis...
If you are using a service like GoDaddy, they put hard limits on their VMs, even "dedicated" vm servers. Other services may as well.
Ultimately, if you are going to have this sort of sustained traffic, you may want to see if an AWS or Azure cluster would be more worth your time. That way you get load balancing and global scalability in one (it just comes with a cost that you will have to determine if it's worth it).
If you own the hardware and are serving it yourself, thats where you want to look into load balancers in front of series of web servers, or Akamai or similar to basically do what AWS/Azure would do for you. Otherwise, it might be just as simple as paying a little extra to bump your bandwidth pipe to handle the data.
It all comes down to your particular need and how much you want to invest...
Its unlikely that PHP is your bottleneck. Are you using a database? If so, I would start there and see if you have any particularly long running processes that you can optimize.
Sometimes, just changing a query from select * from ....
to specific columns select a,b,c from ....
can offer a performance boost depending on table size and what you are returning.
If you are not using a database, then yes - whatever you are processing server side would need to be optimized - but I am still interested in what you would be doing to cause that much traffic on just PHP alone.
Anyway, best of luck! I hope I helped.
You know.. an alternative to your issue might be just optimization...
What is it your site does that you are noticing slow downs? (if you don't mind me asking).
If it's just serving up web pages, the volume of traffic youre getting has to be insane to slow you down.
Nevermind. Case of misunderstanding the recv() function.
For any others who make the same mistake I did, recv should be called on the socket you created from accept()
:-/ Not the bound socket...
nope. Not at all their problem. It will become their problem if your site crushes their bandwidth, but it's likely your server will struggle long before they notice your site as a blip unless youre running multi-cast video or high bandwidth data.
Is it possible to know which connection sent data wiht recv()?
Current setup is
- Main Thread spins and waits
- Thread 1 - do stuff unimportant to socket
- Thread 2 - accept() -> keep linked list of accetpted sockets
- Thread 3 - recv() -> can I know which IP addr/connection sent me the data I am currently reading?
Thank you :)
Ryan
Looking for conceptual help...
I am writing a program in C++ to handle socket connections, eventually to be a websocket server. However, the rest of my stack uses PHP for serving up page.
Is there a way to use PHP as an intermediary between the client (JS) and the application (so I don't have to keep track of session data or state in the database to retrieve with each incoming socket request)?
I understand I can't pass the resource (a socket) to the application from PHP, but could I do a 302 with the request from the client? Could I just pass along the request/upgrade request to the application layer in some way?
Thanks!
Ryan
This is what load balancers and cache servers are for.
While I have not set anything up myself, it is my unerstsanding that you have a few options from using a service like Akamai to having a load balancer as your handling server and then pass requests to servers that are not currently under load.
Whatever it is, you're gonna have to invest in infrastructure.
Congrats on the success, and good luck! :)
Well.. lets begin..
First, arrays in most languages (and it looks like you're using PHP, and PHP is one of them) start at 0. So first, $b = 0;
Second, <= 6 is not what you think it's doing. Since we start at 0 (i.e., $count[0]), when you get up to 6 you are doing $count[6], which is out of bounds of your array. So, $b < 6;
After that.. I dunno. Looks fine to me. Im not sure what you mean it 'goes on forever' but I assume you get something you don't expect, and I will also assume that it has a lot to do with the errors in your code.
TL;DR;
for ($b = 0; $b < 6;$b++) { ... }
I dont think there is a good way to do this with pure CSS. It likely requires some javascript, using a "data-" tag on the parent element, and show which item you want displayed. the Javascript click event would then update the data- tag value to whichever element should be displayed.
However, their logic uses JS to put classes on elements in the grid, and uses on "transitionEnd" event to clean itself up. Internally, it seems to keep track on which "view" is currently displayed.
Lots of ways to do this. If you want to make a page like theirs, though, just debug and see what is happening when you click buttons :-/ Only way to learn is to try yourself or learn from others - and from the example page you provided, someone has already done the latter for you...
First, this function is depricated - it may be time to learn about MySQLi or other something more modern in the PHP world.
Second, take a look here:
http://php.net/manual/en/function.mysql-fetch-array.php
You should be passing ($selcat, FLAG), as $selcat is the "resource" it is expecting (i.e, the result of a query).
For more clarity, look at example #2 in the link above.
Good luck!
Ryan
You could find a way to use the DISTINCT keyword, or a group - likely the latter will have better performance. Of course, your query will have to change to meet the grouping mechanism.
However, your desired output is a bit odd in terms of data - your 1st - 8th is set for a reason, particularly that they have different performance values. So depending on what you are planning to do with your data, you may wish to consider refining your expected output to give credit where credit is due (unless the intention is just to list top performers, in which case why not just do a group by where you MIN the performance?)
Hope that helps.
Ryan
If you are doing some sort of script that outputs values for an insert, eg...
insert table
(
a,
b
) --start script -->
values
(
1,
2
),
(
3,
4
)....
then your options are likely limited.
Even if that was the case, or you have another setup in mind, if I were to tackle this, I would probably insert into a temp table, then do an insert where I join against my target table excluding the value combinations I don't want.
Otherwise, I may not be understanding what you are trying to do :-/
You can also apply what you know towards something you enjoy. Like books? Make a simple program that interfaces with a database that allows you to put info in.
It doesn't matter if your program is useful to anyone other than you, or if it even succeeds - it's the process of identifying a problem, and working a solution out to meet your needs. From there you can work on things like optimizing, or implementing new features, or expanding your understanding of things like data transport or threading, objects, or anything else...
All it starts with is figuring out something you are interested in, and coming up with a simple idea that you want to figure out how to do. That's pretty much programming in a nut shell - be interested. Be curious. Want to understand how things work, and then have the patience to research it. The code to interface with the machine will come naturally once you start working on "something."
I do mostly web work professionally - I spend a majority of my day in Javascript/SQL and a bit of CSS, and I get to use C++ every so often. However, once in a while something comes up that I have to solve that can be done in other languages due to libraries already built, or just because the syntax is easier to get started, and then I get to learn C# or Python. Just find something you want to do, and do it. If you truly …
Depending on what you are searching through, the root form of storage tends to be some sort of database - and SQL is how you generally interact with those.
Then you need methods for quickly searching data, as well as making searches relevant, considering human error - so the basics of machine learning are the follow up to learning SQL and SQL query optimization.
From there it's picking a language to write your machine learning algorithm, and setting it free to make the world a better place.
instead of doing the redirect, do a var_dump on $_SESSION and see whats in there. Then, do the same on index.php as well. Something obviously isnt being set, or carrying over - it may be that headers have been sent before your session begins (but that would cause an error).
It is also possible that isset is giving a false positive:
http://php.net/manual/en/function.isset.php
Since you set the value to "something", even "", it will return a valid value, since it is not NULL. Since you are using empty() earlier in your script, why not apply it here too?
This is because you are using floats for your layout.
Now, this is very difficult to give you good advice on how to approach this for a couple reasons... the biggest being, I do not know your requirements, your time frame, nor your target audience (including what browser support you need). There are SO many options on how to do this, but what you are looking for is called the "holy grail" layout (google it). You will have to pick the solution that fits your needs.
There are plenty of examples on how to accoplish it, and keep the content responsive.
what have you tried?
It looks like you can do it with some subqueries and a NOT IN, but that would likely be very inefficient.. perhaps joining against itself and doing some sort of group by?
In particular, I believe you are talking about the header image --
You have it set to width 100% which means on a 1980 width screen, you image (which is 948px) gets stretched to over double its size. You cant just set width to 100% without a container that has a max size of the image, or that scales vertically to match the horizontal shift (but with jpg, even doing that will cause artifacting/blurring).
You will likely need another container around the image that has the width 100%, and then center the image within that container - that way the image stays its intended size (or a fixed size), and the container will grow around it and fill up the extra space as needed based on the browser's (and user's monitor) size.