Jump to content

requinix

Administrators
  • Posts

    15,062
  • Joined

  • Last visited

  • Days Won

    414

Everything posted by requinix

  1. htmlspecialchars() is only for putting stuff with special characters into HTML. As the name might suggest. The REQUEST_URI must necessarily be safe if your web server was able to accept it and have PHP execute properly for it. The Location header itself doesn't have any special structure besides "Location: URI".
  2. Not both at once. One at a time. Because if you read the documentation for mysqli_query() you would know what the arguments to it are and that it only does one query.
  3. mysqli_multi_query() is not meant to work that way. Use the regular mysqli_query() and just call it twice for the two queries. Even better would be to use transactions: start transaction, do first query, rollback and abort if it fails, do second query, rollback and abort if it fails, commit.
  4. If you're looking for a critique, use the OOP methods instead of the procedural functions. Like function format_timestamp($config, $ui, $timestamp) { $time_zone = (is_logged_in($ui) && $ui['time_zone'] !== 'default') ? $ui['time_zone'] : date_default_timezone_get(); $date_format = (is_logged_in($ui) && $ui['date_format'] !== 'default') ? $ui['date_format'] : $config['default_date_format']; $date = new DateTime('@'.$timestamp); $date->setTimezone(new DateTimeZone($time_zone)); return $date->format($date_format); } A Unix timestamp does not have timezones. It's the same number at the same time everywhere in the world. Your function does the same thing that a single call to time would.
  5. What parse errors? Line breaks are totally allowed in XML. <orderComments>If its possible to get an autograph from the captain and the crew to my husband Amadeus it would be great. He just loves the show on tv and is also a fisherman here in Sweden. Thank you Anna</orderComments>If you called nl2br on the comment and then put it into XML, that would not work because would be interpreted as an XML node when you didn't want it to be.
  6. Yeah... I didn't mean for you to put literally "Williams R" in the query. It was an example.
  7. a) Instead of using fullname LIKE "%Williams R%" make it do fullname LIKE "%Williams%" AND fullname LIKE "%R%". b) If the search has two "words" make it do fullname LIKE "%Williams%R%" OR fullname LIKE "%R%Williams%". Three would probably "Last F M" so that would be OR fullname LIKE "%F%M%Last%". That lone "R" sucks.
  8. Okay, so... what issues? Are you trying to show the comment in HTML and you're not seeing the line breaks? Use nl2br. If not that, what?
  9. Those are the same thing. Unless you have a weird definition of "display images".
  10. I can't speak much to the performance, but I would expect a non-subquery solution to be faster and more efficient than a subquery solution. If you needed other tables (with a one-many relationship), or if you wanted other aggregate (eg, MAX) data at the same time, then subqueries would be the way to go. Mostly because there aren't really any other alternatives.
  11. Why not both? Focus on Java but learn PHP too. Maybe more languages. Diversify your skills.
  12. +1 to error_reporting. Is $conn defined?
  13. This might be turning into a "how do I do $x in WordPress" question... How much did you copy and where did you put it? Do you know what $post is? Is it coming from the imported data you/WP got from the XML? That code you have now: what does it do now and what is it supposed to be doing instead?
  14. I don't see the connection. What does post metadata have to do with an XML feed? I thought you were trying to load an XML feed and display data from it? What does WordPress have to do with it?
  15. It's not that simple. Sessions are driven by cookies, and cookies are tied to domains. Each of the four domains will have its own session* because they each have their own cookies. And you cannot set a cookie for a different domain. There is a way to do it with sessions, but it sucks. Easier would be to reuse the redirection. Um... Take this code with a grain of salt: I feel like I'm making a mistake or two somewhere. First, move the redirection stuff out of PHP and into the web server configuration. It will be faster and more efficient if PHP doesn't get involved in the process. // vhost config (best) or .htaccess (okay) RewriteEngine on RewriteCond %{HTTP_HOST} !=www.WEBSITE_URL_HERE.co.uk RewriteRule ^ http://www.WEBSITE_URL_HERE.co.uk/redirect?site=%{HTTP_HOST}&to=%{REQUEST_URI} [L,R=301]If the host name doesn't match, redirect to the right hostname and pass along the original hostname and the original URL.This introduces a new page dedicated just to supporting this stuff. Don't need to bog down the rest of the site with checks if you don't need to. Then write that new page. It doesn't have to output anything because it will always redirect the user somewhere. $sites = array( 'WEBSITE_URL_HERE.com', 'www.WEBSITE_URL_HERE.com', 'WEBSITE_URL_HERE.co.uk', 'www.WEBSITE_URL_HERE.co.uk' ); if (isset($_GET['site']) && in_array($_GET['site'], $sites)) { // session_start(); if it hasn't happened yet $_SESSION['site'] = $_GET['site']; } if (isset($_GET['to'])) { // need to validate it so people can only be redirected within this website $to = $_GET['to']; $todata = parse_url($to); // don't allow something with a hostname. both "http://example.com" and "//example.com" will do that if ($todata && empty($todata['host'])) { header("Location: {$to}", true, 307); exit; } } // if we're here then this page isn't being used correctly header("Location: /", true, 307); exit;Finally there's the logo function. Basically the same as before. function logoSwap(){ switch(isset($_SESSION['site']) ? $_SESSION['site'] : $_SERVER['HTTP_HOST']) { case 'WEBSITE_URL_HERE.com': return "WEBSITE_URL_HERE/wp-content/uploads/2016/01/logo-red.png"; case 'www.WEBSITE_URL_HERE.com': return "WEBSITE_URL_HERE/wp-content/uploads/2016/01/logo-red.png"; case 'WEBSITE_URL_HERE.co.uk': return "WEBSITE_URL_HERE/wp-content/uploads/2015/09/logo.png"; case 'www.WEBSITE_URL_HERE.co.uk': default: return "WEBSITE_URL_HERE/wp-content/uploads/2015/09/logo.png"; } }Oh. I renamed the thing from "url" to "site" because it's a bit less ambiguous that way. Probably should go with "original site" or something even clearer. PS: The logo with the different domain names doesn't make sense anymore. If someone goes to domain1.com then they'll be redirected to domain1.co.uk but see the .com logo. That's confusing. * Or two. The www and non-www can share cookies if the session cookie parameters are configured properly, but the .com and .co.uk definitely cannot.
  16. I removed your warning and reset you back to 0 warning points. Sorry about the misunderstanding.
  17. If you're not pulling in data from any other tables, and all you need from the transaction table is the date, then use MAX with a GROUP BY on the user. SELECT c.firstname, c.surname, c.regDate, MAX(t.lastTrans) AS lastTrans FROM confirmed c LEFT JOIN transaction t ON c.user_id = t.user_id WHERE c.status = 'confirmed' GROUP BY c.user_id ORDER BY MAX(t.lastTrans)
  18. Don't hijack threads. What are you talking about?
  19. Without duplicating the website? I don't know any way for you to keep four distinct sites, with support from search engines, without being penalized for duplication, in a way that you could feasibly have four logos. Duplicating the website is the only way you could have the four sites so each can have their own logo. Internationalization is probably the answer here. Why do you need four domains? What's the difference between them? You know that domain1 vs domain2 and .com vs .co.uk doesn't matter in any technical ways, right? One of those four combinations will be the most appropriate domain name for you to use. If you want to vary the logo but are willing to give up the association with the domain name, you could vary it by the user's IP address: domain1/2.com for US visitors, domain1/2.co.uk for non-US visitors. Or something like that.
  20. Clearly. But that's not what I asked about. Stop doing that. Set up a development environment on your own computer so you can do whatever you want to your code without having to worry about what is happening on the live site. No one will take you seriously as a PHP developer if you keep working directly on your live site. I'm sure. But, again, that's not what I'm asking about. 1. You are getting a 500 page. A 500 page means PHP is crashing. It is crashing because there is an error. You see the 500 page because PHP is not showing you the error message. You need to see the error message to know what is wrong. You cannot fix the problem if you do not know what the problem is. So change those two settings, perhaps with a custom php.ini or with .htaccess settings or with whatever other mechanism your hosting provider gives you to change PHP settings. Then try the page again. 2. What version of PHP are you using? If you do not know then you can use phpinfo.
  21. If you're getting a 500 error then it means you don't have your PHP installation properly set up for development. You are doing this on your own computer and not on a live site, right? Find your php.ini and change two settings: error_reporting = -1 display_errors = onThen restart your web server and try the page again. You should see an error message. Jumping ahead a bit, what version of PHP are you using?
  22. Possible? Sure. Though I'm not sure I understand what you want. Someone enters an email in a form and you send them a random color, code, and place? You're probably not using a database for anything. Make three files, each one with a different color, code, or place on each line. Then the PHP code picks a random line from each file and sends an email with them. Expensive? Depends what you consider to be expensive. It should take less than an hour for a knowledgeable PHP developer to do this.
  23. Use SimpleXML. Example: $xml = new SimpleXMLElement("URL", 0, true); foreach ($xml->property as $property) { // $node["key"] for attributes $reference = (string)$property["reference"]; // $node->name for sub nodes $type = (string)$property->property_type; $street = (string)$property->street; // multiple elements are accessed by their shared name $rooms = count($property->rooms->room); // room is basically an array of <room>s echo "Property {$reference} is a {$type} on {$street} with {$rooms} room(s).\n"; }
  24. If there are any redirections then it should be easy to spot: go to one domain, see if you're redirected to another domain. But if you don't have those redirections then you'll suffer with SEO: having four domains with the same content is not good. You should pick one and go with it, either by redirecting everyone to it or using a rel=canonical to point to the "main" domain's version of the page. Either way, though, search engines will only show one of the sites in their search results. Varying the image on www or non-www domains is... silly. I have no idea why you would want to do that. Varying by .co.uk or .com? Sure. But that sounds like an internationalization thing, and those kinds of issues are handled differently than showing the same site on multiple domains.
  25. What's the rest of the code? The stuff between the query you posted and where you output the date.
×
×
  • 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.