premiso
Members-
Posts
6,951 -
Joined
-
Last visited
-
Days Won
2
Everything posted by premiso
-
Did you try it? The reason it was returning true was because 1 or 20 had an alpha character, which was a valid response.
-
Better to do that check outside of regex: $stringLen = strlen($string); if ($stringLen < 1 || $stringLen > 20 || !preg_match("/[A-Za-z]*/",$input) ) { echo 'You have provided invalid input. Valid input ......'; } Untested, pending any retarded errors I made should work for what you want.
-
If I am not mistaken the {1,20} means 1 OR 20 not one through 20. Chances are that is your issue.
-
Yep, you are right. I had my kid in my hands so yea. Here is a better version, given my sql guesses of your system are correct. <?php $query = "SELECT count(u.username) as membercnt, u.alliance FROM alliances a, users u WHERE a.draft=1 AND u.alliance = a.allianceno GROUP BY a.allianceno ORDER BY count(u.username) DESC LIMI 10 "; $result = mysql_query($query) or die("Error: ".mysql_error()); $topTen = array(); $display = ""; while ($row = mysql_fetch_assoc($result)) { $topTen[] = $row["membercnt"]; $display .= "Alliance: " . $row['alliance'] . " has " . $row['membercnt'] . "<br />"; } echo $display; ?>
-
order by count(usernames) desc limit 1 should do it if I am not mistaken. I am sure there is a better way to do it, but have my hands full atm.
-
You are going to want to look into the e modifier for the preg functions, as it will do the eval.
-
Chances are in your vhost / apache settings you have MultiViews set somewhere under the options. http://httpd.apache.org/docs/1.3/content-negotiation.html Basically it tries to correct urls itself and this is why it goes to page.php instead of being filtered through htaccess / index.php. [ot]You should not include php files like you have done, this can easily be used to exploit your server. IE: include($url . ".php"); should not be used.[/ot]
-
You seem to be typing fine in english and seemed to understand what people were suggesting / asking of you in this post. I am pretty confident you could figure out what was written in that sticky to help you solve your issue.
-
Notice, your solution was in the first reply: Quote from: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Next time you should read the sticky and try what it suggest to fix the error, as that sticky was set to help you solve your own issues. It just takes a small effort to read it.
-
Not anymore. I know your salt, so all your base are belong to us!
-
Fatal error: Call to undefined function pg_escape_string()
premiso replied to swraman's topic in PostgreSQL
It may be configured, but you also have to enabled the extension in the php.ini. Check that the extension is uncommented (does not have a ; infront) if it is not uncommented, uncomment it and restart the server. -
http://www.raditha.com/php/ftp/ Should be right up your alley.
-
You probably want the fsockopen in the ipn.php page to point to www.sandbox.paypal.com as well.
-
You only use SET at the beginning: UPDATE stacks SET number='$number, username='$username' ....etc
-
$timeSince = time_since(strtotime($timeAdded)); echo $timeSince; function time_since($original) { // array of time period chunks $chunks = array( array(60 * 60 * 24 * 365 , 'year'), array(60 * 60 * 24 * 30 , 'month'), array(60 * 60 * 24 * 7, 'week'), array(60 * 60 * 24 , 'day'), array(60 * 60 , 'hour'), array(60 , 'minute'), ); $today = time(); /* Current unix time */ $since = $today - $original; if($since > 604800) { $print = date("M jS", $original); if($since > 31536000) { $print .= ", " . date("Y", $original); } return $print; } // $j saves performing the count function each time around the loop for ($i = 0, $j = count($chunks); $i < $j; $i++) { $seconds = $chunks[$i][0]; $name = $chunks[$i][1]; // finding the biggest chunk (if the chunk fits, break) if (($count = floor($since / $seconds)) != 0) { // DEBUG print "<!-- It's $name -->\n"; break; } } $print = ($count == 1) ? '1 '.$name : "$count {$name}s"; return $print . " ago"; } Snippet came from: http://snippets.dzone.com/posts/show/3044
-
I think all you need to do is just echo $file instead of readfile. readfile is generally for passing a path to a valid file and actually reading it. Since the file data is stored in the DB, just echo it.
-
preg_match('~input.*name="authenticity_token".*value="(.*)"~i", $twit_source, $match); $vals[1][1] = $match[1]; Should work.
-
So his script can access the database. And storing the database information in cookies is just well...not advised, for lack of a better word. As for "somehow write these variables to a file" what is wrong with something like: $config = <<<CONFIG <?php $mysqlHost = '{$valuefromform}'; $mysqlUser = '{$valuefromform}'; $mysqlPassword = '{$valuefromform}'; $mysqlDatabase = '{$valuefromform}'; ?> CONFIG; $fh = fopen('config.php', 'w'); fwrite($fh, $config); fclose($fh); // lock file down to only be read by webserver / script. chmod('config.php', 0600);
-
It is called the Ternary Operator. Which as stated, it acts as a shortened if / else. As for why it exists, it provides it uses. Namely, for the code you shown, which coincidently I wrote, allows for you to handle invalid / not passed in variables a bit easier without having to do a full on if statement. Some people prefer to use the full on if statement, but for simple assignments, why not use ternary? It does not detract from the code and a full on if statement is not usually needed as all you want to do is make sure that variable has a value assigned, namely for error testing purposes. $name = isset($_POST['name'])?$_POST['name']:null; $address = isset($_POST['address'])?$_POST['address']:null; // VS: if (isset($_POST['name'])) $name = $_POST['name']; else $name = null; if (isset($_POST['address'])) $address = $_POST['address']; else $address = null; As stated, some people do not like it. I like it for assignments like the above, as it just makes sense to me to do it as such.
-
How to get a bytearray for an image on my filesystem
premiso replied to JeremyCanada26's topic in PHP Coding Help
This may work, un-tested: $byteArray = toByteArray(file_get_contents($file)); $file_checksum = crc32(implode("", $byteArray)); function toByteArray($string) { $byteArray = str_split($string); $return = array(); foreach ($byteArray as $item) { $return[] = ord($item); } return $return; } I am not sure if this will work, but may give you some ideas on how to get it. EDIT: An alternative function code, which may be better: function toByteArray($string) { $byteArray = str_split($string); array_map('ord', $byteArray); return $byteArray; } -
How to get a bytearray for an image on my filesystem
premiso replied to JeremyCanada26's topic in PHP Coding Help
$file = '/tmp/g23uh4'; $file_checksum = crc32(file_get_contents($file)); $checksum = 'sum grabbed from source'; if ($checksum == $file_checksum) { echo 'file is valid'; }else { echo 'file is not valid'; } -
Ternary operator, it acts a shortened if else. Basically it goes if (isset($_POST['testbox'])) { $testbox = $_POST['testbox']; }else { $testbox = null; } Same thing, just shortened.
-
If they are bots, you can try and implement reCaptcha to at least slow them down in their user creation process. But if they are spam bots, ips etc is not going to help. They generally use proxies and generate a new ip for each new account etc and user_agents are easily spoofed.
-
SELECT first_name, last_name FROM table_name WHERE first_name = 'bart' AND last_name = 'simpson' And if you get a record back, the name is already in the database. If no records are returned, then the name combination is not in the database.