-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
Is there any way to grow my server's grabbing script?
kicken replied to Rayhan420's topic in Apache HTTP Server
It depends on where the bottleneck is. If the problem is too much network traffic (which seems likely on a shared host) then there's not much you can do. If it's an issue of processing the results taking too long you may be able to speed it up by optimizing your code. Make sure your code is optimized so it will process results quickly. Do some benchmarks and profiling to determine where your code spends most of its time and see if there is any way to improve that area of code. Attempt to download different pages in parallel to make use of all the bandwidth you have available. You can do this with cURL and there are libraries available to make it easier. -
The "0": and "1": are there because you encoded an array-like object. Such json is perfectly valid, and would decode just fine with json_decode. You'll probably want to pass the $assoc flag as true so it decodes to an array rather than an object, that will make accessing things easier. $array = json_decode($json, true); var_dump($array[0], $array[1]);
-
Just because your query will pull the course name for each row doesn't mean you have to display it in the output for each row however. As you process the query results in your code you can detect when the course name has changed and only display it at that point. Alternatively you can have your code group the results by course then output the results with some nested loops.
-
Since your code is essentially mapping one value to another, you could also use an array with a key=>value map. function getTimePeriod($value){ $map = [ '' => '1 month' , '7' => '7 days' , '24' => '24 hours' ]; $value = preg_replace('/[^0-9]/', '', $value); return $map[$value]; }
-
First off, just incase this isn't some copy/paste issue, you really need to work on your formatting. Proper and consistent formatting will help you avoid bugs by making it easier to follow what the code does. Here is your code cleaned up: <?php $Name = $_POST['Name']; $Place = $_POST['Place']; $Age = $_POST['Age']; if (isset($_POST['Submit'])){ //Als men op de Submit knop heeft gedrukt van het formulier... if ($_POST['Name'] == ""){ $error = "Name is not filled in.<BR />"; } if ($_POST['Age'] == ""){ $error .= "Age is not filled in!<BR />"; } if ($_POST['place '] == ""){ $error .= "Place is not filled in!"; } } if ($Age > 18){ echo "Hello $Name"; } elseif ($Age < 18){ echo "Hello little $Name"; } elseif ($Age < 18 && $Place == "New York"){ echo "Living in: $Place"; } elseif ($Age > 18 && $Place == "New York"){ echo "I love New York!!"; } ?> Now, you have a few issues.You should always use isset() to test if input data exists. Failure to do so will result in E_NOTICE level undefined index errors when it does not exist but you try and read it anyway. This means your first three lines need to check if the key exists before reading it. You can do this easily using the ternary operator along with isset(). Since you re-assign the post keys to other variables at the start of the script, you may as well use those variables in your if conditions. $error is potentially undefined since you define it within the if condition relating to $_POST['name']. If that condition is not met but the others are, you'll get an E_NOTICE error about it being undefined. $_POST['place '] is wrong. You never actually output $error anywhere and you do not prevent your second part of the code from running if an error was found. Your last two elseif statements are impossible because in order for one of them to be true, one of the prior two statements must also be true which means it will execute instead of the later ones. It's unclear what the desired output would be from the code alone, but as a general rule when doing an if/elseif/else chain you should order the conditions from most-specific to least-specific. Here is some corrected code that addresses the points above: <?php $Name = isset($_POST['Name'])?$_POST['Name']:''; $Place = isset($_POST['Place'])?$_POST['Place']:''; $Age = isset($_POST['Age'])?$_POST['Age']:''; $error = ''; if (isset($_POST['Submit'])){ //Als men op de Submit knop heeft gedrukt van het formulier... if ($Name == ""){ $error .= "Name is not filled in.<BR />"; } if ($Age == ""){ $error .= "Age is not filled in!<BR />"; } if ($Place == ""){ $error .= "Place is not filled in!"; } } if ($error){ echo $error; } else { if ($Age < 18 && $Place == "New York"){ echo "Living in: $Place"; } elseif ($Age > 18 && $Place == "New York"){ echo "I love New York!!"; } elseif ($Age > 18){ echo "Hello $Name"; } elseif ($Age < 18){ echo "Hello little $Name"; } } ?>
-
$UpdateGoTo = "show.php?GuestID=".$whateverTheIDIs;It's up to you and your code to define $whateverTheIDIs. There's no "just do this, it'll work" answer. You just have to get the ID from somewhere, append it to your URL using concatenation, then redirect to that URL using header.
-
Works for me with mail.google.com. To ignore the page contents you can just set CURLOPT_RETURNTRANSFER to true.
-
<?php $ch = curl_init('https://www.google.com/'); curl_setopt($ch, CURLOPT_CAPATH, '/etc/ssl/certs'); curl_setopt($ch, CURLOPT_CERTINFO, true); $result = curl_exec($ch); var_dump(curl_getinfo($ch, CURLINFO_CERTINFO)); Seems to work for me. CURLINFO_CERTINFO doesn't appear to be documented so I'm not sure if there are any version requirements.
-
I just copy/pasted your link from the original post and edited the href value. I generally do not add a target to any of my links. For items I think should be in a popup I'll just give them a class="popup" or similar and have a bit of jQuery that attaches to it and opens it into a new window. Otherwise it's up to the end-user to open it in a new tab/window if they want too using their browser.
-
Read this post: Joining two tables and returning fields from MAX(id) row Same problem, just worded a bit differently.
-
Create a $totals array with the same pos/neu/neg indexes and sum the values as you loop. $totals=array('pos' => 0, 'neu' => 0, 'neg' => 0); foreach ($strings as $string){ $scores = $sentiment->score($string); $class = $sentiment->categorise($string); $totals[$class] += $scores[$class]; } var_dump($totals);
-
That's one possibility that would cause issues if you're constantly re-generating the random ID's. There are plenty of other ways someone might end up with an invalid ID without realizing why (or even being the cause). For example if someone were downloading using a download manager, there may be two requests for the file: One by the browser which is aborted when it determines the content to be a download, and another later by the download manager. If the browser or an extension uses pre-fetching, it may start requesting other pages on your site in the background in order to speed up the user's browsing experience (chrome will do this if you ask it to). Each of these requests would re-generate the ID's and result in invalid links. The least troublesome method is to generate the IDs as needed, and time-limit them rather than usage-limit them. You could generate the tokens when creating the link, or when they initially request the download, either way. For example: Create the initial link with the actual database ID or something else that doesn't change. Link to some intermediate file rather than directly to the download link <a target="_blank" href="retrieveFile.php?id=516789792">myfile.xlsx</a> In retrieveFile.php generate the random token and store it in the session along with the initial request time and file ID. Redirect to another file with the token. $token = generateRandomToken(); $_SESSION['downloadTokens'][$token] = array( 'initiated' => time() , 'id' => $_GET['id'] ); header('Location: download.php?token='.$token); Verify the token and download the file. define('GRACE_TIME', 3600); //Token is valid for an hour, adjust as desired. $details = isset($_SESSION['downloadTokens'][$_GET['token']])?$_SESSION['downloadTokens'][$_GET['token']]:null; if (!$details || time()-$details['initiated'] > GRACE_TIME){ header('HTTP/1.0 404 Not Found'); header('Status: 404'); echo 'Token not valid.'; exit; } //download the file.
-
You'll need to use GMP to store the addresses and compare against a given prefix. If your PHP build supports IPv6, you can use inet_pton to convert the human-readable address into a binary number. If you do not have IPv6 support, you will have to find or create your own parser for IPv6 addresses. For example: $address = '2620:149:f01:2b0:99ad:f010:61c1:63c5'; $network = '2620:149::/36'; $address = inet_pton($address); $address = gmp_init(bin2hex($address), 16); if (false !== $pos=strpos($network, '/')){ $prefix = substr($network, 0, $pos); $bitlength = substr($network, $pos+1); $network = inet_pton($prefix); $network = gmp_init(bin2hex($network), 16); $mask = str_repeat('1', $bitlength).str_repeat('0', 128-$bitlength); $mask = gmp_init($mask, 2); } else { $network = inet_pton($prefix); $network = gmp_init(bin2hex($network), 16); $mask = str_repeat('1', 128); $mask = gmp_init($mask, 2); } $masked_address = gmp_and($address, $mask); $masked_network = gmp_and($network, $mask); if (gmp_cmp($masked_address, $masked_network) === 0){ echo 'address is within the network.'.PHP_EOL; } else { echo 'address is not within the network.'.PHP_EOL; }
-
is it possible? Find the number of list items and split into 2 cols
kicken replied to peppericious's topic in Javascript Help
You could just use CSS to split the list. Adjusting the width would let you get more columns in, and if the screen size shrinks it will automatically collapse back to a single column. -
So it's about time for a new office chair. My current one is fairly beat up and I think it's poor state might be contributing to some knee pains I've been having lately. It doesn't sit at the right height because the hydraulic is busted and I had to improvise a new base after the casters broke on it which gets in the way and is harder to roll around on. Rather than go get a cheap chair from an office store I figured I'd look for something that might be better quality and last longer. As such I'd like to ask for any recommendations you all have for chairs you may have bought and found to be comfortable and reliable. Let me know any thoughts you have.
-
SMS blogging, do I need a spare line?
kicken replied to moose-en-a-gant's topic in Application Design
Most providers allow you to "text" an email rather than a phone number. Given this some places will just setup a special email that they send texts too and then use a script to monitor new messages to that account and post them. I did this for a while many years ago. If you prefer to send the texts to a phone number instead, you'll need to use a service such as Twilio to receive the texts. They will then call out to a script on your site with the information about the message received which you can then post. I've used them for a password reset application and also an appointment confirmation system before. -
Blog comments and what the average user expects from them.
kicken replied to njdubois's topic in Application Design
I'd suggest that you let people register/login through some well known site like facebook, google, twitter, etc. I know personally I am somewhat more apt to sign up and try something if I can just hit "Login with google." If I have to create a unique account just for that site then it's not worth my time and I move on. I suspect many people would think similarly. -
Joining two tables and returning fields from MAX(id) row
kicken replied to Landslyde's topic in MySQL Help
maxHistory is just a table alias for the sub-query. It provides a way to reference the temporary table created by the sub query for the join condition. It's just like where I did FROM attendees a to alias the attendees table to a. Rather than a simple table name though you have a sub-query to define the table. -
Joining two tables and returning fields from MAX(id) row
kicken replied to Landslyde's topic in MySQL Help
If you want the most recent payment, you don't want MAX(historyid), you want MAX(last_payment). You shouldn't assume that a higher ID value means newer data. Always test against an actual date value that will tell you what data is newer. Once you get MAX(last_payment) then you join back to the history table using that value to find the row that corresponds to that date. For example: select a.fname , a.lname , a.address1 , a.city , a.state , h.historyid , h.last_payment , h.amount from attendees a INNER JOIN (SELECT attendeeid, MAX(last_payment) as last_payment FROM history GROUP BY attendeeid) maxHistory ON maxHistory.attendeeid=a.attendeeid INNER JOIN history h ON a.attendeeid = h.attendeeid AND h.last_payment=maxHistory.last_payment WHERE a.attendeeid=2 See the sample sql fiddle to see it in action. Note that unless last_payment is unique, this could still get you multiple rows of data. If there is potential for multiple history entries on the same date, you'll need to decide how to handle that. Either choose another date/time field that will be unique or combine the last date with something else. -
It may not be dangerous per-say if you can guarantee it only ever runs your files and never anything submitted by another person. It's still not good either. For what you mentioned as your needs, all you really need to do is implement a simple find and replace system. <img src="{CURRENT_DIR}/hidden/someimage.jpg" alt="someimage"> $code = file_get_contents($file); $code = str_replace('{CURRENT_DIR}', $_SESSION['currentClickDirUrl'], $code); echo $code;
-
Can't download exe file from server to clent's browser
kicken replied to Absolvium's topic in PHP Coding Help
In addition to reading the file contents, you also need to set appropriate headers to tell the browser to save the file. You do this with the header function. There are examples in the manual or all over the internet if you search. -
It's because the browser initially requests the URL. Once it determines that it's content it can't handle and needs to be downloaded it passes the URL off to a separate download manager application which will then re-request the url and complete the download in the background. This behavior is by design, there isn't anything you can do to make it issue only a single request.
-
It's generally advisable to leave CURLOPT_SSL_VERIFYHOST enabled. If you're using a self-signed certificate, you just need to tell CURL to trust it by using CURLOPT_CAINFO. Save the server's certificate somewhere locally and then use code like: $ch = curl_init('https://example.com/'); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, '/path/to/example.crt'); curl_exec($ch); You'd still have to make sure that your self-signed certificate doesn't expire, but you could set the expiration date for like 10 years in the future or something when generating it.
-
On a generic level, you can request a particular element be shown full screen in modern browsers. You should check whatever script/API you're using to see if they provide something specific for full screen mode first.