Jump to content

QuickOldCar

Staff Alumni
  • Posts

    2,972
  • Joined

  • Last visited

  • Days Won

    28

Everything posted by QuickOldCar

  1. I suppose will mention can use a foreach instead of counting the array and building the for loop function plusmin ($tab) { $plus = 0; $min = 0; foreach ($tab as $key=>$value) { if ($tab[$key] > 0){ $plus++; } elseif ($tab[$key] < 0){ $min++; } } if ($plus > $min) { $result = "+1"; } elseif ($plus < $min) { $result = "-1"; } elseif ($plus == $min){ $result = "0"; } return $result; } And for something as simple as this can just loop the array and use it's value. function plusmin ($tab) { $plus = 0; $min = 0; foreach ($tab as $value) { if ($value > 0){ $plus++; } elseif ($value < 0){ $min++; } } if ($plus > $min) { $result = "+1"; } elseif ($plus < $min) { $result = "-1"; } elseif ($plus == $min){ $result = "0"; } return $result; }
  2. You could also loop for just less than $n value rather than less or equals $n function plusmin ($tab) { $n = count($tab); $plus = 0; $min = 0; for ($i = 0; $i < $n; $i++) { if ($tab[$i] > 0){ $plus++; } elseif ($tab[$i] < 0){ $min++; } } if ($plus > $min) { $result = "+1"; } elseif ($plus < $min) { $result = "-1"; } elseif ($plus == $min){ $result = "0"; } return $result; }
  3. function plusmin ($tab) { $n = (count($tab) -1);//this would be 0 to actual count in your loop, so deduct one, was adding extra $plus = 0; $min = 0; for ($i = 0; $i <= $n; $i++) { if ($tab[$i] > 0){ $plus++; } elseif ($tab[$i] < 0){ $min++; } } if ($plus > $min) { $result = "+1"; } elseif ($plus < $min) { $result = "-1"; } elseif ($plus == $min){ $result = "0"; } return $result; } Index key 10 does not exist
  4. I have a pretty good curl based scraper that I scrape both http and https sites.That link trying to connect to or even just the domain both return "Unable to fetch website". It's possible they are blocking any requests. There has been known issues with sslv3 due to security issues and some websites are wanting to use TLS instead. To make that matter worse there is issues with TLS in some curl versions. It's like a circle of getting nowhere with it unless use a known working curl version, I believe curl 7.19 for sure has a TLS issue. Here is something that could possibly help or not. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, 'TLSv1'); curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
  5. If you echo within it will echo wherever it was included, instead return the result and echo where using it. As for where it is displayed on a page, that is the job for css style, shouldn't use style in function results.
  6. Is a few things should consider doing so has no errors. first check if $_GET['page'] is actually set with isset() next would be to check if that php file exists you are including with is_file() or file_exists() if(isset($_GET['page'])){ $page = trim($_GET['page']); if(is_file($page.".php")){ include($page.".php"); } } You can further make an array of only the pages want to allow $allowed = array("home","about","contact","stats"); if(isset($_GET['page'])){ $page = trim($_GET['page']); if(in_array($page,$allowed)){ if(is_file($page.".php")){ include($page.".php"); } } } Can add any else statements you desire, such as always include home.php as the default page if page is not set in the url
  7. Possibly an encoding issue or formatting that browsers repair and smarty does not.
  8. While there are some specific website to cms importing tools, does not always obtain all the data.(but certainly worth trying first) This will go for any website to cms conversions. Not all websites are created the same, to complicate it more not all cms are created the same or store all types of data your old website may have had...such as special scripts or functions to do something special. The new cms would have to have a plugin or module similar to do the same job. The new cms needs to store the data the same way was originally intended, it's best to build specific queries and import it into tables related to either the new cms patterns or create new tables in the cms additionally. If that involves building a scraper to obtain your html/websites data so be it. What is also needed is the sites and users uploaded files if are still needed, that will have to be done to match the new as well. If is for a client and wants the same looks as had before, now are talking making a theme or modifying an existing theme for the new cms. Back on the topic of the import tools will see around, if you have many members and lots of data you will have to consider memory and timeout limitations of the server. I've been converting websites since the 90's and is not often 2 procedures are exactly the same. What always does work is to scrape the old site systematically and obtaining the needed data into an array or cvs formatted data so is useful for anything needed to be imported into the new site. That will also include creating folders and saving any files associated. If the old website is not that large, you are better off making new posts in the new cms using copy/paste. Most cms have categories and tag systems, pretty permalinks. Now is your chance to add additional information to an old article or page from an old html built website.
  9. You can also install virtualbox and something like ubuntu server Since is local can also make it a functional linux desktop by installing a gui, I use kubuntu sudo apt-get install kubuntu-desktop
  10. Happy to see you got something to work. Consider the users login and rights for future though, be much better.
  11. To expand onto Barand's to get first part back minus port. $ipport = "2001:db8:a0b:12f0::1:25"; $end = strrchr($ipport, ':'); $first = substr($ipport, 0, -strlen($end)); echo $first; //2001:db8:a0b:12f0::1 echo $end; //--> :25
  12. Seems to me can do all this by assigning individuals to a group and a permission level that group. In code you assign exactly which actions each permission each can do. user_id | group_id | permission_level
  13. Don't you now do specific rooms or do you have to create each room from the groupworld panel and then copy an html embed code for it? Let's say at groupworld you do have to create them in a panel first, then make yourself 10 rooms as they allow... 1-10 Now your urls can look like this site.com/classes/room/?number=3&instance=wskcub6729sjcd9f0so3 Use the $_GET['instance'] value and compare it the same as the code created by a teacher and see if allowed. If allowed use your $_GET['number'] value and echo it inside the groupworld chat embed code. If not allowed do not embed the chat and give a message. We aren't really here to help with 3rd party code, if they won't help you will need to hire someone that will know how to code this for you.
  14. You want to let them upload your script their server and expires? One thing have to understand is that anything you write the person can edit their php file. You can try obfuscation to make it harder, all it will take is one determined person to reverse it and share with the world for free. http://www.zend.com/en/products/zend-guard http://www.phpprotect.info/ You want something that has to check a domain or key, alternately a required snippet of code from your own server for their script to work. Let me say a few possible ways can do it. Creating an api system, you allow domain or private key usage for the script. Tracking domains your server, they download a copy of the same script(only one version needed), the script connects to your server to determine if allowed. Write into the code a key, when the script is accessed it looks for that key. The way it would find the key is connecting to your server and check for it a list however you wanted to save such keys.
  15. function update_password($uid, $password, $salt="") What you typed back just shows the parameters for the function, take a look in the function and see exactly how the salt and password are combined.
  16. Show the update_password() function so we can see how they are combining them to make the final hashed password.
  17. Your old saved md5 passwords in the database never had a salt, so adding a salt to new login will never be able to match. You need to email all users a temp link or password to log in with and have them set a new password that now includes the salt mysql_* functions are deprecated and should look into using mysqli_* or pdo md5 is not safe to use because attackers can use rainbow tables and possible to discover it, use password_hash and password_verify instead
  18. I also agree with mac_gyver, it's best to control the users who can access it. Your idea would allow students to share the link or someone could even possibly run a script or guess it. Yes need the file extensions as .php to parse php code or the server set up so .html can parse it as well. Url structures such as this would work site.com/classes/room/?instance=wskcub6729sjcd9f0so3 site.com/classes/room/index.php?instance=wskcub6729sjcd9f0so3 site.com/classes/room.php?instance=wskcub6729sjcd9f0so3 Even your method said should have a script with a form where teachers can create and delete the new rooms and stored in a database Something as simple as md5 of the time not that great, add a salt/word at minimum or some other value before md5 creation to make them harder to guess.
  19. Not sure why are making a php script expire, usually what is done is the url has parameters and is a dynamic script with different values. Something like using a database and checking a datetime for the value for insertion date would determine how old it was created. If you still want to make many php files and block access you would need to either include a script with code to all created pages or use dynamic page values that the script then includes. Use filetime, compare to see if modified date is older than last 7 days. If you stored all these files in a single folder, you can create a php script and create a cron job to run every day. The script would glob a folder and delete any files older than 7 days. Have your 404 error handling set up to either home page or a custom error page. This method would help keep your server cleaner and not have piles of files no longer needed. <?php $files = glob("/path/to/directory/*.php");//change to path you need $now = time(); foreach ($files as $file) { if (is_file($file)) { if ($now - filemtime($file) >= 60 * 60 * 24 * 7) { unlink($file); } } } ?>
  20. Here is something that can actually store them, I looped just 10,000 of them. I commented out the section for your loop and checking hue ranges. <?php /** * Convert a hexadecimal color in RGB * @param string $hex * @return array */ function hexToHsl($hex){ list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x"); return rgbToHsl($r, $g, $b); } /** * Convert a RGB color in its HSL value * @param int $r red * @param int $g green * @param int $b blue * @return array */ function rgbToHsl($r, $g, $b) { $r /= 255; $g /= 255; $b /= 255; $max = max($r, $g, $b); $min = min($r, $g, $b); $h = 0; $l = ($max + $min) / 2; $d = $max - $min; if ($d == 0) { $h = $s = 0; // achromatic } else { $s = $d / (1 - abs(2 * $l - 1)); switch ($max) { case $r: $h = 60 * fmod((($g - $b) / $d), 6); if ($b > $g) { $h += 360; } break; case $g: $h = 60 * (($b - $r) / $d + 2); break; case $b: $h = 60 * (($r - $g) / $d + 4); break; } } return array('h' => round($h, 2), 's' => round($s, 2), 'l' => round($l, 2)); } /* foreach ($colors as &$color) { $color['hsl'] = hexToHsl($color['color']); } usort($colors, function ($a, $b) { //Compare the hue when they are in the same "range" if(!huesAreinSameInterval($a['hsl']['h'],$b['hsl']['h'])){ if ($a['hsl']['h'] < $b['hsl']['h']) return -1; if ($a['hsl']['h'] > $b['hsl']['h']) return 1; } if ($a['hsl']['l'] < $b['hsl']['l']) return 1; if ($a['hsl']['l'] > $b['hsl']['l']) return -1; if ($a['hsl']['s'] < $b['hsl']['s']) return -1; if ($a['hsl']['s'] > $b['hsl']['s']) return 1; return 0; }); */ /** * Check if two hues are in the same given interval * @param float $hue1 * @param float $hue2 * @param int $interval * @return bool */ function huesAreinSameInterval($hue1, $hue2, $interval = 30){ return (round(($hue1 / $interval), 0, PHP_ROUND_HALF_DOWN) === round(($hue2 / $interval), 0, PHP_ROUND_HALF_DOWN)); } function hex2RGB($hexStr, $returnAsString = false, $seperator = ',') { $hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string $rgbArray = array(); if (strlen($hexStr) == 6) { //If a proper hex code, convert using bitwise operation. No overhead... faster $colorVal = hexdec($hexStr); $rgbArray['red'] = 0xFF & ($colorVal >> 0x10); $rgbArray['green'] = 0xFF & ($colorVal >> 0x8); $rgbArray['blue'] = 0xFF & $colorVal; } elseif (strlen($hexStr) == 3) { //if shorthand notation, need some string manipulations $rgbArray['red'] = hexdec(str_repeat(substr($hexStr, 0, 1), 2)); $rgbArray['green'] = hexdec(str_repeat(substr($hexStr, 1, 1), 2)); $rgbArray['blue'] = hexdec(str_repeat(substr($hexStr, 2, 1), 2)); } else { return false; //Invalid hex color code } return $returnAsString ? implode($seperator, $rgbArray) : $rgbArray; // returns the rgb string or the associative array } //hex2RGB("#FF0") -> array( red =>255, green => 255, blue => 0) //hex2RGB("#FFFF00) -> Same as above //hex2RGB("#FF0", true) -> 255,255,0 //hex2RGB("#FF0", true, ":") -> 255:255:0 $array = array(); //16777215 for all combinations for($i = 0; $i <= 10000; $i++) { $hex = sprintf('%06s', dechex($i)); $rgb = hex2RGB("#$hex", true); $hsl = hexToHsl("#$hex"); $rgb_colors = explode(",",$rgb); $array[] = array("rgb"=>$rgb,"rgbarray"=>array("r"=>$rgb_colors[0],"g"=>$rgb_colors[1],"b"=>$rgb_colors[2]),"hex"=>$hex,"hsl"=>$hsl); } echo "<pre>"; print_r($array); echo "</pre>"; ?> Returns data as so... Array ( [0] => Array ( [rgb] => 0,0,0 [rgbarray] => Array ( [r] => 0 [g] => 0 => 0 ) [hex] => 000000 [hsl] => Array ( [h] => 0 => 0 [l] => 0 ) ) [1] => Array ( [rgb] => 0,0,1 [rgbarray] => Array ( [r] => 0 [g] => 0 => 1 ) [hex] => 000001 [hsl] => Array ( [h] => 240 => 1 [l] => 0 ) ) [2] => Array ( [rgb] => 0,0,2 [rgbarray] => Array ( [r] => 0 [g] => 0 => 2 ) [hex] => 000002 [hsl] => Array ( [h] => 240 => 1 [l] => 0 ) ) [3] => Array ( [rgb] => 0,0,3 [rgbarray] => Array ( [r] => 0 [g] => 0 => 3 ) [hex] => 000003 [hsl] => Array ( [h] => 240 => 1 [l] => 0.01 ) ) [4] => Array ( [rgb] => 0,0,4 [rgbarray] => Array ( [r] => 0 [g] => 0 => 4 ) [hex] => 000004 [hsl] => Array ( [h] => 240 => 1 [l] => 0.01 ) )
  21. Somewhere in my old files I did this. I created arrays with range() using 0-255 rgb values for every combination (16,777,216 possible color values), then conversions for 3 and 6 digit hex. You can create this and save as an associative array, even better a database. So your server doesn't puke...probably better off making 3 variables and cycle in chunks as groups to save into a database. Like 0,0,0 to 255,255,255
  22. I'll be blunt, your code is old and bad. Not many are willing to make it for you...just help with specific problems within your code. Try this link and will be a better start for you. https://daveismyname.com/login-and-registration-system-with-php-bp
  23. This may help you. https://www.gravityhelp.com/documentation/article/gform_after_submission/
  24. Always look for a feed or api first before attempting to scrape it yourself. http://developer.cbssports.com/documentation/api/files/sports
  25. Don't forget to trim() the input, will fail the validation due to whitespace.
×
×
  • 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.