QuickOldCar
Staff Alumni-
Posts
2,972 -
Joined
-
Last visited
-
Days Won
28
Everything posted by QuickOldCar
-
30k usernames, need to remove all females, is this a good way?
QuickOldCar replied to WinterSummer's topic in PHP Coding Help
Can't you tell the text file there is a big shoe sale? There are names that males and females share. -
There isn't any $edit-id variable, I see a possible $no or $project_id can use. You can do this with header() instead, even with a message and delay if wanted to. Additionally use exit; after header() so the rest of the script does not continue.
-
How to prevent txt files from getting cached?
QuickOldCar replied to Krystal's topic in PHP Coding Help
It's simply appending a ?number to the end of the urls In js you can use math.random() and in php I used mt_rand(); Is many ways to create a random number. Some changes. If you want to add additional scroll to top or to positions can make a new js function to do that and include the window.open as well. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Files</title> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="-1"> <style> .listfiles{ display:block; position:relative; width:120px; margin:0; padding:0; text-decoration:none; } </style> </head> <body> <div> <?php $files = array(); $dir = opendir('logs'); while (false != ($file = readdir($dir))) { if (strpos($file, '.txt') !== FALSE) { $files[] = $file; } } natsort($files); $files = array_reverse($files); foreach ($files as $file) { $random = mt_rand(1, 99999999); $location = "http://" . $_SERVER['SERVER_NAME'] . "/logs/$file?$random"; echo "<a class='listfiles' href='$location' onclick='window.open('$location', '_blank');'>$file</a>"; } ?> </div> </body> </html> -
Doesn't matter what or how you access it, the point is the chat server itself doing the work and able to do it.
-
https://secure.php.net/manual/en/index.php
-
You should use websocket for a chat, constant polling php is too much usage for the server. http://socket.io/get-started/chat/ http://tutorialzine.com/2014/03/nodejs-private-webchat/ http://www.sanwebe.com/2013/05/chat-using-websocket-php-socket You can search for others, this is the basic idea.
-
I guess I should have written there could be different $_GET, $_POST, $_COOKIE and $_REQUEST variables but not the three that were defined in that if statement. Such as if one or all three of these did not exist $uname = $_REQUEST["set_username"]; $email = $_REQUEST["set_email"]; $pword = $_REQUEST["set_password"];
-
You can use time or date right in a cron job command and then save it to a log, then you parse your log data. I prefer to log something through the script itself. You can do a start/end in the php script itself and log to a database. Two timestamps for instance, you know when it started and when it ended, you can do calculations on the timestamps and whatever cron periods you have the jobs set for. If you need live data could poll the data with jquery or js/ajax
-
SELECT statement, Multiple WHERE, with requirements
QuickOldCar replied to BuildMyWeb's topic in MySQL Help
If you want them neatly categorized like you say, five queries is most likely the easiest way. I had some code to do multiple LIKE and even another doing REGEXP, you can query x many results, but that wouldn't guarantee are going to get 50 results each region. Using one table for this should be just as fast as trying to use five if is indexed properly. You may be thinking if need to pull specific region data it could be easier if each had it's own table. (still be five queries and now using JOIN when need all the data) If is just five regions I wouldn't worry about it, if was a lot of them I would do multiple tables. -
That's the best time to use it. I use DOM a lot in api's, crawling, scraping or data parsing. A lot of times I combine DOM and SimpleXML.
-
For security sake use the password_hash and password_verify functions. $_REQUEST is always set so if($_REQUEST){ is useless $results = $conn->query("SELECT * FROM strea345_db1 where username='$USERNAME' AND password='$PASSWORD'"); First check your query statement and php doesn't parse within single quotes. $sql = "SELECT * FROM strea345_db1 where username='".$USERNAME."' AND password='".$PASSWORD."'"; echo $sql; $results = $conn->query($sql); if (mysqli_num_rows($result) > 0){ //code... } else { //handle results not being there }
-
unlinking a file suddenly stopped working. Any ideas why?
QuickOldCar replied to sonnieboy's topic in PHP Coding Help
Check to see if any of your database tables are corrupt and repair them. -
Might need to translate this to english.
-
unlinking a file suddenly stopped working. Any ideas why?
QuickOldCar replied to sonnieboy's topic in PHP Coding Help
What is the $file value? It must not be returning results from the query and the 0 is the false value. -
That location is the form itself. You are using POST in your form and checking for POST values as well, if you wanted to pass additional parameters and values into the url need to use GET $editFormAction = $_SERVER['PHP_SELF'];//bad idea to use this if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); //you won't get a query string with form values because using POST for the form, need to use GET if want to pass these into the url } see all this? $insertGoTo = "HTTP_REFERER"; //should be $_SERVER['HTTP_REFERER'] if (isset($_SERVER["HTTP_REFERER"])) { //it's always going to be set, what it returns is another story header("Location: " . $_SERVER["HTTP_REFERER"]); exit; //always use exit after a header redirect } //header(sprintf("Location: %s", $insertGoTo)); //don't need this, would do the same as the above check, concatenation is done with a decimal point not a comma } Since you already check post variables from the form all you need to do is redirect from their referer location (in your case this would be the original form) This is a simple example how to handle a header redirect to it's previous location. I added a check to see if came from your domain, if not would redirect them to the main page if ($_SERVER['SERVER_NAME'] == @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST )) { $insertGoTo = $_SERVER["HTTP_REFERER"]; }else{ $insertGoTo = "http://" . $_SERVER['SERVER_NAME']; } header("Location: " . $insertGoTo); exit; If you wanted to continue doing the rest of your code after this move this header redirect lower Edit: I wanted to add this code would work fine because of the check for POST values, be sure not to cause an infinite loop with redirects when using header()
-
unlinking a file suddenly stopped working. Any ideas why?
QuickOldCar replied to sonnieboy's topic in PHP Coding Help
If magic constants is actually enabled it returns that folders directory path You can define it if it's not. if (!defined('__DIR__')) { define('__DIR__', dirname(__FILE__)); } if you have some sort of rewrite rule for the site the code is still seeing it's original path. You can easily set this manual versus using __DIR__ $thisfile = 'E:\inetpub\wwwroot\Train\Boards/uploads/'.$file; Hard to suggest anything beyond that because do not know anything else about your file structure or rewrite rules. -
glob() or scandir() would be the better way. You could even use stat(), fileperms(), fileowner() or other functions to show the user only files that have a certain permission or belong to that user. Echo html out, no need to use dom.
-
unlinking a file suddenly stopped working. Any ideas why?
QuickOldCar replied to sonnieboy's topic in PHP Coding Help
If the current code worked before and was no changes to it...is most likely something else, file permissions maybe? -
$create = fopen($filename, "w"); http://php.net/manual/en/function.fopen.php 'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. In this mode, fseek() only affects the reading position, writes are always appended. $create = fopen($filename, "a+"); It would be better to build your variable or array in the loop and write it all at the same time to the file after the loop.
-
There won't be any code snippets you can easily add in, you have to make a database and do the forms and queries, learn and do the coding or have someone that does. You can save as flat files, but that's not a good way to do it these days when is something better.(still requires coding) There are text editors that makes saving and editing a little easier to implement and some features. http://ckeditor.com/ http://www.tinymce.com/ You will still have to save this data somewhere. If you are willing to dive into php I will point you to the manual https://secure.php.net/manual/en/index.php It may seem like a "simple wordpress" but they spent many years and lots of people to get that to do what it does. I respect people wanting to do something from scratch and willing to learn, in this case as you explained because time limited, wordpress or another premade cms may be the route to take.
-
Facebook has their sdk, app, and tokens to share on their site. https://developers.facebook.com/docs/reference/php/5.0.0 Then there is the sharing. https://developers.facebook.com/docs/sharing/web
-
fputs(file,string,length) so you need the directory location and also a file name to save the data to $destination = "archive/source_1.html";
-
You are trying to write to a directory and not a file $destination = "archive";
-
Temporary working while loop selection
QuickOldCar replied to CloudBreaker's topic in PHP Coding Help
do a query for the data to populate the form if the query returned no results would be an insert if the query returned results and it populated the post fields, do the update on the submit It's up to you if want to just update all values or do checks if anything is different and dynamically build the query for the update. Alternately you can do something more advanced and do ajax on each form input, something like a live edit