Jump to content

gizmola

Administrators
  • Content Count

    4,865
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by gizmola

  1. Correct. Because it's a numeric array, when you do foreach($key => $value) the array key is going to be either an "associative" key ie some string like 'title', or it will just be numeric. Other languages often have completely different data structures for these things like array vs. map, but one of the really nice features of PHP is that they intermix the two. Since the array I was foreaching through was numeric, the first element will be 0. PHP is the same as most other languages (c, c++, javascript, c#, java) in that the first element of an array will be indexed at 0. ++ is the increment operator, so it just adds 1 to the value. Thus you get things numbered starting at 1. If you want a different numbering system, I would actually recommend not using your own numbering at all, but instead emit an html ordered list, and use css to style the list for you.
  2. The reason things are jumbled is because the output was set for command line php. If you run this as a script via a webserver, then you will be outputting html and you would need to add the desired html. Just to get a quick look at it, you can add pre tags around it. Anything else would be a tutorial in html and I have to assume you can do that on your own. echo "<pre>"; foreach($json['data'] as $data) { echo "Title: {$data['title']}\n"; echo "Event Time: {$data['live_event']['start_time']}\n"; echo "Streams:\n"; foreach($data['live_event']['stream_list'] as $i => $stream) { $i++; echo " $i. {$stream['stream_id']}\n"; } echo "\n"; } echo "</pre>"; As for format of the number, the important thing is that you read my code and figure out why it does what it does. Then changing the way the number looks should be easy. As for the date/time, I just used what you were using, but it looks like if you want a Datetime value, you should use $data['live_event']['start_at'] instead of start_time. In order to change the format you might need to look into the php DateTime Class.
  3. This is what I was looking for: $jsondata = file_get_contents("https://kalebdf.com/flo/api.php?url=events%2Fnow-and-upcoming%3Flimit%3D70%26tz%3DAmerica%2FNew_York%26live_only%3D1%26site_id%3D1%252C2%252C3%252C4%252C5%252C6%252C7%252C8%252C9%252C10%252C11%252C12%252C13%252C14%252C15%252C16%252C17%252C18%252C19%252C20%252C21%252C22%252C23%252C24%252C25%252C26%252C27%252C28%252C29%252C30%252C31%252C32%252C33%252C34%252C35%252C36%252C37%252C38%252C39%252C41%252C43"); $json = json_decode($jsondata, true); var_dump($json['data']); Now that we can see your source json, this is obviously a huge result. I'm not sure that turning this into a gigantic array is helpful because it's such a large json data structure with many keys. However, in general you can determine what is going to happen based on whether the json has an array structure ie [ ] or a property "somename": "some_value" The original json has many of these properties. If something is inside a json array, then it will be turned into a numerically indexed array: $var[0], $var[1] etc. Unless you know which specific array element you need, typically you're going to foreach() loop through them. If the original json is a property then the property name is going to be turned into an array key, with the associated value stored in the array element. That value could be a nested object: { }, a single value, or an array. And in each case there is possible nesting. If you understand the basics of this, you should be able to look at the original json and figure out how it will be converted. In your case, when we var_dump($json['data']) the top level is revealed to be a giant numerically indexed array: You are foreach()ing through this array. So to get an idea of what just one looks like, it's helpful to var_dump the first one: var_dump($json['data'][0]); This shows the nested structure for each array element you'll get when you foreach through the outer structure: array(41) { ["id"]=> int(6251309) ["should_show_read_more"]=> bool(true) ["ad_set_code"]=> NULL ["slug_uri"]=> string(33) "/events/6251309-2019-giro-ditalia" ["title"]=> string(18) "2019 Giro d'Italia" ["short_title"]=> string(13) "Giro d'Italia" ["seo_description"]=> string(122) "Tune in to FloBikes for complete editorial coverage and to watch every stage of the 2019 Giro d'Italia live and on demand!" ["author"]=> array(10) { ["profile_picture_url_small"]=> string(86) "https://res.cloudinary.com/diznifoln/image/upload/w_100,h_100/oz7rkl8ihbds5yb20ujn.png" ["profile_picture_url_medium"]=> string(86) "https://res.cloudinary.com/diznifoln/image/upload/w_125,h_125/oz7rkl8ihbds5yb20ujn.png" ["profile_picture_url_large"]=> string(86) "https://res.cloudinary.com/diznifoln/image/upload/w_150,h_150/oz7rkl8ihbds5yb20ujn.png" ["id"]=> int(1625830) ["username"]=> string(10) "JoeBatts75" ["first_name"]=> string(3) "Joe" ["last_name"]=> string(9) "Battaglia" ["gender"]=> string(1) "m" ["created_at"]=> string(24) "2014-04-10T14:03:26+0000" ["modified_at"]=> string(24) "2019-02-04T16:24:23+0000" } ["asset"]=> array(14) { ["id"]=> int(6456733) ["title"]=> string(53) "El-Giro-de-Italia-2018-comenzará-en-Jerusalén.jpg" ["description"]=> NULL ["credit"]=> NULL ["source"]=> string(71) "//flo30-assets-prod.s3.amazonaws.com/uploads/FloBikes/5ba8fda8b17eb.png" ["site"]=> array(13) { ["domain"]=> string(16) "www.flobikes.com" ["id"]=> int(37) ["name"]=> string(8) "FloBikes" ["code"]=> string(8) "flobikes" ["host"]=> string(23) "http://www.flobikes.com" ["active"]=> bool(true) ["type"]=> string(4) "site" ["version"]=> int(3) ["color"]=> string(7) "#FF8200" ["hero_image"]=> string(86) "https://d6fm3yzmawlcs.cloudfront.net/mobileVerticalBackground/mobile_bg_flocycling.jpg" ["modified_at"]=> NULL ["show_on_mobile"]=> bool(true) ["sport_name"]=> string(7) "Cycling" } ["url"]=> string(55) "https://d2779tscntxxsw.cloudfront.net/5ba8fda8b17eb.png" ["library"]=> bool(true) ["status_code"]=> int(200) ["path"]=> string(77) "https://flo30-assets-prod.s3.amazonaws.com/uploads/FloBikes/5ba8fda8b17eb.png" ["copied"]=> bool(true) ["duplicated"]=> bool(false) ["created_at"]=> string(24) "2018-09-24T15:07:21+0000" ["modified_at"]=> string(24) "2018-10-13T08:09:22+0000" } ["logo"]=> NULL ["slug"]=> string(17) "2019-giro-ditalia" ["publish_start_date"]=> string(24) "2018-09-24T15:26:00+0000" ["publish_end_date"]=> NULL ["status"]=> int(1) ["status_text"]=> string(18) "Active - Published" ["status_color"]=> string(7) "#CDEB8B" ["premium"]=> bool(false) ["node"]=> array(13) { ["categories"]=> array(3) { [0]=> array(5) { ["id"]=> int(605) ["name"]=> string(4) "Road" ["parent"]=> array(5) { ["id"]=> int(602) ["name"]=> string(10) "Discipline" ["parent"]=> NULL ["created_at"]=> string(24) "2018-02-02T17:47:21+0000" ["modified_at"]=> NULL } ["created_at"]=> string(24) "2018-02-02T17:47:34+0000" ["modified_at"]=> NULL } [1]=> array(5) { ["id"]=> int(612) ["name"]=> string(12) "Professional" ["parent"]=> array(5) { ["id"]=> int(603) ["name"]=> string(11) "Rider Level" ["parent"]=> NULL ["created_at"]=> string(24) "2018-02-02T17:47:21+0000" ["modified_at"]=> NULL } ["created_at"]=> string(24) "2018-02-02T17:47:53+0000" ["modified_at"]=> NULL } [2]=> array(5) { ["id"]=> int(621) ["name"]=> string(8) "UCI 2.WT" ["parent"]=> array(5) { ["id"]=> int(604) ["name"]=> string(10) "Race Level" ["parent"]=> NULL ["created_at"]=> string(24) "2018-02-02T17:47:21+0000" ["modified_at"]=> NULL } ["created_at"]=> string(24) "2018-02-02T17:48:48+0000" ["modified_at"]=> NULL } } ["primary_event_association"]=> NULL ["primary_event_or_series_association"]=> NULL ["people"]=> array(0) { } ["teams"]=> array(0) { } ["id"]=> int(6251309) ["current_revision"]=> NULL ["site"]=> array(13) { ["domain"]=> string(16) "www.flobikes.com" ["id"]=> int(37) ["name"]=> string(8) "FloBikes" ["code"]=> string(8) "flobikes" ["host"]=> string(23) "http://www.flobikes.com" ["active"]=> bool(true) ["type"]=> string(4) "site" ["version"]=> int(3) ["color"]=> string(7) "#FF8200" ["hero_image"]=> string(86) "https://d6fm3yzmawlcs.cloudfront.net/mobileVerticalBackground/mobile_bg_flocycling.jpg" ["modified_at"]=> NULL ["show_on_mobile"]=> bool(true) ["sport_name"]=> string(7) "Cycling" } ["view_count"]=> int(100740) ["legacy_id"]=> NULL ["search_indexed_at"]=> string(24) "2019-05-22T12:13:40+0000" ["created_at"]=> string(24) "2018-09-24T15:27:50+0000" ["modified_at"]=> string(24) "2019-05-22T12:13:40+0000" } ["enable_interstitial_ad"]=> bool(true) ["enable_pre_roll_ads"]=> bool(true) ["shareable_link"]=> string(57) "https://www.flobikes.com/events/6251309-2019-giro-ditalia" ["created_at"]=> string(24) "2018-09-24T15:27:50+0000" ["modified_at"]=> string(24) "2019-05-22T12:04:37+0000" ["has_schedule"]=> bool(true) ["preview_text"]=> string(217) "<p>The 2019 Giro d’Italia is a UCI World Tour event. Tune in to FloBikes for a complete editorial coverage and to watch every stage of the 2019 Giro d'Italia live and on demand, available in the U.S. and Canada.</p>" ["description"]=> string(225) "<p>The 2019 Giro d&rsquo;Italia is a UCI World Tour event. Tune in to FloBikes for a complete editorial coverage and to watch every stage of the 2019 Giro d&#39;Italia live and on demand, available in the U.S. and Canada.</p>" ["city"]=> string(7) "Bologna" ["region"]=> NULL ["country"]=> string(2) "IT" ["venue"]=> NULL ["start_date"]=> string(10) "2019-05-11" ["end_date"]=> string(10) "2019-06-02" ["schedule_tab_label"]=> string(8) "Schedule" ["participant_tab_label"]=> string(7) "Entries" ["live_updates_tab_label"]=> string(12) "Live Updates" ["info_tab_label"]=> string(4) "Info" ["live_event"]=> array(33) { ["event_ids"]=> array(1) { [0]=> int(6251309) } ["start_at"]=> string(20) "2019-05-22T11:05:00Z" ["end_at"]=> string(20) "2019-06-03T03:59:59Z" ["id"]=> int(8778) ["title"]=> string(18) "2019 Giro d'Italia" ["short_title"]=> string(13) "Giro D'Italia" ["stream1"]=> string(26) "cyp8778_2019_giro_d_italia" ["stream2"]=> string(26) "cyp8778_2019_giro_d_italia" ["stream_list"]=> array(2) { [0]=> array(7) { ["stream_id"]=> int(18633) ["stream_name"]=> string(18) "2019 Giro d'Italia" ["stream_code"]=> string(26) "cyp8778_2019_giro_d_italia" ["stream_active"]=> bool(true) ["stream_hls"]=> string(68) "http://flocasts-hls.videocdn.scaleengine.net/flocasts-florigins/play" ["stream_type"]=> string(8) "multiple" ["stream_mode"]=> string(6) "normal" } [1]=> array(7) { ["stream_id"]=> int(25651) ["stream_name"]=> string(13) "Giro d'Italia" ["stream_code"]=> string(21) "cyp8778_giro_d_italia" ["stream_active"]=> bool(false) ["stream_hls"]=> string(68) "http://flocasts-hls.videocdn.scaleengine.net/flocasts-florigins/play" ["stream_type"]=> string(8) "multiple" ["stream_mode"]=> string(6) "normal" } } ["slug"]=> string(18) "2019-giro-d-italia" ["description"]=> string(79) "<p> <span style="background-color: initial;">2019 Giro d'Italia</span> </p>" ["premium"]=> bool(true) ["ppv"]=> bool(false) ["disable_bumping"]=> bool(false) ["disable_login"]=> bool(false) ["enable_ott"]=> bool(true) ["status"]=> string(4) "LIVE" ["status_message"]=> NULL ["type"]=> string(6) "STREAM" ["start_date"]=> string(10) "2019-05-22" ["end_date"]=> string(10) "2019-06-02" ["start_time"]=> string(8) "07:05:00" ["end_time"]=> string(8) "23:59:59" ["timezone"]=> string(16) "America/New_York" ["start_date_time"]=> string(24) "2019-05-22T11:05:00+0000" ["end_date_time"]=> string(24) "2019-06-03T03:59:59+0000" ["start_at_next"]=> string(24) "2019-05-22T11:05:00+0000" ["background_url"]=> NULL ["live_event_url"]=> string(34) "https://www.flobikes.com/live/8778" ["player_version"]=> string(3) "3.0" ["dvr"]=> bool(false) ["created_at"]=> string(24) "2019-05-22T12:04:56+0000" ["modified_at"]=> string(24) "2019-05-22T12:04:56+0000" } ["watchable"]=> bool(true) ["replay_video_count"]=> int(10) ["replay_preview_vod"]=> NULL ["type"]=> string(5) "event" } Sometimes it's useful in such a large structure just to see the list of top level array keys. PHP has a helpful array_keys() function for this. Also, print_r has a slightly different output format from var_dump that omits the variable types. Just to get some clarity, I ran this: $json = json_decode($jsondata, true); $t = array_keys($json['data'][0]); sort($t); print_r($t); And got this output: Array ( [0] => ad_set_code [1] => asset [2] => author [3] => city [4] => country [5] => created_at [6] => description [7] => enable_interstitial_ad [8] => enable_pre_roll_ads [9] => end_date [10] => has_schedule [11] => id [12] => info_tab_label [13] => live_event [14] => live_updates_tab_label [15] => logo [16] => modified_at [17] => node [18] => participant_tab_label [19] => premium [20] => preview_text [21] => publish_end_date [22] => publish_start_date [23] => region [24] => replay_preview_vod [25] => replay_video_count [26] => schedule_tab_label [27] => seo_description [28] => shareable_link [29] => short_title [30] => should_show_read_more [31] => slug [32] => slug_uri [33] => start_date [34] => status [35] => status_color [36] => status_text [37] => title [38] => type [39] => venue [40] => watchable ) You had determined previously that the 2 top level elements you were interested in were 'title' and 'live_event'. 'title' is a single value, however live_event is another nested structure. To figure out what that looks like: var_dump($json['data'][0]['live_event']); And you get: array(33) { ["event_ids"]=> array(1) { [0]=> int(6251309) } ["start_at"]=> string(20) "2019-05-22T11:05:00Z" ["end_at"]=> string(20) "2019-06-03T03:59:59Z" ["id"]=> int(8778) ["title"]=> string(18) "2019 Giro d'Italia" ["short_title"]=> string(13) "Giro D'Italia" ["stream1"]=> string(26) "cyp8778_2019_giro_d_italia" ["stream2"]=> string(26) "cyp8778_2019_giro_d_italia" ["stream_list"]=> array(2) { [0]=> array(7) { ["stream_id"]=> int(18633) ["stream_name"]=> string(18) "2019 Giro d'Italia" ["stream_code"]=> string(26) "cyp8778_2019_giro_d_italia" ["stream_active"]=> bool(true) ["stream_hls"]=> string(68) "http://flocasts-hls.videocdn.scaleengine.net/flocasts-florigins/play" ["stream_type"]=> string(8) "multiple" ["stream_mode"]=> string(6) "normal" } [1]=> array(7) { ["stream_id"]=> int(25651) ["stream_name"]=> string(13) "Giro d'Italia" ["stream_code"]=> string(21) "cyp8778_giro_d_italia" ["stream_active"]=> bool(false) ["stream_hls"]=> string(68) "http://flocasts-hls.videocdn.scaleengine.net/flocasts-florigins/play" ["stream_type"]=> string(8) "multiple" ["stream_mode"]=> string(6) "normal" } } ["slug"]=> string(18) "2019-giro-d-italia" ["description"]=> string(79) "<p> <span style="background-color: initial;">2019 Giro d'Italia</span> </p>" ["premium"]=> bool(true) ["ppv"]=> bool(false) ["disable_bumping"]=> bool(false) ["disable_login"]=> bool(false) ["enable_ott"]=> bool(true) ["status"]=> string(4) "LIVE" ["status_message"]=> NULL ["type"]=> string(6) "STREAM" ["start_date"]=> string(10) "2019-05-22" ["end_date"]=> string(10) "2019-06-02" ["start_time"]=> string(8) "07:05:00" ["end_time"]=> string(8) "23:59:59" ["timezone"]=> string(16) "America/New_York" ["start_date_time"]=> string(24) "2019-05-22T11:05:00+0000" ["end_date_time"]=> string(24) "2019-06-03T03:59:59+0000" ["start_at_next"]=> string(24) "2019-05-22T11:05:00+0000" ["background_url"]=> NULL ["live_event_url"]=> string(34) "https://www.flobikes.com/live/8778" ["player_version"]=> string(3) "3.0" ["dvr"]=> bool(false) ["created_at"]=> string(24) "2019-05-22T12:04:56+0000" ["modified_at"]=> string(24) "2019-05-22T12:04:56+0000" } So finally we can see, that 'stream_list' is the key for an array of streams. Being that this is a numerically indexed array of 1..n items, you need to do a nested foreach() to iterate through the internal array elements. You've stated that you are only interested in the 'stream_id' element. So hopefully at this point, you can understand that you have an outer foreach() through the data elements, and then the requirement to do an inner foreach to get the individual stream_id elements from stream_list. <?php $jsondata = file_get_contents("https://kalebdf.com/flo/api.php?url=events%2Fnow-and-upcoming%3Flimit%3D70%26tz%3DAmerica%2FNew_York%26live_only%3D1%26site_id%3D1%252C2%252C3%252C4%252C5%252C6%252C7%252C8%252C9%252C10%252C11%252C12%252C13%252C14%252C15%252C16%252C17%252C18%252C19%252C20%252C21%252C22%252C23%252C24%252C25%252C26%252C27%252C28%252C29%252C30%252C31%252C32%252C33%252C34%252C35%252C36%252C37%252C38%252C39%252C41%252C43"); $json = json_decode($jsondata, true); foreach($json['data'] as $data) { echo "Title: {$data['title']}\n"; echo "Event Time: {$data['live_event']['start_time']}\n"; echo "Streams:\n"; foreach($data['live_event']['stream_list'] as $i => $stream) { $i++; echo " $i. {$stream['stream_id']}\n"; } echo "\n"; } Output: Title: 2019 Giro d'Italia Event Time: 07:05:00 Streams: 1. 18633 2. 25651 Title: 2019 Japan vs United States | Women's VNL Event Time: 08:45:00 Streams: 1. 24691 Title: 2019 Serbia vs Korea | Women's VNL Event Time: 09:45:00 Streams: 1. 24692 Title: 2019 Thailand vs Italy | Women's VNL Event Time: 10:15:00 Streams: 1. 24695 Title: 2019 Brose Bamberg vs Rasta Vechta | easyCredit BBL Event Time: 12:00:00 Streams: 1. 25885 Title: 2019 Bulgaria vs Belgium | Women's VNL Event Time: 12:15:00 Streams: 1. 24697 Title: 2019 Netherlands vs Turkey | Women's VNL Event Time: 12:45:00 Streams: 1. 24698 Title: 2019 Poland vs Germany | Women's VNL Event Time: 13:15:00 Streams: 1. 24699 Title: 2019 Kirolbet Baskonia vs Divinas Seguros Joventut | 2018-19 La Liga BB Event Time: 13:30:00 Streams: 1. 24555 Title: Here's The Deal Event Time: 14:30:00 Streams: 1. 17181 Title: 2019 China vs Russia | Women's VNL Event Time: 14:45:00 Streams: 1. 24700 Title: 2019 TSSAA Outdoor Championships Event Time: 17:00:00 Streams: 1. 23950 Title: Going Brooklyn: In Studio With Bowling's Big Names Event Time: 16:00:00 Streams: 1. 19566 Title: 2019 USAC Sprints at Terre Haute Action Track Event Time: 17:30:00 Streams: 1. 20891 2. 21547 3. 21850 Title: 2019 Brazil vs Dominican Republic | Women's VNL Event Time: 17:45:00 Streams: 1. 24701 Title: 2019 D.C. United vs Real Betis Event Time: 18:45:00 Streams: 1. 25324 2. 25961 Title: 2019 Sassari City Matteo Pellicone Memorial Event Time: 03:00:00 Streams: 1. 22004 Title: 2019 Canadian Gymnastics Championships - Artistic Event Time: 08:30:00 Streams: 1. 22977 Title: 2019 Belgium vs Japan | Women's VNL Event Time: 08:45:00 Streams: 1. 24702 Title: 2019 CAN vs SUI | IIHF World Quarterfinals Event Time: 09:15:00 Streams: 1. 25647 2. 25958 Title: 2019 Netherlands vs Korea | Women's VNL Event Time: 09:45:00 Streams: 1. 24703 Title: 2019 Italy vs Germany | Women's VNL Event Time: 10:15:00 Streams: 1. 24704 Title: FloTrack TV Event Time: 12:00:00 Streams: 1. 24624 Title: 2019 United States vs Bulgaria | Women's VNL Event Time: 12:15:00 Streams: 1. 24705 Title: 2019 Turkey vs Serbia | Women's VNL Event Time: 12:45:00 Streams: 1. 24706 Title: 2019 Thailand vs Poland | Women's VNL Event Time: 13:15:00 Streams: 1. 24707 Title: 2019 CZE vs GER | IIHF World QuarterFinals Event Time: 13:15:00 Streams: 1. 25959 Title: 2019 DI NCAA West Preliminary Round Event Time: 12:00:00 Streams: 1. 23835 2. 25953 Title: 2019 DI NCAA East Preliminary Round Event Time: 15:30:00 Streams: 1. 23834 2. 25954 Title: 2019 China vs Dominican Republic | Women's VNL Event Time: 14:45:00 Streams: 1. 24708 Title: 2019 MPSSAA Outdoor Championships Event Time: 16:00:00 Streams: 1. 24005 Title: 2019 NHSRA Louisiana State Finals: RidePass PRO Event Time: 15:15:00 Streams: 1. 25111 etc.
  4. FYI I answered you in irc. We need a print_r or var_dump of the structure in order to understand the array structure, as do you.
  5. gizmola

    Query needed, thanks!

    MariaDB and MySQL 8 both have REGEXP_REPLACE. A regex like this would probably work to find your bbcode: \[QT\].*\[\/QT\] Replace that with and empty string, and you'll remove the bbcode blocks from the messages.
  6. Hey Jim R, I just want to say that I'm pleased to see you letting go of some of your preconceived notions. There are few people with both the expertise and patience Barand brings to these forums. In my career I've designed and engineered systems for companies like Paramount Pictures, Industrial Light & Magic, Blizzard Entertainment, Sierra Online and many more I won't elaborate. Some of the systems have had millions of users and 100's of millions of rows in individual tables. Please take it from me that you're getting amazing advice from a professional who is an authority on anything having to do with relational database design, SQL or web systems based on a relational database.
  7. Any decent editor with PHP support should have shown you the issue with a missing bracket or parens. What are you using to edit your code? It also would have been easy to see if you indented your code. I'm not sure if that was an issue with cutting and pasting or if you are writing your code that way, but if you are, that is a terrible habit and one you should remedy immediately. Again most editors support basic indent/outdent pretty well in most cases. One thing that would help is to have your } else { and } else if () { On one line. Here's what I'd expect your code to look like in an editor: <?php if (isset($_POST['login-submit'])) { require 'dbh.inc.php'; $mailuid = $_POST['mailuid']; $password = $_POST['pwd']; if (empty($mailuid) || empty($password)) { header("Location: ../index.php?error=emptyfields"); exit(); } else { $sql = "SELECT * FROM users WHERE uidUsers=? OR emailUsers=?;"; $stmt = mysqli_stmt_init($conn); if (!mysqli_stmt_prepare($stmt, $sql)) { header("Location: ../index.php?error=sqlerror"); exit(); } else { mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); if ($row = mysqli_fetch_assoc($result)) { $pwdCheck = password_verify($password, $row['pwdUsers']); if ($pwdCheck == false) { header("Location: ../index.php?error=wrongpwd"); exit(); } else if ($pwdCheck == true) { session_start(); $_SESSION['userId'] = $row['idUsers']; $_SESSION['userUid'] = $row['uidUsers']; header("Location: ../index.php?login=success"); exit(); } else { header("Location: ../index.php?error=wrongpwd"); exit(); } } else ( header("Location: ../index.php?error=nouser"); exit(); } } else { header("Location: ../index.php"); exit(); } } With proper indentation, the structure of the logic is visible and can be followed.
  8. gizmola

    Xdebug installation

    How is PHP integrated into the browser? Is it Apache with mod_php, nginx with php-fpm? Also did you run command line php (php -i) and see if the module is showing there? What xdebug configuration do you have? Is there an xdebug.ini, and if so where, and what are the contents?
  9. gizmola

    Problem with Form URL in PHP Code

    You didn't provide the actual code that does the redirect upon form submission, so it's anyone's guess.
  10. gizmola

    Help with embedding Google SMTP mail function.

    Your original source literally has this code: $email_message = '<html><body>'; $email_message .= '<table rules="all" style="border-color: #666;" cellpadding="10">'; $email_message .= "<tr style='background: #eee;'><td><strong>Request</strong></td></tr>"; $email_message .= "<tr style='background: #fff;'><td></td><td>" . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Requested By:</strong> </td><td>" . strip_tags($_POST['query']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Assigned To:</strong> </td><td>" . strip_tags($_POST['assigned']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Contact Email:</strong> </td><td>" . strip_tags($_POST['senderemail']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>New Part Number:</strong> </td><td>" . strip_tags($_POST['partno']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Item Description:</strong> </td><td>" . strip_tags($_POST['item']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Expected Annual Volume:</strong> </td><td>" . strip_tags($_POST['volume']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 1:</strong> </td><td>" . strip_tags($_POST['sup1']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec1']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 2:</strong> </td><td>" . strip_tags($_POST['sup2']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec2']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 3:</strong> </td><td>" . strip_tags($_POST['sup3']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec3']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 4:</strong> </td><td>" . strip_tags($_POST['sup4']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec4']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Email Subject:</strong> </td><td>" . strip_tags($_POST['subject']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['message']) . "</td></tr>"; $email_message .= "</body></html>"; So, with phpMailer ---- $email_message = '<html><body>'; $email_message .= '<table rules="all" style="border-color: #666;" cellpadding="10">'; $email_message .= "<tr style='background: #eee;'><td><strong>Request</strong></td></tr>"; $email_message .= "<tr style='background: #fff;'><td></td><td>" . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Requested By:</strong> </td><td>" . strip_tags($_POST['query']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Assigned To:</strong> </td><td>" . strip_tags($_POST['assigned']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Contact Email:</strong> </td><td>" . strip_tags($_POST['senderemail']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>New Part Number:</strong> </td><td>" . strip_tags($_POST['partno']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Item Description:</strong> </td><td>" . strip_tags($_POST['item']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Expected Annual Volume:</strong> </td><td>" . strip_tags($_POST['volume']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 1:</strong> </td><td>" . strip_tags($_POST['sup1']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec1']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 2:</strong> </td><td>" . strip_tags($_POST['sup2']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec2']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 3:</strong> </td><td>" . strip_tags($_POST['sup3']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec3']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 4:</strong> </td><td>" . strip_tags($_POST['sup4']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec4']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Email Subject:</strong> </td><td>" . strip_tags($_POST['subject']) . "</td></tr>"; $email_message .= "<tr style='background: #eee;'><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['message']) . "</td></tr>"; $email_message .= "</body></html>"; $mail->Body = $email_message; The $mail->AltBody should be a version of the same data without the html, and just newline characters after each line.
  11. gizmola

    Error establishing a database connection

    I tend to start by verification of the username and password using the mysql command line client. Do the credentials work? If the db is on a separate non localhost server (-h someserver.someplace ) then this will help you debug that issue. Many things in PHP having to do with mysql connectivity have changed in recent years, not the least of which is the removal of the mysql_ library which old versions of wordpress used. Assuming PHP has been upgraded on the server, but wordpress has not, it is quite likely that upgrading wordpress to a current version will fix the issue. Of course, make sure you have full and complete OS and database backups before you start down that road.
  12. gizmola

    Help with embedding Google SMTP mail function.

    PHP's built in mail() function is designed to dump off mail to a system Mail Transfer Agent (MTA). It is not a full blown implementation of SMTP with support for SSL etc. To get that level of functionality, unless you plan to spend a good amount of time writing this to SMTP and Email format RFC standards, it is advisable to use a library. The traditional answer to this question involves pointing you to the PHPMailer library. PHPMailer source is here: https://github.com/PHPMailer/PHPMailer I am a big fan of things that have come from the Symfony project, and they have an alternative to PHPMailer named Swiftmailer. Swiftmailer is here: https://swiftmailer.symfony.com/docs/index.html Either library will do the job for you, so I'd advise you look at both and use whichever one you like the best, or that fits in with your overall project.
  13. gizmola

    Help with undefined variable error.

    You've made this really annoying by posting a screenshot rather than the code into a code block. In your screenshot go to the code on line #25 in your editor. Add a new blank line. For that blank line add this code: die('<pre>' . $content_to_eval . '</pre>'); Run the script, and it should output a string in a box. That is what was requested -- essentially the code the plugin is attempting to eval().
  14. gizmola

    my add to cart does not seem to work

    Just to elaborate on my comment "The IP address code is dumb" that is beyond the matter of using an IP address to identify a user for the purposes of a shopping cart application. If you look at the code it essentially degrades to REMOTE_ADDR, however, were this server to be behind a proxy or load balancer, the other variables being prioritized may very well degrade to any array. The code does nothing to attempt to actually extract the user IP in that case. There's more picking apart of the code, but there are just so many better examples and tutorials out there, not to mention frameworks and libraries you can build a robust shopping app out of. For example, here's a Symfony4 based "simple cart" with unit tests, a nice UI, administration system, twig templates and solid basic "getting started" that even provides docker support -> https://github.com/krybc/cart
  15. gizmola

    mongodb connection issue

    Well I did see this from your lsof: nginx 684 www-data 11u IPv4 17234 0t0 TCP *:27017 (LISTEN) 27017 is the MongoDB listener port, so it makes sense that when you killed nginx, you could connect. The question is, why is nginx configured to be listening to 27017?
  16. gizmola

    my add to cart does not seem to work

    I'm sorry but this is an idiotic approach to handling carts. IP addresses are shared, sometimes en masse. There is no way that a shopping cart should be based upon a user's IP address. The IP address code is dumb. PHP has sessions built in, and they are easy to use and solve this problem. I don't know where you found this tutorial, but it's apparently old, outdated, and has a number of poor and/or obsolete practices. You know when you have code that requires global, this is php3 level sophistication. I'm also on the same bandwagon as most of the long time established developers who frequent phpfreaks, in being a firm proponent of the "use PDO, it's a better db API" camp. It might help to let people know what you are trying to get out of this: (learning exercise?, building a site for a small business or personal project?, homework?) as that might help people modulate their responses. The obvious issue with the code you provided is that you didn't show us the code that actually calls add_cart() function, so it's anyone's guess why it isn't working, although ginerjm already pointed out the way you bypass potential db errors and assume your connections and queries are functioning.
  17. Basics: How does your script accept input? In your case, the code provided shows you are looking for $_GET parameters. If you want to change this to use POST then you would need to check for $_POST parameters. Are you clear on what runs where? PHP code is run on the server, and a response is generated and returned to the client. Javascript is run within the user's browser. This is why you need to use the developer console to look at what is happening with your ajax code when the app is run.
  18. I'd just be repeating information I've provided numerous times for other similar questions. It's an art with some science and there are no guarantees, however, there are numerous things you can do, some of which aren't all that difficult, but most of which are more system and domain administration tasks. Here's one of those recent threads:
  19. gizmola

    open source forum software

    Most of the best known open source forum packages are written in PHP, so you have a lot of choices on that front. There are a few that are commercial, which many companies actually want. Open source does not necessarily mean free. Another recent business model involves hosted services, and this has proven to be big business AND something customers often want. Keeping on top of patches and security issues and configuration and backups has been the downfall of many a community. It nearly killed this one as a matter of fact. Assuming you want php FREE and open source, then it pretty much comes down to phpBB (current versions based on Symfony) or Flarum (based on Laravel) . There are a number of other projects (like MyBB) that all have lots of uncertainty and sometimes years of technical debt (Phorum, .Simple Machines, FLuxbb, Fudforum) Some of those projects are certainly proven and stable, so you might want to look into them, but you will likely find antiquated php code and moribund communities.
  20. gizmola

    Help with substituting web script code

    I think his point is, that you are basically asking someone to rewrite code to your specifications. On a good day, with the right type of question, you might get people writing code for you, especially if there is something very interesting or challenging about it. This is not one of those questions. Basically, we need to see what you tried to do that didn't work. As it is, you haven't tried anything yet. Do some work, and come back with questions, and you might surprise yourself and fix it yourself. 😉
  21. gizmola

    help with contact-form spam test

    You can start by removing these lines from your code: $headers .= 'From: '. $email. "\r\n" . $headers .= "Reply-To: ". $email. "\r\n"; This is not code related, but an easy improvement that simply requires that you control the DNS for your domain, is to add an SPF record. With that said, you also need to have a valid DNS MX record, and email needs to come from a server that is designated to be a mail exchanger (MX). The SPF record essentially ties the server IP address (ipv4 & ipv6 if possible) for your mail server. Also, I hope you looked at the information I provided about having your email in multipart/mime format. If that is too much for you to accomplish, then remove all the html tags from your email, and send the in pure text only format.
  22. gizmola

    help with contact-form spam test

    You can send emails to whomever you want through your system. That is not the problem I discussed, however, in doing so you are creating a system that can be used by a spammer to send spam from your system. This is a great way to get your system on a blacklist. In summary, this is not something you should proceed with. With that said many people have systems that send email of various types (this forum is an example of that) for valid reasons. For example, some users may like to be sent an email notification when they have made a topic as you did, and others reply. The issue with spoofing, is that you can send an email on a user's behalf, but it needs to come from your system. You should not attempt to send emails from your system and try and make it look like they came from someone else. That is spoofing.
  23. gizmola

    help with contact-form spam test

    Spoofing means that you are setting the From address to look like it is coming from a user@domain that is not valid for your mail server. So if my domain is gizmola.test and I set up my from to be someuser@yahoo.com, this is "spoofing". I would need the mail to come from someuser@gizmola.test. You should open up your received email that is in the spam folder for your tests, and look at the actual email headers to see what is in there. If you want to provide the headers, we might be able to offer more advice.
  24. gizmola

    help with contact-form spam test

    Classification as spam is under the control of the receiving mail server. There is nothing you can do to prevent that in your code, although of course the actual content of the mail might be spammy. Spam classification is not binary. Most spam classification systems utilize a scoring system. There are a lot of things that will be seen as "spammy" including No reverse DNS entry for the mailserver Spoofing the from address Not having an SPF entry for the domain Not implementing DKIM These are things that a Devops/Sysadmin would need to work on. If you are spoofing the from address, that is something you should not be doing. The other thing you have hit upon is the proper way to construct an email. By default, the body of an email is assumed to be text. To send an html version of the email, you should actually have a structure where there are multiple versions of the email using multipart/mime format. This is non-trivial, and a reason why people use libraries like phpmailer rather than trying to code it yourself. Having a non-standard body with html tags detected is not the proper RFC compliant way to handle this, and will often add to the spam score.
  25. gizmola

    Unable to use connection to MySQL

    This reminds me of the old programmer joke about the code that calculates 1+2 and returns the value 4. To fix, the programmer adds: if (result = 4 then result = 3). In other words, it is never a good idea to work around something like this that should work, but doesn't. When Requinix asked what changed, we were expecting something like: "Upgraded to PHP 7" or "I added a new library" or "I am refactoring the database class." Sounds to me like you went and made your codebase a lot less DRY, which made it worse.
×

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.