-
Who's Online 1 Member, 1 Anonymous, 643 Guests (See full list)
All Activity
- Past hour
-
according to the 1st parameter, you are making a GET request. not a POST request. the main point of my 1st reply in this thread is that your code must validate (all) input data before using it. the account_no input is required (not an empty string), it must consist of a specific set of characters (decimal digits), and it might need to be a specific length or range of lengths. if it is not valid, it is an application error and you should setup and output a useful error message for each of these possible validation steps, and not attempt to use the input data. your first posted code and the code using the null coalescing operator are suppressing any helpful php errors (you would be getting an undefined index error) that would be pointing out that there is no expected entry in $_POST. so, you must change the php code to use $_GET['account_no'], and you must trim, then validate the input before using it. you would only get to the point of testing if the value is in the array of $valid_accounts if the input is valid.
- Today
-
if i add a "echo($account_no);" then it shows me there's "0" account numbers in that array, so the problem for me seems to be this line $account_no = $_POST['account_no'] ?? 0;
-
Thank you both for your reply. I use this php script with a webrequest from an Expert Advisor in MT4. The webrequest looks like this : string url = "https://johnnylai.me/license/customers.php"; string headers; char post[]; char result[]; string resultHeaders; int response = WebRequest("GET", url, headers, 1000, post, result, resultHeaders); Print(__FUNCTION__," > Server response is ", response, " and the error is ", GetLastError()); Print(__FUNCTION__," > ", CharArrayToString(result)); return(INIT_SUCCEEDED); I know it has nothing to do with php, but the only reason i ask in here about that was that i use a php script to check on my server if the account was there or not and no matter what account no i use it does not see it in the php array, so i guess the problem is in the php script cause the mq4 code seems to talk to the php on my server. This is the message i get in MT4 expert tab telling me there's no account.
-
Pynetlabs joined the community
-
if ($statu1 = "Online") { echo "<font color = green>$status1->nodeValue</font><br>"; } elseif ($statu1 = "Offline") { echo "<font color = red>$status1->nodeValue</font><br>"; } One = does an assignment, which means the above code actually works like $statu1 = "Online"; if ($statu1) { echo "<font color = green>$status1->nodeValue</font><br>"; So naturally, every status will be green. Two ==s does equality comparison. (Three ===s is if you want to be pedantic about what it means to be "equal".) if ($statu1 == "Online") { echo "<font color = green>$status1->nodeValue</font><br>"; } elseif ($statu1 == "Offline") { echo "<font color = red>$status1->nodeValue</font><br>"; } That aside, this is very outdated HTML 4-style markup. You should switch to <span>s and CSS.
-
Hello, I am pulling data from a site I want to give color according to the value that I want to do, is this possible? I am doing it with the code below but the result is always green $url = "simple"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($curl); curl_close($curl); $dom = new DOMDocument(); @$dom->loadHTML($data); $xpath = new DOMXPath($dom); $statu1 = $xpath->query('//*[@id="page-wrapper"]/div/div[6]/div/h4[7]/span'); foreach ($statu1 as $status1) if ($statu1 = "Online") { echo "<font color = green>$status1->nodeValue</font><br>"; } elseif ($statu1 = "Offline") { echo "<font color = red>$status1->nodeValue</font><br>"; }
-
krygnc joined the community
- Yesterday
-
the reason for unusual operation is the ternary operator without a middle term, that the input is probably not what you expect, and php's type casting. when you leave out the middle term in the ternary operator, when the first term evaluates to true, the value used is whatever the first term is, which will be a boolean true due to the empty() statement. instead, your post method form processing code should - detect if a post method form was submitted before referencing any of the form data. detect if there is $_POST data (in case the post_max_size setting has been exceeded.) keep the form data as a set in a php array variable, then operate on elements in this array variable throughout the rest of the code. trim all the input data, mainly so that you can detect if all white-space characters were entered. validate all inputs, storing user/validation errors in an array using the field name as the array index. after the end of the validation logic, if there are no user/validation errors, use the form data. after using the form data, if there are no user/validation errors, perform a redirect to the exact same url of the current page to cause a get request for that page. this will prevent the browser from trying to resubmit the form data should that page get browsed back to or reloaded. if you want to display a one-time success message, store it or a flag value in a session variable, then test for, display the success message, and clear the session variable at the appropriate location in the html document. if there are user/validation errors, the code will continue on to display the html document, where you will test for and display any errors, redisplay the form, populating fields with existing data, so that the user only needs to correct the invalid input(s) and can resubmit the form.
-
You didn't provide the form that targets this script, but often the issue with people new to PHP superglobals, is that $_POST only gets set to data that is in an actual POST request. <form action="url/to/yourscript.php" method="POST"> If the form includes a file input, you also need to set the enctype to multipart/form-data. <form method="post" action="url/to/yourscript.php" enctype="multipart/form-data"> Your code has this: $account_no = empty($_POST['account_no']) ? : $_POST['account_no']; A cleaner way to handle this would be to use the null coalescing operator "??" $account_no = $_POST['account_no'] ?? 0; One last piece of advice: Leave off the PHP end tag. You don't need it, and in some cases it can cause trouble. This and other formatting standards and advice can be reviewed in https://www.php-fig.org/per/coding-style/
-
I'll add that if you're retooling things now to deal with your hosting company, take the time while you're at it to switch to PHPMailer or Symfony Mailer. They're both massively easier to use and more reliable than php's native mail() function.
-
If you're using 3rd party email service, then you should be sending email through them. They also should provide you the SPF, DKIM and DMARC TXT records you would need to add to your DNS. Really this is a question for your hosting company, as the details of how they support email differ based on the hoster.
-
Admin please delete the post above thx.
-
Hello, I have this php file <?php $account_no = empty($_POST['account_no']) ? : $_POST['account_no']; $valid_accounts = array(501412195); $result = in_array((int)$account_no,$valid_accounts); if($result) { echo('Success'); } else { echo('Failed! - no account where found... '); } ?> It print out "Failed! - no account where found..." no matter what account number im using. If i change $result = in_array((int)$account_no,$valid_accounts); to $result = in_array($account_no,$valid_accounts); it print out "Success" not matter what account number i use. What is wrong with the code i have?
-
FXSniperGuy joined the community
-
It would be good to actually explain where you are using this regex. Looks like it's in a spreadsheet. Regex engines can have different syntax and capabilities. You also provided examples of strings that I guess don't work right, but you didn't include the output you expect. That is important information to include in a question like this. The core of this is very simple. [A-Z][a-z]+ Things inside a [] pair are called character classes. So this means: Match any uppercase character -> [A-Z]. This will be a single match. Then match any lowercase character [a-z]. The "+" following is a quantifier which means "1 or more times". So for a match to be made, it requires at least 1 lowercase letter. So the obvious problem with this example: Zentropa International SwedenCanal+Ciné+ Is that it has a plus sign. That could be fixed by this: [A-Z][a-z+]+ However, the non - obvious problem is that you have a non-ascii character in Ciné, which wlll also not match. I am going to make an assumption here that you're using excel, and that it supports .NET's regex library. So by substituting a unicode specific character class that matches any "lowercase" unicode character, as well as allowing a + sign to be part of a string this would work: [A-Z](\p{Ll}|[+])+ I don't know if these are the only strings you have that are problematic, as company names can have all sorts of other non-ascii characters you might have to deal with. Which brings us to this: Nordisk Film ProductionNadcon FilmZweites Deutsches Fernsehen (ZDF) I assume the problem is that nothing will match the (ZDF). This is really a weakness of the approach. A better approach for this would be: Parse original string into an array using the space as a delimitter For each element in the array, perform the regex replacement that finds capital letters and adds a space to break it up into multiple words Rejoin all the elements in the array using a space This would fix the problem with the ZDF as well as any similar issues, as the regex replacement would not affect existing "words" like the "(ZDF)". I hope this helps you. Vibe coding/copy paste only gets you so far when you aren't able to study and understand how the code works, and whether or not it is applicable to your problem.
-
Paulfin489 joined the community
-
Hypnotized1 joined the community
- Last week
-
Hey everyone, I changed the service I use for my e-mail hosting away from my website hosting. The only "email thing" I really use the hosting service for is sending emails, for reason explained below. Usually, I would have changed the SMTP settings using php.ini, and been done with it, however, my shared hosting has removed that ability. This has created two unique problems: 1. Now that my my email is handled by a third party, the hosting no longer DKIM signs emails it sends out using "mail()" 2. The "header from" and the "envelope from" no longer match by default. The ladder is the default shared hosting domail email. These two issue resault in the mail going into the spam folder. I can fix this by using either the phpmailer library, or the -f parameter in mail; however that now means compatabilty issues with future applications I install, that depend on the php.ini information being accurate. Is there any workaround you guys can think of that might help me fix this?
-
php segmentation fault when connecting to Access database
requinix replied to raphael75's topic in PHP Coding Help
Not having symbols is okay, it just means that gdb won't be able to fully translate the machine symbols it's reading into more useful, human-friendly symbols - like, parts of a backtrace will be cryptic. But it'll all still work fine. -
php segmentation fault when connecting to Access database
raphael75 replied to raphael75's topic in PHP Coding Help
@requinix I'm not sure what happened, but when I start gdb now I get this error: $ gdb php GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git Copyright (C) 2024 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from php... This GDB supports auto-downloading debuginfo from the following URLs: <https://debuginfod.ubuntu.com> Enable debuginfod for this session? (y or [n]) y Debuginfod has been enabled. To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit. Downloading separate debug info for /usr/bin/php8.3 (No debugging symbols found in php) (gdb) I tried searching on that error "(No debugging symbols found in php)" but I couldn't find anything. I don't understand why it was working before and then stopped working. -
I was following along until the "please do this for me" bit at the end. REGEXREPLACE + REGEXEXTRACT like that is silly. Not sure where you got it from, but a single REGEXEXTRACT is enough to extract all the <uppercase letter + stuff>s in the cell. Check the documentation/help docs for how to make it match everything instead of just once (which is what it does by default). For the regex part, it's currently doing <uppercase letter + lowercase letters> so naturally it will only work with lowercase letters and not with numbers or symbols. If you want to match things that look like <uppercase letter + stuff> then realize that "stuff" is a less precise way of saying "keep going until the next uppercase letter". Or in other words, "anything that isn't uppercase". Because computers need you to be precise if you want them to work a certain way. Excel's regex syntax for "anything that isn't ___" is the same as everybody else does it, so you can check either the docs (which I'm sure include a little bit of regular expression syntax) or virtually any other regex resource to find how to write that.
-
Hello Regexperts, I have pulled a regex from the internet to seperate words that start with capital letters. The regex is here TEXTJOIN(" ",,REGEXEXTRACT(R158,REGEXREPLACE(R158,"([A-Z][a-z]+)","($1)"))) When I have this: HummelfilmTamtam FilmThe Imaginarium Films The Regex works and returns this: Hummelfilm Tamtam Film The Imaginarium Films But when I have this Nordisk Film ProductionNadcon FilmZweites Deutsches Fernsehen (ZDF) or this Zentropa International SwedenCanal+Ciné+ The Regex breaks. It looks like the presence of non alphanumeric characters is causing the problem. Can anyone please help me out and rewrite the Regex so that it works with non alphanumeric characters too?
-
PHP array... $data = [ 'store_id' => 'test', 'api_token' => 'test', 'checkout_id' => 'test', 'txn_total' => '4.00', 'environment' => 'qa', 'action' => 'preload', 'cart' => [ 'items' => [ [ 'description' => 'Item 1', 'unit_cost' => '1.00', 'quantity' => '3' ], [ 'description' => 'Item 2', 'unit_cost' => '1.00', 'quantity' => '1' ] ], 'subtotal' => '4.00' ] ]; $json = json_encode($data); echo $json; gives this json string (spaces and newlines added for readability) { "store_id":"test", "api_token":"test", "checkout_id":"test", "txn_total":"4.00", "environment":"qa", "action":"preload", "cart":{ "items":[ {"description":"Item 1", "unit_cost":"1.00", "quantity":"3" }, { "description":"Item 2", "unit_cost":"1.00", "quantity":"1" } ], "subtotal":"4.00" } }
- Earlier
-
How to represent this JSON data as PHP?
TrialByFire replied to TrialByFire's topic in PHP Coding Help
Thanks for the reply everyone, No basically I wanted to know how to actually declare the PHP object so json_encode() would return everything properly. What tripped me up was that there's an Array inside an Array inside of an Array and it made the actual declaration too confusing to write. So I broke it up into sub arrays and then declared the largest array by calling the smaller arrays. I have it working now, and I really appreciate the help! -
No the idea is, if I send or receive email from a email with pgp the php script does nothing. if I receive an email from someone who doesn’t, the php script will encrypt it on my server. if I sent it to someone that doesn’t have it, it will send a plain text email, then encrypt the local copy.
-
Header Location redirects to 200 instead of 302
gizmola replied to engageub's topic in PHP Coding Help
PHP will set the response code to be a 302, when it issues the Location header. If this same code was running, but it was sending a 200, that could be because either the webserver or something in the code has already set the response code. We have no context or information on what triggers this code. The only other thought I could contribute is that a 302 should not be used if the redirect is being issued in response to a POST request, you should not use the 302, but instead issue a 307. This is discussed here. -
Why? Do you expect everyone you send email to, to use PGP to decrypt your emails?
-
There's been a name for this type of UI/window/panel effect for a while under the moniker of "glassmorphism". So if you do some googling for that with css, you'll find a lot of different examples. Here's one of many: https://codepen.io/kanishkkunal/pen/QWGzBwz One thing to note is that most implementations make use of backdrop-filter, and you want to check caniuse for support.
-
Hi all This image is from Apple's new OS... and they called it Liquid Glass. I was wondering if there is some smart CSS you could create to turn this effect, into a Button? I know you can do blurring, but like this? with that sort of edging.. I tried a box shadow but even with rgba background of the button, it doesn't show thru. Love to see some ideas.