I have indeed searched the forum and google for a bit. To no avail. I wrote the following:
$steamInfo = $_POST['steam64'];
if($steamInfo != preg_match('/7656119[0-9]{10}/i', $steamInfo)){
echo "Incorrect Steam64";
die();
}
and this works on 1 part of my website using a different set up of ifs / ifelse for an entirely different reason. This time, however, when I enter steam64 no matter what it returns echo. Basically; I need this to tell the user they need the correct steam 64 , I've tried the following as well , which is a slight variation;
if(!preg_match('/7656119[0-9]{10}/i', $_POST['Steam']) ) {
echo "Incorrect";
}
Again, no luck. I also tried storing preg_match as a variable and still nothing lol. Looking for some guidance on how to proceed to have this check for a steam64 and not accept anything else.
Thanks!
Related
Before anyone tells me to look at other similar posts, I already have and I cannot find any solution to my problem.
I am building a questionnaire for a project, and I am using php 5.6, xampp, phpmyadmin, Phpstorm 2017.1.2 and of course the usual languages html css javacript.
In order to write less code, I used the masterpage method to build my website for the questionnaire.
I therefore have a do-test.php where I put my questionnaire alone and an index.php where I have the main skeleton of the page.
I have my questionnaire form with various fieldsets and their inputs. Lastly I have a input type=submit button that I click and the form is supposed to be submitted. However my $_POST method is not working at all.
The following code does all the work. Unfortunately for reasons yet unknown to me, when the if statement runs, it doesn't even look at the isset or !empty method.
Using an IDE debugger
Debugging the do-test.php without the master-page.: My xdebug (installed in phpstorm), jumps directly from the breakpoint in if statement to the bottom of the page. I tried using an else with a message that "submit is not set" and it shows it before and after submitting the form.
if(isset($_POST['Submit']) && !empty($_POST['Submit'])) {
$results = new Results();
$results->ProcessRequest();
if ($results->isSuccessful()) {
echo "<script type='text/javascript'>
alert('Your data is sent to the server');
</script>";
} else {
echo "<script type='text/javascript'>
alert('Something went wrong.');
</script>";
}
}
My http raw post data is visible but the post array is empty.
Debuggin the do-test.php with the master-page: Gets me 502 bad gateway error
Debug using localhost
Using this code snippet here I tried to see what is going on.
Submitting the form from the master-page or the simple do-test page, gives me the following result:
which means that my post array has all the right variables. All that remains is for the method to be executed and for the data to pass into the db.
My post_max_size and variables_order (advise taken from here) are correct.
magic_quotes_gpc (from this post) are off in php.ini.
Could it be the http modules that interfere with POST as told by GeorgeMillo
here??? If so how do I tamper with those?
Could there be something wrong with my version of phpstorm or the php version?
Any suggestion is welcome. Thank you in advance.
I may have written one thing wrong so I gave the wrong impression. I wrote "when the if statement runs", when in fact, the debugger runs and tries to execute the if statement but it doesnt. Sorry for my bad explanation.
The member "Alive or Die" gave me the simple solution of using
if(count($_POST)>0)
and it works!! So I will stick with that.
Thanks to everyone for your fast comments and for pointing out the obvious when one cannot see it!!
this is my first time using PHP in a real project environment. The project is pretty simple, take an existing, working PHP site and update the HTML to be consistent with HTML5. After designing the HTML, I am inserting the PHP from the previous site. This works most of the time, but I get a few errors. For instance:
<?
$sec = $_GET['sec'];
if ($sec == "1") {
echo ('Success!');
}
?>
Is causing the error:
Notice: Undefined index: sec in /file_that_holds_site_build.
Of course that is only if the url doesn't include the append tag (=1) that alerts the message.
So the question is this, what am I missing that causes the $GET when there is no $sec? How do I eliminate this error on first page load?
You're getting that notice because you're trying to access an array index that doesn't exist in some scenarios. Here's how you should be getting the data out of the request.
$sec = array_key_exists('sec', $_GET) ? $_GET['sec'] : null;
Thanks to everyone who provided possible answers to this question. It was Daniel that came up with the easiest fix. Again, I am just adjusting someone else's code to work, so a universal solve would involve too much of my own writing. To the point, the final code looks like this:
<?
if (isset($_GET["sec"])){
$sec = $_GET['sec'];
if ($sec == "1") {
echo ('Success! Your username and password have been sent via email.');
}}
?>
Notice the added if statement. As I said in a comment to Daniel, SO SIMPLE!
Thanks again for everyone's help. I hope to be likewise of service to you all soon.
Simple just use isset($_GET['sec']) to check for the parameter 'sec' before using it in the php code. That should eliminate the error. This is quite trivial I suppose.
I often simply extract() the wohle $_GET super global and then either get the desired variable or not. As a kind of "declaration" I initialize each expected variable first with false. This way I find it much easier to handle than individually doing a check like if(isset($_GET['element'])) ...
$var1=$var2=$var3=false; // my desired variables
extract($_GET); // everything I get from the form
// or: extract($_REQUEST);
if ($var1) { /* do something with it */ }
Possible security risk:
Of course you should be aware that everybody could simply include their own variable as an argument to he page ...
As part of a page I'd like to be able to show files available for download if they contain the GET result number ($_GET[number]). However, what I'm doing doesn't appear to be working, and I'm also not sure it's a particularly secure means of achieving it either. Here's what I'm trying so far (which doesn't display anything at all!):
foreach (glob("Files/*$_GET[number]*.*") as $filename) {
echo $filename."<br />";
}
You definatly should check $_GET["number"] if is really and only a number for security reasons.
$_GET["number"] = intval($_GET["number"]);
Sorry but too low reputation to post this as a comment..
This may be hard to help me with but I'm out of options and have no hair left so here goes;
I have this simple part in my program where if a check box is disabled and the user is using the site on a device like an iPad they will get an alert box popup if they touch the check box. The problem that I'm having is that it works as expected on one domain but then on another domain it just flashes very quickly then goes away.
Because I don't have a Mac computer I can't use the Safari Web Console installed to see if any errors are coming up.
Here's the code to generate the alert;
if ($device == 'TAB') {
echo "<div id='" . preg_replace('/[^a-zA-Z0-9]/', '', $menu_name) . "OV'
class=\"overlay\" onClick=\"alert('My message');\"></div></div>";
} else {
echo "</div>";
}
Any ideas of why this would work in one place and not the other and anything that I can do to try to get the iPad to give me more info to what's going on here?
Here is where it works, interactive-floor-plan dot com/ifp.php?width=633&ProductID=1
and here is where it doesn't
plangator dot com/demo/ifp.php?width=633&ProductID=1
Your code seems completely fine to me, although your echo is a little bit unclear, because it's on one line. The problem should be somewhere else on your page. Try to find out what's happening with firebug. Here's a SO post about it.
iPad firebug lite or similar
Both links on that page seem useful to me.
Good luck!
I apologize if this has been answered, but I haven't been able to find anything about it. I've been having trouble with a certain block of PHP code on my server and have finally realized that it doesn't like single line comments. With this code, the method get_all_articles is never called.
<?php
$article_class = new Articles();
// Fetch all articles
$articles = $article_class->get_all_articles();
?>
However, removing the comment or converting it to a block comment allows the page to render perfectly. I realize that I've already figured out what's causing the problem, but what I'm looking for is why or how I might be able to fix it. Any help would be greatly appreciated. Thanks!
Maybe the formatting is getting lost on upload to where line breaks are being deleted? Try downloading the PHP file after you've uploaded it and see if the line breaks are still intact.
This can be frustrating... One time I had an if statement that would ALWAYS execute, no matter what the values were...
Started out as this, where $x was equal to 5 (I verified this with debugging)
if($x > 10);
{
....
}
Eventually, I had it down to this:
if(false);
{
echo("This should never happen");
echo("but it does!!!!!!!");
}
After much loss of hair, I realized that I had a semi-colon at the end of the if() line, therefore translating into:
if(false)
/*do nothing*/;
{
//Nice block that always executes
}
The moral of this story is that while the problem you percieve is actually giving you a problem, it is not a PHP problem. Try to find out the root cause by first verifying that the actual code that is executing is EXACTLY what you typed. Re-download the file, publish with different protocol, publish as binary, check sha1sum() on files to make sure the same... Look and look and you will find it.
Let us know.