![](https://forums.phpfreaks.com/uploads/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
QuickOldCar
Staff Alumni-
Posts
2,972 -
Joined
-
Last visited
-
Days Won
28
Everything posted by QuickOldCar
-
I don't see anything wrong with using open source such as http://www.opencart.com/, possibly integrate it into wordpress,joomla or your own cms? I guess if you are trying to do something special and all of the open source solutions would be too hard to modify....make your own. You will need the skill and a lot of time. Is probably not too many people out there that can make a complete and fairly secure store.
-
Show the code that gets the comments and displays it.
-
Try this version using preg_match, I did a little testing and seemed to work ok, although may be even better looking with parsed urls as well <?php function checkUrl($url) { $allowed = FALSE; if (trim($url) != '') { $good_domains = array( "youtube.com", "google.com", "facebook.com", "twitter.com" ); $bad_domains = array( "bad-site.com", "real-bad.com" ); $urlreg = '/^(((?:http|https|ftp)):\/\/)?(www?[0-9]*?\.)?(([a-zA-Z0-9][[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]]?)\.)?([a-zA-Z0-9][[[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]]?\.]*[a-zA-Z]{2,6})(\/.*)?$/'; preg_match($urlreg, $url, $matches); if ($matches) { foreach ($matches as $match) { if (in_array($match, $good_domains) && !in_array($match, $bad_domains)) { $allowed = TRUE; } } } } return $allowed; } //end checkUrl function //simple usage example $url = "http://google.com"; //$url = "http://site.google.com"; //$url = "https://maps.google.com"; //$url = "http://bad-site.com"; if (checkUrl($url) === TRUE) { echo "allowed"; } else { echo "not allowed"; } ?>
-
Because is domains and subdomains it makes this difficult unless parsing the actual main hosts from the url I did this a very complicated function, the code provided will do for exact domains and subdomains.
-
Is a few ways to go about it, this is my preferred method. Can make an array of allowed sites, then using in_array() to allow, or can even do an additional not in array and blocking too First you can parse the url with parse_url() Should add a check for protocols like http,https,etc or parse_url fails <?php function checkUrl($url) { $allowed = FALSE; if (trim($url) != '') { $good_domains = array( "youtube.com", "google.com", "facebook.com", "twitter.com" ); $bad_domains = array( "bad-site.com", "real-bad.com" ); $parsedUrl = @parse_url(trim(strtolower($url))); $domain = trim($parsedUrl['host'] ? $parsedUrl['host'] : array_shift(explode('/', $parsedUrl['path'], 2))); $domain = ltrim($domain, "www."); if (in_array($domain, $good_domains) && !in_array($domain, $bad_domains)) { $allowed = TRUE; } } return $allowed; } //end checkUrl function //simple usage example $url = "http://google.com"; //$url = "http://bad-site.com"; if (checkUrl($url) === TRUE) { echo "allowed"; } else { echo "not allowed"; } ?>
-
Additionally that xml result returns an ip error check, maybe they only do allowed ip's. <error>Fails Check ip: 192.168.0.1</error>
-
People help others here all the time. From what I get as to "the curl changed"....you mean the sites address or additional parameter needed to access their information has changed. First off, someone here probably won't try the script because we don't know what the id,user_id or key is. Does it connect and is there data if you echo out the raw html? echo $data;
-
If this all started to happen after a server crash, maybe your database table is corrupted, try to use a mysql manager and repair the tables
-
I like bsmither's way with curly braces, helps keep coding consistent and never forget them when needed. My opinion of course. while ($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { $roster[] = $row; } echo json_encode($roster);
-
Since you are new and learning, you should use all mysqli_* versus mysql_* functions. http://www.php.net/mysqli_connect
-
Missing closing curly brace, also made it die() if(!link){ die ("Not Connected to DB" . mysqli_connect_error()); }
-
Creating a CRUD application for the MySQL database
QuickOldCar replied to dbdavis55's topic in PHP Coding Help
Help in what way? Homework is meant so you actually learn something from it. If have a particular question about how to do something am sure people will help. -
What's the exact error?
-
Do what exactly? If it's how to save all the items into mysql database, do one large insert query including a column for that users id, order id...maybe both... or however you do it. You would need to show some sort of code and expalin better what you want to do, question is too vague.
-
Is nothing obvious to me why it would. in wp-config.php you can either edit or add these lines to show errors and try to debug it. define('WP_DEBUG_DISPLAY', true); ini_set('display_errors',1);
-
What's the error? Did you ask Johannes Zinnau johannes@johnimedia.de and see if he knows what issue could be?
-
How is something like this? //Set initial output to false $tData = false; $entries = simplexml_load_file($data); if(count($entries)): //Registering NameSpace $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); $result = $entries->xpath("//prefix:entry"); //no need to include files over and over in a loop, keep outside the loop include ('inc-alert-colors.php'); //create an array of desired warnings $warnings = array("Flash Flood Watch", "Flash Flood Warning", "Severe Thunderstorm Watch", "Severe Thunderstorm Warning", "Torndao Watch", "Torndao Warning"); foreach ($result as $entry){ $event = trim($entry->children("cap", true)->event); if (in_array($warnings, $event)){ //need to set it's colors? switch ($event) { case "Flash Flood Watch": $color = "limegreen"; break; case "Flash Flood Warning": $color = "darkred"; break; case "Severe Thunderstorm Watch": $color = "palevioletred"; break; case "Severe Thunderstorm Warning": $color = "orange"; break; case "Torndao Watch": $color = "yellow"; break; case "Torndao Warning": $color = "red"; break; } echo "<p style='color:".$color.";'>".$event."</p>"; } } }
-
That's some crazy time stuff you have going on there, here is an example of a function to use normal date and timestamp functions? Then it's simple to add 24 hours or whatever need to do. returns: 2014-04-20 12:00:00 2014-04-21 12:00:00 <?php $date_string = "20140420120000"; function jumbledDate($date_string){ return $date_string[0].$date_string[1].$date_string[2].$date_string[3]."-".$date_string[4].$date_string[5]."-".$date_string[6].$date_string[7]." ". $date_string[8].$date_string[9].":".$date_string[10].$date_string[11].":".$date_string[12].$date_string[13]; } $date_and_time = jumbledDate($date_string); echo $date_and_time."<br />"; $tomorrow_date = date('Y-m-d H:i:s', strtotime($date_and_time . ' + 1 day')); echo $tomorrow_date."<br />"; ?>
-
how to get items from your database into your php form
QuickOldCar replied to dario's topic in PHP Coding Help
Making a store isn't for beginners. I'm with bsmither by using something already done unless you are willing to spend time and actually learn how to do everything.. It's like making your own CMS plus is a store. So pretty much you want to make something like http://assembleyourpc.net/ ? -
If you wanted a natural sorting of numbers you would use natsort() otherwise numbers group by similar digits and not how say a normal person counts 1 11 111 2 22 222
-
Use web browser engine to extract URLs from a page?
QuickOldCar replied to KingNeil's topic in PHP Coding Help
As in the case for ArsTechnica.com, they use relative paths versus absolute paths for their href links. To sum it up you have to determine what type path they use and fix accordingly by appending the protocol, host and any paths to the beginning I do this with a relative links function I made along with knowing the targeted scrape location to go by. I'll try to explain as simply as can A path is a slash separated list of directory names followed by either a directory name or a file name. A directory is the same as a system folder. relative paths: hash tag # (by itself directs to same page, if a fragment is added usually an anchor tag on the same page......but sites have been using them to navigate entire sites or scripts with them over the years) no identifier (just a directory or file) will append own host same directory / root directory ./ up one directory ../ up two directories ../../ up three directories ../../../ on and on for up directories absolute paths: any url (more correctly called uri) that includes the protocol and host with optional others following it just a few examples, is way too many to list every possible type. http://user:password@subdomain.domain.tld.sld:port/directory/file.ext?query=value#fragment http://subdomain.domain.tld http://subdomain.domain.tld.sld/folder/script.php http://domain.tld/script.php local paths: sometimes linked when are outside of the www directory C:\folder\ C:\folder\file C:/folder/file.ext \\folder\file I wrote this using simple_html_dom with functions to fix some issues Can test it at http://dynaindex.com/link-scrape.php Is more to it than meets the eye, I actually have a much longer and complicated relative links function that does much more, this should get you by. <form action="" method="GET"> <input type="text" name="target" size="100" id="target" value="" placeholder="Insert url to get links" /> <input type="submit" value="Get the links" /> <br /> </form> <?php //check if target is set and not a blank value if (isset($_GET['target']) && trim($_GET['target']) != '') { //requires simple_html_dom include 'simple_html_dom.php'; //clean input url $target_url = htmlspecialchars(trim($_GET['target']), ENT_QUOTES, 'UTF-8'); $target_url = filter_var($target_url, FILTER_SANITIZE_URL); //check input url for http or https or file_get_contents fails if (!preg_match("~^(http|https)://~i", $target_url)) { $target_url = "http://" . $target_url; } echo "<h2>Links from " . rawurldecode($target_url) . "</h2>"; //parse the host, no protocol returned function parseHOST($url) { $new_parse_url = str_ireplace(array( "http://", "https://", "http://", "ftp://", "feed://" ), "", trim($url)); $parsedUrl = @parse_url("http://$new_parse_url"); return strtolower(trim($parsedUrl['host'] ? $parsedUrl['host'] : array_shift(explode('/', $parsedUrl['path'], 2)))); } //remove relative paths and position correctly function removePaths($url, $number_positions = NULL) { $path = @parse_url($url, PHP_URL_PATH); $trim_path = trim($path, '/'); $positions = ""; $positions = explode('/', $trim_path); if (preg_match("/\./", end($positions))) { array_pop($positions); } if (!is_null($number_positions)) { for ($i = 1; $i <= $number_positions; $i++) { array_pop($positions); } } foreach ($positions as $folders) { if (!empty($folders)) { $folder_path .= "$folders/"; } } return $folder_path; } //fix relative links to absolute links function fixRELATIVE($target_url, $url) { $domain = "http://" . parseHOST($target_url); if ($url == "#" || $url == "./") { $url = $domain; } if ($url == "/") { $url = $target_url; } $url = rtrim($url, "/"); $up_one = removePaths($target_url, 1); $up_two = removePaths($target_url, 2); $up_three = removePaths($target_url, 3); $up_four = removePaths($target_url, 4); $up_five = removePaths($target_url, 5); $path = parse_url($target_url, PHP_URL_PATH); $full_path = trim($path, '/'); $explode_path = explode("/", $full_path); $last = end($explode_path); $fixed_paths = ""; if (is_array($explode_path)) { foreach ($explode_path as $paths) { if (!empty($paths) && !preg_match("/\./", $paths)) { $fixed_paths .= "$paths/"; } } } $fixed_domain = "$domain/$fixed_paths"; if (substr($url, 0, 1) == "/") { $url = ltrim($url, "/"); $url = "$domain/$url"; } if (substr($url, 0, 1) == "#") { $url = "$domain/$full_path$url"; } if (substr($url, 0, 1) == "?") { $url = "$domain/$full_path$url"; } if (substr($url, 0, 15) == "../../../../../") { $url = str_replace("../../../../../", "", $url); $url = "$domain/$up_five$url"; } if (substr($url, 0, 12) == "../../../../") { $url = str_replace("../../../../", "", $url); $url = "$domain/$up_four$url"; } if (substr($url, 0, 9) == "../../../") { $url = str_replace("../../../", "", $url); $url = "$domain/$up_three$url"; } if (substr($url, 0, 6) == "../../") { $url = str_replace("../../", "", $url); $url = "$domain/$up_two$url"; } if (substr($url, 0, 3) == "../") { $url = str_replace("../", "", $url); $url = "$domain/$up_one$url"; } return $url; } //using curl and following redirects and responses would be better $html = @file_get_html($target_url); if (!$html) { die("failed to connect"); } $url_array = array(); foreach ($html->find('a') as $element) { $href = fixRELATIVE($target_url, trim($element->href)); $title = trim($element->title); $text = trim($element->plaintext); //not all hyperlinks contain a title if ($title == '') { $title = $text; } //if title is still empty, use the href link if ($title == '') { $title = $href; } //create an array associating them $url_array[] = array( "href" => $href, "title" => $title ); } //define urls array $urls = array(); //remove duplicates from array $urls = array_map("unserialize", array_unique(array_map("serialize", $url_array))); //clear url_array $url_array = array(); //print_r($urls); //display the links with titles as hyperlinks foreach ($urls as $link) { echo "<a href='" . $link['href'] . " 'target='_blank'>" . $link['title'] . "</a><br />"; } } ?> Don't forget to make everything safe if saving to database. -
Hard to tell because do not see your form. It would help if showed the actual error, turn on error reporting if do not see it. My best guess is that the form is sending a blank value or was never set and you try to use it. Add this before trying to use the post values as a starter, you should also be filter/sanitizing/escape these values associated to the type of data you expect. //check for if it's set and not blank if(isset($Ayar["Sepet"]) && trim($Ayar["Sepet"]) != '') { //your code in this area now echo trim($Ayar["Sepet"]); } else { echo "can show a message or die("the message"); here"; } I also noticed some of your code uses the short <? tags, use the full <?php tags
-
Hash marks and fragments get ignored through the address bar. Run this example on what you can do or not to see the fragment. <?php $url = filter_var("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])) { $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $url .= "?" . $query_string; } echo "<h4>what your script sees from address bar</h4>"; echo $url . "<br />"; //as can see here, nothing through $_server shows the fragment print_r($_SERVER); echo "<h4>client side using javascript</h4>"; echo "<script language='javascript'> document.write(window.location.hash); </script>"; echo "<h4>directly from server or in code</h4>"; $url = "http://site.com/page#fragment"; //example 1 echo parse_url($url, PHP_URL_FRAGMENT) . "<br />"; //example 2 echo end(explode("#", $url)) . "<br />"; //example 3 $arr = parse_url($url); //print_r($arr); echo $arr['fragment']; ?>
-
wrong post I did somehow
-
Issue with updating database from checkboxes in table
QuickOldCar replied to Abundances's topic in PHP Coding Help
$con->query($sql);