Jump to content

MMDE

Members
  • Posts

    654
  • Joined

  • Last visited

Everything posted by MMDE

  1. Okay. I've never used FluxBB. I once programmed for some other forum software, and you will have to read and study a little bit to understand exactly how to make an add-on for FluxBB. Should be some kind of documentation somewhere. Most likely will the add-on system support installation and uninstallation, so you should program both. In your case... I would make the installation script alter and add an extra column in the user table in the database. I would add some extra menu for changing color or adding some extra options at the end of some option page that already exists. It would simply be a form where you select a color and then when saving it would save it to the database. Make sure to also either use some already existing validation script in the server or create one yourself. It is very important you validate the data to be safe to use against the database. You also need to make the script add the color to each user when avatar and username etc is loaded. Simply extend the sql query to get the extra column and output it along with the username just inside some html font tag or something or styling of some sort. Just remember to make it so you can later remove it. To uninstall the script, make sure it can remove everything you've added. Like dropping the extra column from the user table (make sure to not drop the entire table). etc I recommend creating a test forum and play around with it first. Read the forum's code and try to understand it. :s Alternatively you can try to pay someone to do it for you.
  2. You need to specify a name attribute for the input tags... <form action="eatnlocal_validate.php" method="post"> <P> Name: <input type="text" id="name" name="name"><br> Restaurant name: <input type="text" id="restaurant" name="restaurant"><br> Email: <input type="text" id="email" name="email"><br> <input type="submit" value="Submit" name="submit"> </P> </form> and you don't really need to use id, unless it has something to do with your CSS or something...
  3. Got no idea what kind of forum software you use. Have you programmed it yourself? (Kind of doubt it since you are asking this question). Does it support add-ons? If it supports add-ons, I would think you could write one. If it does not have an add-on system you will have to edit the forum code.
  4. We don't see your code, how should we know? Please post it! My tip is to trace it all the way back to where you think you get it from and echo it all the way from there to wherever you lose it.
  5. <?php function get_data($url, $post=null, $header=false, $cookie=null, $ref=null, $ssl=false){ $ch = curl_init($url); if($post){ curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } if($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie); if($ref) curl_setopt($ch, CURLOPT_REFERER, $ref); curl_setopt($ch, CURLOPT_HEADER, $header); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ssl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); return curl_exec($ch); } function add_postfields($data, &$post){ $site = new DOMDocument(); @$site->loadHTML($data); $inputs = $site->getElementsByTagName('input'); foreach($inputs AS $input){ if($input->hasAttribute('name')){ switch($input->getAttributeNode('name')->value){ case 'nl.marktplaats.xsrf.token': $post['nl.marktplaats.xsrf.token'] = $input->getAttributeNode('value')->value; return; } } } } function get_cookies($data){ preg_match_all('|Set-Cookie: (.*);|U', $data, $matches); return implode('; ', $matches[1]); } function marktplaats($url, $username, $password){ $post = array( 'j_username' => $username, 'j_password' => $password, 'remember_me' => true ); $data = get_data('https://vernieuwd.marktplaats.nl/account/login.html', null, true, null, null, false); add_postfields($data, $post); $cookies = get_cookies($data); $cookie = get_cookies( get_data( 'https://vernieuwd.marktplaats.nl/account/securityCheck.html', http_build_query($post), true, $cookies, 'https://vernieuwd.marktplaats.nl/account/login.html', false ), $post ); return get_data($url, null, false, $cookie); } $url = 'http://vernieuwd.marktplaats.nl/'; $username = 'username'; $password = 'password'; $data = marktplaats($url, $username, $password); echo $data; ?> If you want the activity to seem a bit more "legit", then you could add: curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0');
  6. To further extend upon what Christian F. said... You can easily write a script that makes a regex which will make preg_match return true if at least one of the words in the input are in the string. word1|word2|word3 etc You can also make preg_match return true if one of the words input are found as a whole word in the script, and not the part of a word: ((\W|^)word1(\W|$))|((\W|^)word2(\W|$))|((\W|^)word3(\W|$)) The hard part comes when you want it to contain all the inputted words in one regex pattern... Then you get a very long permutated string, which I totally don't recommend (might be there is some way around it I don't know about). In this case I think a better option would be to loop through all the words and make sure you find them all in the string. function match_input($input, $string){ $one_match = false; $words = explode(' ', $input); $wc = count($words); for($i=0; $i<$wc; i++){ if(preg_match('/\A\s\Z/', $words[$i])){ continue; } if(!preg_match('/(\W|^)'.$words[$i].'(\W|$)/', $string)){ return false; }else{ $one_match = false; } } if($one_match){ return true; } return false; } Sorry, did a couple of typos, but I think I've fixed 'em all now! I also just added another small change to one of my codes, to check if the $words[$i] only contained white-space characters, and to ignore those, and also to return false if no words was actually found in the string.
  7. Do you check if $_GET is set before you use it? Though, I only get Undefined index: no, when I don't set it. <?php $string = 'some text test'; if (preg_match('/'. urldecode($_GET['no']) . '/i', $string)) echo 'TRUE: '.$_GET['no']; else echo 'FALSE '.$_GET['no'] ?> ^ Worked as expected for me. results: TRUE: test TRUE: text FALSE string TRUE: some FALSE some text string TRUE: some text test etc BUT watch out for special characters like (, ) and many others: Warning: preg_match() [function.preg-match]: Compilation failed: unmatched parentheses at offset 4 FALSE some) Warning: preg_match() [function.preg-match]: No ending delimiter '/' FALSE some\ Warning: preg_match() [function.preg-match]: Unknown modifier '/' FALSE some/ I would strongly suggest not using user input in the regex pattern, unless you are very sure you've tested it to be safe already.
  8. The problem is you are not giving the server what it wants. Different sites use all kinds of strange ways to verify various data, sometimes there are redirects and then there's sessions/cookies etc. I recommend usin Live HTTP headers, an add-on for firefox, to catch all the header data that is sent. You will need to try to replicate it. Send me a test account in PM and I could try to help you later tonight or tomorrow or something like that, but try some on your own first please. I recently did tumblr for someone here, and while that was fun, it took a little while.
  9. If I am to understand this correctly, arrays in PHP is hash maps? If that is the case, the worst case time it takes to find something in an array is O(log(n)), right? Shouldn't there then be cases where foreach could be faster to loop through an array with? Imagine the case of a huge array of integers, maybe some thousands. Would it use the same time accessing each of the entries in the array with foreach as a normal for loop? If that is not the case, what if it is a huge array filled with arrays of integers, and you use more than one or two of the values in each array you loop through the giant one? I understand there is quite a huge advantage of using a for loop because you have more control of exactly what key you use against the array. Thoughts?
  10. Do you want to do this because of bandwidth to the server? If this is not the case, then you can use HTML and CSS for this. http://dev.w3.org/ht...markup/img.html If you really want to re-size it to save bandwidth, then you need to use one of the image processing libraries in PHP, here's a good list of some of them: http://www.php.net/m...lspec.image.php I've only really used GD: http://www.php.net/m.../book.image.php I know it can do what you are asking for and there should be lots of tutorials for it online.
  11. What part of "Just for fun... ;o" did you not understand? It was never meant as a robust re-usable component or anything like that, just to show the idea behind the code. Which is also why I wrote 5 different ones. It's just meant as examples and things to continue work on for him. I'm not here to do his work. This is what I react to: ^ You are not correcting me at any point here, you're being nothing but a jerk. Your "points" are lost in the way you write it. It seems you are more eager to tell me I'm wrong and insult me than actually trying to write something useful for the user.
  12. Also, it seems I didn't use the same regex in both the edits... I made a small adjustment: '/1000|[1-9][0-9]{1,2}|[1-9]/' It looks for matches in this order: 1000 (1000) OR first character is between 1 and 9, the second and maybe third is between 0-9 (10-999) OR first character is between 1 and 9 (1-9) preg_match($input, $regex, $matches); Looks for matches of the regex pattern in the input. Stores them in $matches Stops after finding one match. Returns the number of matches. // if any matches if(preg_match($input, $regex, $matches)){ echo $matches[0]; // the first and only match }
  13. Without changing the class: <?php class Person { private $name; function __construct($name) { $this->name = $name; } function setName($newName) { $this->name = $newName; } function getName() { return $this->name; } } class Person2 extends Person{ public function nameLength(){ return strlen($this->getName()); } } $person = new Person2('the name'); echo $person->nameLength(); ?> <?php class Person { private $name; function __construct($name) { $this->name = $name; } function setName($newName) { $this->name = $newName; } function getName() { return $this->name; } } $person = new Person2('the name'); echo strlen($this->getName()); ?>
  14. I wrote 5 similar functions to show 5 different stand-alone functions. I did not try to use them at the same time, and they are not supposed to do so either. I suppose I could have written a way to compare these, that simply by putting them all in the same loop. They way of guessing was the variation. All I did was copy/paste them quickly. I suppose the last one I posted is not good enough either to verify the data is a number, just to see if it is in range if it is a number. With the code I wrote, it would never happen.... There would be no SQL injections. Read it, don't just act like a jerk. It takes only what matches the regex, only numbers. It doesn't care about the rest of the input from the user, because it doesn't use it. Neither is there any SQL connection in my code. I think the biggest problem is this site's way of formatting code. I guess this is a problem caused by me. I made the check dependent on regex. You need to understand what it does before you change it. o.O It takes the first number that matches the pattern. The pattern is 1000 OR first character 1-9 the next two 0-9 OR first 1-9 the next one 0-9 OR the first is 1-9.
  15. I think it's more when it comes to reading you got much to learn... It's like you didn't read the code at all... >_> 1. There are 5 functions so the person can see the different variations and see how they perform. No need for callback. Using callback here is very wrong when all I'm doing is showing him the 5 different variations. 2A. That would never happen... if(!empty($_POST['guess']) && preg_match('/[0-9]{1,3}/', $_POST['guess'], $match)){ $number = $match[0]; I know he asked for between 1 and 1000, but again, just for test purposes, I wrote the regex to match between 0 and 999, hence why I used that in the code as well. The functions could easily be adjusted thereafter. No need to prevent when it will never happen, while not completely wrong to do what you are saying, it's pointless. EDIT: I believe this regex would suffice what he wants: '/1000|[1-9][0-9]{1,2}|[1-9][0-9]|[1-9]{1}/' 2B. I don't get what you are talking about here, but I implemented what he request in the 3rd variant. First it guesses a random number. Then it gets to know if its lower or higher. If it's higher then we know the number we are looking for is minimum the number we guessed +1. We then take max-((max-min)/2) and round it. This will end because of +1 and -1 with the max and min value. function computer_guesses($number){ $min = 0; $max = 999; $guess = rand($min,$max); for($guesses=1; $guess!=$number; $guesses++, $guess=round($max-(($max-$min)/2))){ if($number<$guess) $max = $guess-1; else $min = $guess+1; } echo 'Computer guessed the number '.$number.' in '.$guesses.' guesses!<br>'; } ^ It can be done as simple as that. It doesn't verify the number, it just assumes it is between 0 and 999. You can do this instead if you want it to verify all data and be more dynamic: EDIT: I made it like it was request, between 1 and 1000. function computer_guesses($number, $min=1, $max=1000){ if($number>$max || $number<$min){ echo 'The number is too '.($number>$max ? 'large' : 'small').'.<br />'; } $guess = rand($min,$max); for($guesses=1; $guess!=$number; $guesses++, $guess=round($max-(($max-$min)/2))){ if($number<$guess) $max = $guess-1; else $min = $guess+1; } echo 'Computer guessed the number '.$number.' in '.$guesses.' guesses!<br>'; } if(!empty($_POST['guess']) && preg_match('/1000|[1-9][1-9]{1,2}|[1-9]{1}/', $_POST['guess'], $match)){ computer_guesses($match[0]); } ^ This one allows for the user to have typed in something else than just a number, but will only take the first valid number it finds.
  16. public function nameLength(){ return strlen($this->name); } or, but not recommended in many situations: public function getLength($var){ return strlen($this->{$var}); } first case to use: $person = new Person('dani33l_87'); echo $person->nameLength(); In the latter case to use: $person = new Person('dani33l_87'); echo $person->getLength('name');
  17. <?php // for test purposes only: set_time_limit(60); $_POST['guess'] = $_GET['guess']; function computer_guesses1($number){ $min = 0; $max = 999; $guess = round($max-(($max-$min)/2)); for($guesses=1; $guess!=$number; $guesses++, $guess=round($max-(($max-$min)/2))){ if($number<$guess) $max = $guess-1; else $min = $guess+1; } echo 'Computer guessed the number '.$number.' in '.$guesses.' guesses!<br>'; } function computer_guesses2($number){ $min = 0; $max = 999; $guess = rand($min,$max); for($guesses=1; $guess!=$number; $guesses++, $guess=rand($min,$max)){ if($number<$guess) $max = $guess-1; else $min = $guess+1; } echo 'Computer guessed the number '.$number.' in '.$guesses.' guesses!<br>'; } function computer_guesses3($number){ $min = 0; $max = 999; $guess = rand($min,$max); for($guesses=1; $guess!=$number; $guesses++, $guess=round($max-(($max-$min)/2))){ if($number<$guess) $max = $guess-1; else $min = $guess+1; } echo 'Computer guessed the number '.$number.' in '.$guesses.' guesses!<br>'; } function computer_guesses4($number){ $min = 0; $max = 999; $guess = round($max-(($max-$min)/2)); for($guesses=1; $guess!=$number; $guesses++, $guess=round($max-(($max-$min)/2))){ if($number<$guess) $max = $guess-1; else $min = $guess+1; } echo 'Computer guessed the number '.$number.' in '.$guesses.' guesses!<br>'; } function computer_guesses5($number){ $min = 0; $max = 999; $guess = rand(0,1) ? round($max-(($max-$min)/2)) : rand($min,$max); for($guesses=1; $guess!=$number; $guesses++, $guess=rand(0,1) ? round($max-(($max-$min)/2)) : rand($min,$max)){ if($number<$guess) $max = $guess-1; else $min = $guess+1; } echo 'Computer guessed the number '.$number.' in '.$guesses.' guesses!<br>'; } if(!empty($_POST['guess']) && preg_match('/[0-9]{1,3}/', $_POST['guess'], $match)){ $number = $match[0]; // for test purposes only: for($i=0; $i<1000; $i++){ computer_guesses1($i); } for($i=0; $i<1000; $i++){ computer_guesses2($i); } for($i=0; $i<1000; $i++){ computer_guesses3($i); } for($i=0; $i<1000; $i++){ computer_guesses4($i); } for($i=0; $i<1000; $i++){ computer_guesses5($i); } } ?> Just for fun... ;o But there are 5 different versions of basically the same script. What you asked for would be this one I think: function computer_guesses($number){ $min = 0; $max = 999; $guess = rand($min,$max); for($guesses=1; $guess!=$number; $guesses++, $guess=round($max-(($max-$min)/2))){ if($number<$guess) $max = $guess-1; else $min = $guess+1; } echo 'Computer guessed the number '.$number.' in '.$guesses.' guesses!<br>'; } if(!empty($_POST['guess']) && preg_match('/[0-9]{1,3}/', $_POST['guess'], $match)){ computer_guesses($match[0]); } When it comes to the user guessing the number. It must either be stored in a session/cookie or in a database (maybe file).
  18. What exactly do you want? Do you want to catch it so the user doesn't see it and you can write your own error? Read the manual: http://php.net/manua...n.ftp-login.php bool ftp_login ( resource $ftp_stream , string $username , string $password Return Values Returns TRUE on success or FALSE on failure. If login fails, PHP will also throw a warning. How to suppress error and warning in PHP: http://php.net/manua...rrorcontrol.php $logged_in = @ftp_login($ftp_stream, $username, $password); if(!$logged_in){ echo 'wasn\'t able to log in'; exit(); }
  19. PHP must be parsed server-side. It is not parsed by client. Why are you using PHP? ^ Should explain how it works. You use Javascript or HTML5 or something like that for client-side scripting. Things that the server decide and is dynamic etc can be done by for example PHP, or actually Java. http://en.wikipedia.org/wiki/Server-side_scripting
  20. I've done similar stuff many times. I don't have the time to help you now, lol, but payment for such an easy job would have been nice! xD http://forums.phpfreaks.com/topic/270290-tumblr-curl-not-working/ ^ Try to understand what I did there, and read the link to another similar case I've solved before. They are all solved the same way. You need to duplicate the way the website expects the web browser to act to achieve your goal. If you are not able to do it on your own, send me a pm or something.
  21. You can do it chunks at a time if you'd like. It could be a page that require some GET data to decide who to update, maybe a "password" to verify it's you it's the script that activated this update. Like this: http://www.example.com/updatescript.php?u=MMDE&pw=somesecretpw updatescript.php file: function update($username){ // your update script } function valid_user($username){ $valid_users = array('MMDE', 'far2slow'); if(in_array($username, $valid_users)) return true; return false; } if(!(!empty($_GET['pw']) && $_GET['pw']=='somesecretpw' && !empty($_GET['u']) && !valid_user($_GET['u']))) exit(); update($_GET['u']); You will need a script that loops through all of the users and visits the site with the appropriate get values in the url. I don't think you can use cURL for this, as it will wait for the responds and get that. You just want to initialize the connection. Another solution may also be to fork, but I'm not sure if it gets affected by time limit.
  22. set_time_limit($seconds); If you are going to do this very often, then I bet ms won't be too happy about it. I hope you cache the data and only update every x hour or so. While fetching the data you should be nice to the server, only send a request every x second. sleep($seconds); ^ That allows your script to sleep. Remember whenever you sleep you should make the time limit a bit larger. So basically you should create a function that will run after each fetch which adds the delay time and the extra time it takes for the new fetch.
  23. You should do the other way around, no need to search! $row['Sum8'] = "1b"; $grade_number=array("1a"=>3,"1b"=>2,"1c"=>1); // etc echo $grade_number[$row['Sum8']]; // should output 2 see that works just fine, eh? No need to search. You can do this too: <?php $row['Sum8'] = 'X'; if(is_numeric($row['Sum8'])){ $sum8_value = ($row['Sum8'][0]*3) - (ord($row['Sum8'][1])-97); }else{ $special_grades = array('X'=>25,'N'=>0,'-'=>2000,''=>2010); $sum8_value = $special_grades[$row['Sum8']]; } echo $sum8_value; ?> Or you can do what I really recommend, create a table for it in your MySQL database. How is it currently looking? We can probably help you make that smoother, and join these grade numbers, which is preferable, because PHP treats these types of "arrays" as hash tables.
  24. That whole if and elseif seems kinda stupid. In most cases the best solution would have been to do something like this: <?php $row['Sum8'] = '3c'; if($row['Sum8'][0]<22){ $sum8_value = ($row['Sum8'][0]*3) - (ord($row['Sum8'][1])-97); } echo $sum8_value; ?> But since your system doesn't seem to follow this all the way, I could recommend using an array like this: $values[8][$row['Sum8']]; ^ Yes and just used that all the time. Of course only if there is something special about row 8, if all rows are checked against the same values, simply do this instead: $values[$row['Sum8']]; $values array would contain all the various values and the key to the value would be the same as you check for in the if and else part of your code. Why is it called $row? Do you get it from a database? If that is the case, then you should store this in the database too, and instead of having to write all these if else stuff you could have had a fast db do it all for you dynamically. So easy to update and change. Usually you also don't need to make 8 variable names to store 8 different values, but keep them in an array and access them by their named key value. o.O If that makes any sense. Bottom line, use arrays, (maybe database) and write a proper functions.
  25. <?php @require_once('test'); echo 'hello world'; ?> require_once will only include the file once, and it will exit() the script if it is not able to include the file, at least that's my experience using it. So in this case, it would return "hello world" only if it finds and is able to include the file named "test". I also suppress the error, because you may not want to show that to the user. If you want to show a custom error message to the user: <?php $included = @include_once('test'); if(!$included){ echo 'was not able to include the file'; exit(); } ?>
×
×
  • 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.