Jump to content

oz11

Members
  • Posts

    169
  • Joined

  • Last visited

Everything posted by oz11

  1. Thanks so much for helping me man. I'll "normalized" the db and it all functions way better now. Thanks. Took me till 6:30 am but its done. I thought originally I was doing ok, but a properly 'lized DB is the way to go. woo
  2. Hey.. i have this code. Though the form is shown on the page after entering the password, and its gone as desired when I reload the page.. how do I get it to not show on the next page before having to reload?? $room = $_GET['room']; $salt = 444422; if($_SESSION['in_chat']!=$room.$salt){ $stmt = $pdo->prepare("SELECT pass_code FROM `chatrooms` WHERE name =?"); $stmt->execute([$_GET['room']]); $pass_checker = $stmt->fetch(); $hash = $pass_checker['pass_code']; if($hash!=null AND $_SESSION['in_chat']!=$room.$salt){ ?> <form action="" method="POST" name="passcheck"> <input type="password" name="password_"><input type="hidden" name="chat_pass"><input type="submit" value="Submit"></form> <?php } if(isset($_POST['password_'])) { if(!password_verify($_POST['password_'], $pass_checker['pass_code'])) { echo "Wrong password"; exit; } else{ $_SESSION['in_chat'] == $room.$salt; } } else{ exit(); } } Note: "salt" is just there so i can test the sessions without resetting. Thanks!
  3. Do you also happen to know how to get other words after the first ones to show up with different alphabetical pages? Like "magazine" wont show as it's not the first in the line, thus not showing under 'M'. .. and 9/11 wont show under '9' either.. Code update: echo $_SERVER['REQUEST_URI']; echo "<br><hr>"; $stmt = $pdo->prepare("SELECT DISTINCT terms FROM links WHERE terms LIKE ? OR terms like ? GROUP BY terms"); $stmt->execute(array("$alpha%", ", $alpha%")); $data = $stmt->fetchAll(); $index = 0; echo "<ul>"; foreach ($data as $result_tag) { $one = implode(', ', $result_tag) . ""; $two = strtok($one, ',') . "<br>"; $three = strtolower($two); $words = explode(" ", $three); $unique_words = array_unique($words); echo "<li>".$string = implode(" ", $unique_words)."</li>"; } echo "</ul>"; echo '<pre>' . var_export($data, 1) . '</pre>'; exit(); Edit: I apologize for jumping ahead. One thing at a time i guess.. is it OK to talk about both in the same thread? :/
  4. Hey (again :).. This is the code I'm working on but can't figure out to the heck of me how to remove these duplicate "words"/strings... A small sample of the output is added to the upload so you can see what I mean.. HELP! ps: a few comments have been left there for testing. $stmt = $pdo->prepare("select DISTINCT terms from links WHERE terms LIKE ? GROUP BY terms"); $stmt->execute(array("$alpha%")); // fetching rows into array $data = $stmt->fetchAll(); //echo gettype($data); foreach($data as $result_tag) { $one = implode(', ',$result_tag) . ""; $two = strtok($one, ',')."<br>"; //echo gettype($two); //echo strtolower($two); $three = strtolower($two); //print_r($three); $string = implode(" ", array_unique(explode(" ", $three))); //echo gettype($string); echo $string; } exit();
  5. Hey. Thanks for the help.. here is my working code 4 anyone else..,. <?php $join_terms = ""; $stmt = $pdo->prepare("select terms from links"); $stmt->execute([]); while ($row = $stmt->fetch()) { $join_terms = " ".$join_terms . $row['terms'].", "; } $frequent = implode(' ', array_unique(explode(' ', $join_terms))); $myArray = explode(',', $frequent); sort($myArray); print_r($myArray);
  6. Turns out its not an array
  7. Hey. I shortened the code.. <?php $join_terms = ""; $stmt = $pdo->prepare("select terms from links"); $stmt->execute([]); while ($row = $stmt->fetch()) { //echo $row['terms']."<br />\n"; $join_terms = " ".$join_terms . $row['terms']." "; } $frequent = implode(' ', array_unique(explode(' ', $join_terms))); $frequent = str_replace(",", "", $frequent); print_r($frequent); ?> Can I loop through the $frequent array and then finally sort?
  8. This is my code.. though it only sorts by occurrences atm.. how do i get it to sort by alphabetical order?? <?php function most_frequent_words($string, $stop_words = [], $limit = 10000) { $string = strtolower($string); // Make string lowercase $words = str_word_count($string, 1); // Returns an array containing all the words found inside the string $words = array_diff($words, $stop_words); // Remove black-list words from the array $words = array_count_values($words); // Count the number of occurrence arsort($words); // Sort based on count return array_slice($words, 0, $limit); // Limit the number of words and returns the word array } $join_terms = ""; $stmt = $pdo->prepare("select terms from links"); $stmt->execute([]); while ($row = $stmt->fetch()) { //echo $row['terms']."<br />\n"; $join_terms = " ".$join_terms . $row['terms']." "; } $dupl = implode(' ', array_unique(explode(' ', $join_terms))); $dupl = str_replace(",", "", $dupl); $stop_words = array(""); $frequent = most_frequent_words($dupl, $stop_words); //print_r($frequent); ?> <small id="pop_terms"> <?php if(is_array($frequent)){ foreach($frequent as $k=>$value) { $encode = base64_encode($k); echo "<a href='../tags.php?q=". $encode."'>". $k."</a>, " ; // $k is the key if ($k === array_key_last($frequent)) { echo "."; } } } ?> I must have nabbed abit of code from somewhere a while ago . Just cant get my head around it. Helpz plz.
  9. Nevermind I think if i rejigg the parts of the code i can get it to "fit" better. Thanks again. I know the limitations of the code i posted especially with the capacha part and order.
  10. Hey! Thanks! I updated a bit of code Rendition: $err = 0; if($_SERVER['REQUEST_METHOD'] === 'POST'){ if(isset($_POST["submit"])) { if(empty($_POST['title'])){ echo "Missing title"; $err=1; } if(empty($_POST['tags'])){ echo "Missing tags"; $err=1; } if(empty($_POST['descr'])){ echo "Missing description"; $err=1; } if( empty($_POST['descr']) OR empty($_POST['tags']) OR empty($_POST['title'])){ echo "Eror missing values"; exit(); } if(empty($_FILES["fileToUpload"]["name"])){ echo "Eror missing upload"; exit(); } if($_FILES["fileToUpload"]["error"]!='0'){ echo "Eror in upload --"; echo $_FILES["fileToUpload"]["error"]; echo "--"; exit(); } }} It checks through without problem , echos name and error (which was zero/0).. but when the captcha form at the bottom of the page is run then the $_FILE goes blank.. ("form after form") help. Maybe my code is just really problem'd. ? Sure,it looks troubled but, what do i do ? How do i make it persist...? I normally just shove them (like now) in hidden inputs.. security problem?
  11. Could it be down to the naming of my fields, particularly "fileToUpload" ?
  12. For some reason, my file upload is not running. Could someone glance over this code for me... I'm having trouble POSTING (or whatever) the $_FILES array information. Never used this type much in the past. proceed_2.php (goto: from form) <?php include 'includes/config.php'; session_start(); date_default_timezone_set('Europe/London'); ?> <div id='main'> <?php $err = 0; if(isset($_POST["submit"])) { if(empty($_POST['title'])){ echo "Missing title"; $err=1; } if(empty($_POST['tags'])){ echo "Missing tags"; $err=1; } if(empty($_POST['descr'])){ echo "Missing description"; $err=1; } if( empty($_POST['descr']) OR empty($_POST['tags']) OR empty($_POST['title'])){ echo "Eror missing values"; exit(); } } if (isset($_POST['title']) AND isset($_POST['descr']) AND $_POST['tags']){ $newDate = date('Y-m-d H:i:s', strtotime($expired. ' +1 minutes')); $sql = "UPDATE `users` SET `expired` = ? WHERE `users`.`user_id` = ?;"; $stmt= $pdo->prepare($sql); $stmt->execute([$newDate, $_SESSION['userID']]); echo "<b>Submitted thanks!</b>"; $le_random_string = bin2hex ( random_bytes ( 2 )); // ------------ INSERT INTO DB - START ---------------- $sql = "INSERT INTO pending (url, title, terms, user_id, description, is_upload) VALUES (?,?,?,?,?,?)"; $stmt= $pdo->prepare($sql); $stmt->execute([$_POST['fileuploadname'], $_POST['title'], $_POST['tags'], $_SESSION['userID'], $_POST['descr'], 1]); // ------------ INSERT INTO DB - END ---------------- // -- FILE OPERATION -START $target_dir = "data/pending/"; if(isset($_FILES["fileToUpload"]["name"])){ $target_file = $target_dir . "11".$le_random_string.basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { //echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { //echo "File is not an image."; //$uploadOk = 0; // $uploadOk = 1; // <-- } } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if (isset($_FILES["fileToUpload"]["size"]) AND $_FILES["fileToUpload"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "pdf" && $imageFileType != "txt") { echo "Sorry, only PDF & TXT files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded."; echo "<br><br><b>Hash:</b><br>".hash_file('md5', 'data/pending/'.$_FILES["fileToUpload"]["name"]); } else { echo "Sorry, there was an error uploading your file."; } }} // -- FILE OPERATION -END*/ header ("location: submit.php?back=201"); // SUBMITTED AND RETURNED TO MESSAGE include 'includes/top_bottom/footer.php'; exit(); } ?> //echo $status; <form name="form" method="post" action=""> <input type="hidden" name="randcheck" value="<?php echo $_POST['randcheck']; ?>"> <input type="hidden" name="title" value="<?php echo $_POST['title']; ?>"> <input type="hidden" name="tags" value="<?php echo $_POST['tags']; ?>"> <input type="hidden" name="descr" value="<?php echo $_POST['descr']; ?>"> <input type="hidden" name="fileuploadname" value="<?php echo basename($_FILES['fileToUpload']['name']); ?>"> } upload_file.php (form) <form action="proceed_2.php" method="post" enctype="multipart/form-data"> <div class="boxer"> <div class="box-row"> <div class="box" style="padding: 10px; border: 0px;">Document title: </div> <div class="box" style="padding: 10px; border: 0px;"><input type="text" name="title" style="width:400px;" value="<?php if(isset( $_POST['title'])) echo $_POST['title']; ?>"><br></div> </div> <div class="box-row"> <div class="box" style="padding: 10px; border: 0px;">Descriptive tags: </div> <div class="box" style="padding: 10px; border: 0px;"><input type="text" name="tags" placeholder="tag1, tag2, tag3, etc." style="width:400px;" value="<?php if(isset($_POST['tags'])) echo $_POST['tags']; ?>"><br><small>Sperate by comma or space</small></div> </div> <div class="box-row"> <div class="box" style="padding: 10px; border: 0px;">Description: </div> <div class="box" style="padding: 10px; border: 0px;"><textarea name="descr" style="width:400px; height: 100px;" placeholder="(Optional)" ><?php if(isset($_POST['descr'])) echo $_POST['descr']; ?></textarea></div> </div> <div class="box-row"> <div class="box" style="padding: 10px; border: 0px;">Published year: </div> <div class="box" style="padding: 10px; border: 0px;"><input type="text" name="tags" placeholder="Year, eg: '2028'" style="width:400px;" value="<?php if(isset($_POST['publ_date'])) echo $_POST['publ_date']; ?>"><br><small></small></div> </div> </div> <div style="background-color: white; border: 1px solid black; padding: 20px; margin: 10px; border-radius: 20px;"> <input type="file" name="fileToUpload" id="fileToUpload"> <input style="padding: 10px;" type="submit" value="Upload Document" name="submit"> </form> I just keep an eye on the upload folder and nothing gets written. :S I chopped up the code abit to be posted, if it fails then I can post the whole thing.. note: some mistakes here, because the code was chopped up to e shown here. But, generally, the question is still relevant. What me doing wrong :S I thought it would just work like any POST value..?.. ... Everything works fine.. just not getting the data into this [extract]... // -- FILE OPERATION -START $target_dir = "data/pending/"; if(isset($_FILES["fileToUpload"]["name"])){ $target_file = $target_dir . "11".$le_random_string.basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { //echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { //echo "File is not an image."; //$uploadOk = 0; // $uploadOk = 1; // <-- } } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if (isset($_FILES["fileToUpload"]["size"]) AND $_FILES["fileToUpload"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "pdf" && $imageFileType != "txt") { echo "Sorry, only PDF & TXT files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded."; echo "<br><br><b>Hash:</b><br>".hash_file('md5', 'data/pending/'.$_FILES["fileToUpload"]["name"]); } else { echo "Sorry, there was an error uploading your file."; } }} // -- FILE OPERATION -END*/ ..where is $_FILES["fileToUpload"]? Is it reaching? ..
  13. this code worked for me. . Thanks again! <script type="text/javascript"> function showDiv(divid) { var x = document.getElementById(divid); if (x.style.display === "none") { x.style.display = "block"; } else { x.style.display = "none"; } } </script>
  14. Know how to get it to hide on second click?
  15. Thanks pal. Just to finalise this was the [whole] working code: <script type="text/javascript"> function showDiv(divid) { document.getElementById(divid).style.display = "block"; } function hideDiv(divid) { document.getElementById(divid).style.display = "none"; } </script> <a name="answer" value="Show Div" onclick="showDiv('one')" >Show</a> <div id="one" style="display:none;" class="answer_list" > <h2>Hello</h2> <button onclick="hideDiv('one')" class="loginBut" style="font-family: 'Handjet', cursive; font-size: 2EM;">Close</button> </div> <a name="answer" value="Show Div 2" onclick="showDiv('two')" >Show</a> <div id="two" style="display:none;" class="answer_list" > <h2>Hello2</h2> <button onclick="hideDiv('two')" class="loginBut" style="font-family: 'Handjet', cursive; font-size: 2EM;">Close</button> </div>
  16. Please could you help.. I need to make this code allow me to use the showDiv function multiple times on the page.. <script type="text/javascript"> function showDiv() { document.getElementById('welcomeDiv').style.display = "block"; } function hideDiv() { document.getElementById('welcomeDiv').style.display = "none"; } </script> <a name="answer" value="Show Div" onclick="showDiv()" >Show</a> <div id="welcomeDiv" style="display:none;" class="answer_list" > <h2>Hello</h2> <button onclick="hideDiv()" class="loginBut" style="font-family: 'Handjet', cursive; font-size: 2EM;">Close</button> </div> Thanks. It seems I need to add an index variable to the function. Don't know how though.. I'm new to JS.
  17. $dateInLastHour = strtotime('-1 hours'); $dateInLastDay = strtotime('-1 days'); $dateInLastWeek = strtotime('-1 weeks'); $stmt = $pdo->prepare("SELECT string, q_id, count(string), date FROM queries WHERE IP=? AND session_tokn=? AND cleared=0 AND date > ? GROUP BY string ORDER BY q_id DESC LIMIT 200"); $stmt->execute([$ip, $_SESSION["history"], $dateInLastHour]); echo "<ul>"; while ($row = $stmt->fetch()) { if($row['count(string)'] == 1){ echo "<li><a title='".$row['date']."' href='?q=".$row['string']." ' >\"".$row['string']."\"</a></li> "; } else { echo "<li><a title='".$row['date']."' href='?q=".$row['string']." ' >\"".$row['string']."\"</a> <small>(x".$row['count(string)'].")</small> </li>"; } } echo "</ul>"; echo "</div></small></center>"; Hey freaks. Why can't i get this working? I'm planning on having three loops, one for hour, one for day and the other for week.. I'm really bad at interpreting maths but ok at conditionals.. help please. Should show the results in terms of the time scales
  18. Hye. Quick question!.. <details> <summary>Details</summary> Something small enough to escape casual notice. </details> How can I make this [ https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details ] display on hover rather than "click"?? thanks.!
  19. Came down to a Take time with Franken code!
  20. Nevermind. seems to work in an independent html fil so its own to some php-related business. Closed.
  21. made some changes.. not a positive result but thought i should show you...... <details style=" display: inline;"><summary><?php echo $item; // $k is the key ?></summary> <div style="border:1px solid pink; padding: 10px; position: absolute; color: red"> Search <br>or...</div> </details> Weird overlapping .
  22. <details style=" display: inline;"><summary><?php echo $item; ?></summary> <div style="border: 1px solid black; padding: 4px; border-radius: 5px; position: absolute; background-color: white; box-shadow: rgba(17, 17, 26, 0.1) 0px 1px 0px, rgba(17, 17, 26, 0.1) 0px 8px 24px, rgba(17, 17, 26, 0.1) 0px 16px 48px; text-align: left; opacity: 0.82; height: 100px;"> Search <br>or... </div> </details> Hey freaks (again). HTML question this time .. why is my details element now showing the second line. See image bellow: only shows "search" and not "or.." . Thanks!
  23. It's doing it for results that don't contain.. anyway. Nevermind its unnecessary since my PDO's are fine. Thanks.
  24. Thanks btw!
  25. For some reason it kills my page. :/ All white.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.