Jump to content

jodunno

Members
  • Posts

    321
  • Joined

  • Last visited

  • Days Won

    5

Everything posted by jodunno

  1. so you haven't replied in weeks . I assume based upon your post that you just want to remove the loading bar and display successfully loaded message, yes? <html> <head> <title>5 sec div</title> <style> @keyframes loading { from { opacity: 1; } to { opacity: 1; visibility: hidden; } } @keyframes loaded { from {opacity: 0;} to {opacity: 0;} } .loadingbar { max-width: 100px; border: solid 1px #c0c0c0; } .loading { animation: 5s linear loading; opacity: 0; } .loaded { animation: 5s linear loaded; } .load { position: absolute; top: 0 px; left: 0 px; padding: 8 px; } </style> </head> <body> <div class="load loading loadingbar">Loading ...</div> <div class="load loaded">Successfully Loaded</div> </body> </html>
  2. I did some research last night and i stumbled across grid path algorithms in connection with grid games, which could help you determine a path. Mathematicians have created these algorithms so there is no need for us to re-invent the wheel. http://qiao.github.io/PathFinding.js/visual/ so you must decide if you want to use a path algorithm or if you want to use the tile numbers (re-invent the wheel) to calculate with basic arithmetic (neighbors would require more calculation to avoid misplacing traps and blocking a valid path). i've set up the grid with random start and goal nodes which can be passed to an algorithm (which requires adding this code to the grid build and display code) <?php // Grid settings $maxColumns = (int) 3; $maxRows = (int) 4; if ($maxColumns < 3 || $maxColumns > 10 || $maxRows < 3 || $maxRows > 10) { //screen width must be a factor print 'Please change your mapsize'; exit; } // Images (Icons) $iconMonster = '&#129430;'; // Shows a dinosaur $iconTreasure = '&#127873;'; // Shows a gift $monsters = ceil($maxRows * $maxColumns * 0.15); $treasures = floor($maxRows * $maxColumns * 0.25); $svgSize = 100; $fontSize = $svgSize * 2; // Build the full grid with all information $grid = array(); $displayGridArray = (int) 1; $paths = array(); $trapSize = ceil(($maxColumns * $maxRows) / $maxRows - 1); $availableTiles = $maxColumns * $maxRows - ($trapSize + 2); //create random start and goal nodes $nodes = array(); $nodes['start']['icon'] = '&#128578'; $nodes['start']['row'] = mt_rand(1, $maxRows); $nodes['start']['column'] = mt_rand(1, $maxColumns); $nodes['goal']['icon'] = '&#128274'; $nodes['goal']['row'] = mt_rand(1, $maxRows); $nodes['goal']['column'] = mt_rand(1, $maxColumns); while ($nodes['goal']['column'] === $nodes['start']['column']) { $nodes['goal']['column'] = mt_rand(1, $maxColumns); } //build and display the grid $tileCounter = 0; for ($i = 1; $i <= $maxRows; $i++) { for ($j = 1; $j <= $maxColumns; $j++) { $tileCounter++; $grid[$i][$j]['tile'] = $tileCounter; $grid[$i][$j]['exits'] = null; $image = '<svg width="'.$svgSize.'px" height="'.$svgSize.'px" fill="#333" xmlns="http://www.w3.org/2000/svg">'.PHP_EOL; $image .= '<title>tile: '.$grid[$i][$j]['tile'].'&#xA;row: '.$i.'&#xA;column: '.$j.'</title><rect width="80%" height="80%" x="10%" y="10%" rx="5%" ry="5%" />'.PHP_EOL; // Center square if ($i === $nodes['start']['row'] && $j === $nodes['start']['column']) { $image .= '<text x="50%" y="50% "textLength="100%" font-size="'.$fontSize.'%" dominant-baseline="middle" text-anchor="middle">'.$nodes['start']['icon'].'</text>'.PHP_EOL; } if ($i === $nodes['goal']['row'] && $j === $nodes['goal']['column']) { $image .= '<text x="50%" y="50% "textLength="100%" font-size="'.$fontSize.'%" dominant-baseline="middle" text-anchor="middle">'.$nodes['goal']['icon'].'</text>'.PHP_EOL; } if ($i > 1 && $i <= $maxRows) { /* north,top */ $grid[$i][$j]['exits'] .= 'north'; $image .= '<rect width="20%" height="10%" x="40%" y="0%" />'.PHP_EOL; } if ($j > 1 && $j <= $maxColumns) { /* west,left */ $grid[$i][$j]['exits'] .= (!empty($grid[$i][$j]['exits']) ? ', ' : '') . 'west'; $image .= '<rect width="10%" height="20%" x="0%" y="40%" />'.PHP_EOL; } if ($i < $maxRows) { /* south,bottom */ $grid[$i][$j]['exits'] .= (!empty($grid[$i][$j]['exits']) ? ', ' : '') . 'south'; $image .= '<rect width="20%" height="100%" x="40%" y="90%" />'.PHP_EOL; } if ($j < $maxColumns) { /* east,right */ $grid[$i][$j]['exits'] .= (!empty($grid[$i][$j]['exits']) ? ', ' : '') . 'east'; $image .= '<rect width="10%" height="20%" x="90%" y="40%" />'.PHP_EOL; } $image .= '</svg>'; echo $image; } echo '<br>'.PHP_EOL; } if ($displayGridArray) { echo '<p>'; $k = 1; foreach ($grid as $row => $association) { $l = 1; foreach ($association as $column => $data) { echo 'row ' . $k . ', column ' . $l; foreach ($data as $label => $info) { echo ', ' . $label . ': ' . $info; } echo '<br>'; $l++; } $k++; } echo '</p>'; } echo 'total tiles: ' . $tileCounter . '<br>'; echo 'start node: ' . $nodes['start']['row'] . ':' . $nodes['start']['column'] . ' tile ' . $grid[$nodes['start']['row']][$nodes['start']['column']]['tile'] . '<br>'; echo 'goal node: ' . $nodes['goal']['row'] . ':' . $nodes['goal']['column'] . ' tile ' . $grid[$nodes['goal']['row']][$nodes['goal']['column']]['tile'] . '<br>'; echo 'traps: ' . $trapSize . '<br>'; echo 'available tiles = ' . $availableTiles . ' (minus traps, start and goal nodes)<br>'; ?> now you just have to place the monsters and treasures into columns not belonging to start and goal nodes, calculate a path or possible paths, place traps not interfering with atleast one valid path from start to goal and remove the exits that create the traps.. i also created a variable for displaying the grid array for development purposes. let us know if you have problems finishing the code.
  3. I'm trying to build this program myself in spare time but i out of time for now. I have added the "doors" and documented them in the array. <?php // Grid settings $gridWidth = 3; $gridHeight = 4; $svgSize = 100; // Images (Icons) $iconExit = '&#128274;'; // Shows a lock $iconMonster = '&#129430;'; // Shows a dinosaur $iconStart = '&#128578;'; // Shows a smiley $iconTreasure = '&#127873;'; // Shows a gift // Calculate Monsters $monsters = ceil($gridHeight * $gridWidth * 0.15); // Calculate Treasures $treasures = floor($gridHeight * $gridWidth * 0.25); // Make iconBox and shuffleBox $iconBox = array_merge( array_fill(1, $treasures, $iconTreasure), array(1 => $iconExit), array_fill(1, $monsters, $iconMonster), array(1 => $iconStart) ); $shuffleBox = $iconBox; shuffle($shuffleBox); /* Build the full grid with all information ///////////////////////////////////////////////*/ $grid = array(); for ($i = 1; $i <= $gridHeight; $i++) { for ($j = 1; $j <= $gridWidth; $j++) { $grid[$i][$j]['top'] = $grid[$i][$j]['left'] = $grid[$i][$j]['bottom'] = $grid[$i][$j]['right'] = 0; $image = '<svg width="'.$svgSize.'px" height="'.$svgSize.'px" fill="#333" xmlns="http://www.w3.org/2000/svg">'.PHP_EOL; $image .= '<rect width="80%" height="80%" x="10%" y="10%" rx="5%" ry="5%" />'.PHP_EOL; // Center square if ($i > 1 && $i <= $gridHeight) { /* top */ $grid[$i][$j]['top'] = 1; $image .= ' ' . '<rect width="20%" height="10%" x="40%" y="0%" />'.PHP_EOL; } if ($j > 1 && $j <= $gridWidth) { /* left */ $grid[$i][$j]['left'] = 1; $image .= ' ' . '<rect width="10%" height="20%" x="0%" y="40%" />'.PHP_EOL; } if ($i < $gridHeight) { /* bottom */ $grid[$i][$j]['bottom'] = 1; $image .= ' ' . '<rect width="20%" height="100%" x="40%" y="90%" />'.PHP_EOL; } if ($j < $gridWidth) { /* right */ $grid[$i][$j]['right'] = 1; $image .= ' ' . '<rect width="10%" height="20%" x="90%" y="40%" />'.PHP_EOL; } $image .= '</svg>'; echo $image; } echo '<br>'; } //echo '<br>'; print_r($grid); //echo '<br><br>'; $k = 1; foreach ($grid as $row => $association) { $l = 1; foreach ($association as $column => $connection) { foreach ($connection as $door => $status) { echo 'row ' . $k . ', column ' . $l . ', ' . $door . ' door: ' . $status . '<br>'; } $l++; } $k++; echo '<br>'; } ?> Now you just need to think of a path algorithm which needs documented coordinates. Once you have a path, that doesn't involve randomly disabling doors which require checking for broken paths, you can then loop over the necessary connections to disable them as well as display the surprise items. I've removed a few unnecessary variables and comments from the code. I'll try to wok on a path algorithm along side of your path algorithm ideas and we'll see if we can solve your problems. Unless, someone else beats us to it...
  4. I wonder why you do not want to build a grid and cut a path at the same time as well as build an array to track the grid. You could easily create the grid and a grid array in one fell swoop. <?php // Grid settings $gridWidth = 5; $gridHeight = 5; $svgSize = 100; $svgColor = '#333'; $svg['center'] = '<rect width="80%" height="80%" x="10%" y="10%" rx="5%" ry="5%" />'; // Images (Icons) $iconExit = '&#128274;'; // Shows a lock $iconMonster = '&#129430;'; // Shows a dinosaur $iconStart = '&#128578;'; // Shows a smiley $iconTreasure = '&#127873;'; // Shows a gift // Calculate Monsters $monsters = ceil($gridHeight * $gridWidth * 0.15); // Calculate Treasures $treasures = floor($gridHeight * $gridWidth * 0.25); // Make iconBox and shuffleBox $iconBox = array_merge( array_fill(1, $treasures, $iconTreasure), array(1 => $iconExit), array_fill(1, $monsters, $iconMonster), array(1 => $iconStart) ); $shuffleBox = $iconBox; shuffle($shuffleBox); // Build the full grid with all information $grid = array(); for ($i = 1; $i <= $gridHeight; $i++) { for ($j = 1; $j <= $gridWidth; $j++) { $grid[$i][$j] = 'content'; $image = '<svg width="'.$svgSize.'px" height="'.$svgSize.'px" fill="'.$svgColor.'" xmlns="http://www.w3.org/2000/svg">'.PHP_EOL; $image .= ' '.$svg['center'].PHP_EOL; // Center square $image .= '</svg>'; // Close SVG echo $image; // Show image } echo '<br>'; } //echo '<br>'; print_r($grid); //echo '<br><br>'; $k = 1; foreach ($grid as $row => $association) { $l = 1; foreach ($association as $column => $data) { echo 'row ' . $k . ', column ' . $l . ': ' . $data . '<br>'; $l++; } $k++; echo '<br>'; } ?> your code seems to contradict the doors because the doors are not being used in anyway other than creating paths around a random maze. I think that this is somewhat like the old Atari game Haunted House (one of my favs.) Anyway, you could write a make path algorithm and build the doors from there, which would now only be bottom or right. I think that you are overthinking. Even better is to use mathematics to design the grid and path but it is not necessary.
  5. I thought that you wanted every square to be connected, which is what i changed. I looked at your code again and i see what you are doing: the smiley is the start and the lock is the exit. The walking in a circle is doors that should be broken but all columns should not have four doors. Still, i wouldn't program it this way but it's your code. we get a better view of what is happening when we print the contents of your field array. Take a look at the array, if you have time. take a closer look at yourcheck each field = connected code. echo '<br><br>'; foreach ($field as $row => $colArr) { foreach ($colArr as $col => $door) { echo '<table cellspacing="2" cellpadding="2" border="1" width="400"><tr><td bgcolor="#f0f0f0" width="100">row</td><td bgcolor="#f0f0f0" width="100">col</td><td bgcolor="#f0f0f0" width="100">door</td><td bgcolor="#f0f0f0" width="100">content</td></tr>'; foreach ($door as $direction => $content) { //echo 'row: ' . $row . ', col: ' . $col . ', door: ' . $position . ', item: ' . $item . '<br>'; echo '<tr><td>' . $row . '</td><td>' . $col . '</td><td>' . $direction . '</td><td>' . $content . '</td></tr>'; } echo '</table>'; } } echo '<br><br>'; where is the text 'content' coming from in this array? i have yet to locate the source. meantime, row -1 is curious since that would be row 0 and there is not a row 0 (for row = 1).
  6. I have tested the original script with my border control hack and the grid is complete without other changes to your script. Hopefully, this tweak solves your problems. complete script with border hack and comment around the hack.: <?php // Start Sessie //session_start(); // Map settings $mapWidth = 5; $mapHeight = 5; $squareSize = 70; $squareColor = '#333'; // Content settings $monster = '&#129430;'; $treasure = '&#127873;'; $start = '&#128578;'; $exit = '&#128274;'; // Make SVG files $fontSize = $squareSize * 2; $svg['center'] = '<rect width="80%" height="80%" x="10%" y="10%" rx="5%" ry="5%" />'; $svg['right'] = '<rect width="10%" height="20%" x="90%" y="40%" />'; $svg['bottom'] = '<rect width="20%" height="10%" x="40%" y="90%" />'; $svg['left'] = '<rect width="10%" height="20%" x="0" y="40%" />'; $svg['top'] = '<rect width="20%" height="10%" x="40%" y="0%" />'; // Function to count the values in a field function count_values($arr) { $counting = 0; foreach ($arr as $key => $val) { if (is_numeric($val)) { $counting = $counting + $val; } } return $counting; } // Calculate Monsters $monsters = ceil($mapHeight * $mapWidth * 0.16); // Calculate Chests $chests = floor($mapHeight * $mapWidth * 0.24); // Check map size if ($monsters == 0 || $chests == 0 || ($monsters + $chests + 2) > ($mapHeight * $mapWidth)) { print 'Please change your mapsize'; exit; } // Create content $squareChests = array_fill(1, $chests, 'treasure'); $squareMonsters = array_fill(1, $monsters, 'monster'); $squareStart = array(1 => 'start'); $squareEnd = array(1 => 'exit'); // Merge and mix all content $fillbox = array_merge($squareChests, $squareMonsters, $squareStart, $squareEnd); shuffle($fillbox); /******************************\ Start Grid Map \******************************/ // Build column for ($row=1; $row<=$mapHeight; $row++) { // Build row for ($col=1; $col<=$mapWidth; $col++) { $randomSquare = array(); while (count_values($randomSquare) < 1) { // Default settings $squareMaxTop = 1; $squareMaxLeft = 1; $squareMaxBottom = 1; $squareMaxRight = 1; // Top row has never a door at top if ($row == 1){ $squareMaxTop = 0; } // First column has never a door at left if ($col == 1){ $squareMaxLeft = 0; } // Last row has never a door at the bottom if ($row == $mapHeight){ $squareMaxBottom = 0; } // Last column has never a door at the right if ($col == $mapWidth){ $squareMaxRight = 0; } $randomSquare = array( 'top' => rand(0, $squareMaxTop), 'right' => rand(0, $squareMaxRight), 'bottom' => rand(0, $squareMaxBottom), 'left' => rand(0, $squareMaxLeft), ); } $field[$row][$col] = $randomSquare; } } /******************************\ Check each field = connected \******************************/ foreach ($field as $row => $colArr) { foreach ($colArr as $col => $door) { // Check top door is connected with previous top field $previousTop = $row - 1; $field[$previousTop][$col] = isset($field[$previousTop][$col]) ? $field[$previousTop][$col] : NULL; if ($field[$previousTop][$col] != NULL) { $field[$row][$col]['top'] = $field[$previousTop][$col]['bottom']; if (count_values($field[$row][$col]) < 1) { $field[$row][$col]['top'] = 1; $field[$previousTop][$col]['bottom'] = 1; } } else { unset($field[$previousTop]); } // Check right door is connected with next right field $nextRight = $col + 1; $field[$row][$nextRight] = isset($field[$row][$nextRight]) ? $field[$row][$nextRight] : NULL; if ($field[$row][$nextRight] != NULL) { $field[$row][$col]['right'] = $field[$row][$nextRight]['left']; if (count_values($field[$row][$col]) < 1) { $field[$row][$col]['right'] = 1; $field[$row][$nextRight]['left'] = 1; } } else { unset($field[$row][$nextRight]); } // Check bottom door is connected with next bottom field $nextBottom = $row + 1; $field[$nextBottom][$col] = isset($field[$nextBottom][$col]) ? $field[$nextBottom][$col] : NULL; if ($field[$nextBottom][$col] != NULL) { $field[$row][$col]['bottom'] = $field[$nextBottom][$col]['top']; if (count_values($field[$row][$col]) < 1) { $field[$row][$col]['bottom'] = 1; $field[$nextBottom][$col]['top'] = 1; } } else { unset($field[$nextBottom]); } // Check left door is connected with previous left field $previousLeft = $col - 1; $field[$row][$previousLeft] = isset($field[$row][$previousLeft]) ? $field[$row][$previousLeft] : NULL; if ($field[$row][$previousLeft] != NULL) { $field[$row][$col]['left'] = $field[$row][$previousLeft]['right']; if (count_values($field[$row][$col]) < 1) { $field[$row][$col]['left'] = 1; $field[$row][$previousLeft]['right'] = 1; } } else { unset($field[$row][$previousLeft]); } // Give dead end always a monster / treasure / Start or Exit if (count_values($field[$row][$col]) == 1 && count($fillbox) > 0) { $field[$row][$col]['content'] = $fillbox[0]; array_shift($fillbox); } else { $field[$row][$col]['content'] = ''; } } } /**************************************************\ Check broken paths If broken path, add entry to random field in broken path \**************************************************/ // How to do ????? /**************************************************\ Check walking circles If circle, remove one entry from random field in cicle path \**************************************************/ // How to do ????? // Set leftover content to random fields while (count($fillbox) > 0) { $x = rand(1, $mapHeight); $y = rand(1, $mapWidth); if ($field[$x][$y]['content'] == '') { $field[$x][$y]['content'] = $fillbox[0]; array_shift($fillbox); } } /******************************\ Show grid \******************************/ foreach ($field as $rowKey => $rowArr) { foreach ($rowArr as $colKey => $colArr) { // Create and show image SVG $image = '<svg width="'.$squareSize.'px" height="'.$squareSize.'px" fill="'.$squareColor.'" xmlns="http://www.w3.org/2000/svg">'.PHP_EOL; $image .= ' '.$svg['center'].PHP_EOL; // Center square // The doors edit: border control happens here. so essentially, the broken paths are created here with your original code. if ($rowKey == 1) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['top'].PHP_EOL; } if ($colKey == 1) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['left'].PHP_EOL; } if ($rowKey == 5) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['bottom'].PHP_EOL; } if ($colKey == 5) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['right'].PHP_EOL; } // the above code closes the doors around the grid (borders) but does not break the other doors. // The text (content) $text = ''; if ($colArr['content'] == 'monster'){ $text = $monster; } if ($colArr['content'] == 'treasure'){ $text = $treasure; } if ($colArr['content'] == 'start'){ $text = $start; } if ($colArr['content'] == 'exit'){ $text = $exit; } $image .= ' <text x="50%" y="50% "textLength="100%" font-size="'.$fontSize.'%" dominant-baseline="middle" text-anchor="middle">'.$text.'</text>'.PHP_EOL; $image .= '</svg>'; // Close SVG print $image; // Show image } print '<br>'; // Next row } ?>
  7. i had some time to find the errors in your logic which control the borders, so i tweaked your code to complete the 'grid'. <?php // Start Sessie //session_start(); // Map settings $mapWidth = 5; $mapHeight = 5; $squareSize = 70; $squareColor = '#333'; // Content settings $monster = '&#129430;'; $treasure = '&#127873;'; $start = '&#128578;'; $exit = '&#128274;'; // Make SVG files $fontSize = $squareSize * 2; $svg['center'] = '<rect width="80%" height="80%" x="10%" y="10%" rx="5%" ry="5%" />'; $svg['right'] = '<rect width="10%" height="20%" x="90%" y="40%" />'; $svg['bottom'] = '<rect width="20%" height="10%" x="40%" y="90%" />'; $svg['left'] = '<rect width="10%" height="20%" x="0" y="40%" />'; $svg['top'] = '<rect width="20%" height="10%" x="40%" y="0%" />'; // Function to count the values in a field function count_values($arr) { $counting = 0; foreach ($arr as $key => $val) { if (is_numeric($val)) { $counting = $counting + $val; } } return $counting; } // Calculate Monsters $monsters = ceil($mapHeight * $mapWidth * 0.16); // Calculate Chests $chests = floor($mapHeight * $mapWidth * 0.24); // Check map size if ($monsters == 0 || $chests == 0 || ($monsters + $chests + 2) > ($mapHeight * $mapWidth)) { print 'Please change your mapsize'; exit; } // Create content $squareChests = array_fill(1, $chests, 'treasure'); $squareMonsters = array_fill(1, $monsters, 'monster'); $squareStart = array(1 => 'start'); $squareEnd = array(1 => 'exit'); // Merge and mix all content $fillbox = array_merge($squareChests, $squareMonsters, $squareStart, $squareEnd); shuffle($fillbox); /******************************\ Start Grid Map \******************************/ $squareMaxTop = 1; $squareMaxLeft = 1; $squareMaxBottom = 1; $squareMaxRight = 1; // Build column for ($row=1; $row<=$mapHeight; $row++) { // Build row for ($col=1; $col<=$mapWidth; $col++) { $randomSquare = array(); while (count_values($randomSquare) < 4) { $randomSquare = array( 'top' => rand(0, $squareMaxTop), 'right' => rand(0, $squareMaxRight), 'bottom' => rand(0, $squareMaxBottom), 'left' => rand(0, $squareMaxLeft), ); } $field[$row][$col] = $randomSquare; } } /******************************\ Show grid \******************************/ foreach ($field as $rowKey => $rowArr) { foreach ($rowArr as $colKey => $colArr) { // Create and show image SVG $image = '<svg width="'.$squareSize.'px" height="'.$squareSize.'px" fill="'.$squareColor.'" xmlns="http://www.w3.org/2000/svg">'.PHP_EOL; $image .= ' '.$svg['center'].PHP_EOL; // Center square // The doors if ($rowKey == 1) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['top'].PHP_EOL; } if ($colKey == 1) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['left'].PHP_EOL; } if ($rowKey == 5) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['bottom'].PHP_EOL; } if ($colKey == 5) { $image .= ' '.PHP_EOL; } else { $image .= ' '.$svg['right'].PHP_EOL; } // The text (content) $text = ''; $image .= ' <text x="50%" y="50% "textLength="100%" font-size="'.$fontSize.'%" dominant-baseline="middle" text-anchor="middle">'.$text.'</text>'.PHP_EOL; $image .= '</svg>'; // Close SVG print $image; // Show image } print '<br>'; // Next row } ?> if you run the script, you will see a complete grid with all of the fields connected without border paths. I would not code a grid like this but it is your script. I hacked the code to make it work as you suggest (unless i have misinterpreted your request.)
  8. the code is doing what you have instructed it to do: create at least one door. Shouldn't you create at least 4 doors? the logic is a problem. Let's hack the script and see what happens. /******************************\ Start Grid Map \******************************/ $squareMaxTop = 1; $squareMaxLeft = 1; $squareMaxBottom = 1; $squareMaxRight = 1; // Build column for ($row=1; $row<=$mapHeight; $row++) { // Build row for ($col=1; $col<=$mapWidth; $col++) { // Default settings makes no difference here // Create random square with at least 1 door $randomSquare = array(); while (count_values($randomSquare) < 4) { $randomSquare = array( 'top' => rand(0, $squareMaxTop), 'right' => rand(0, $squareMaxRight), 'bottom' => rand(0, $squareMaxBottom), 'left' => rand(0, $squareMaxLeft), ); } $field[$row][$col] = $randomSquare; } } You need to re-examine the border control (doors at edges) and tweak the code to include 4 doors/paths.
  9. is this your code and design or are you using someone elses code and design? valid user ids as query strings is insecure and, frankly, stupid. if you wrote the code, then i suggest a rewrite is in order. do you pass a user id query string to every page as a method of validating a logged in user? ranklist should simply use the user id in the database to query results for the valid logged-in user. you would need to rewrite your code to utilize a proper log in script and check the database each page request (shared hosting). if you have a dedicated host then use a session variable to flag a logged in user but still check the database at each page request. nota bene: if the current user is not permitted to view another user's page, then this is simply access control and you should slap yo'self for posting this question. if user_id query not equal to user_id then not permitted to view. In other words, if user_id !== user_id query McFly? Hello, McFly? try not to search the internet for solutions because you may stumble across a "pretty uri" Apache rewrite proposal, which is not pretty and it is an awful patch for even more awful design methods. Any use of Apache rewrite is alot like saying "pretend [that] you didn't see that", so silly and resource consuming. i have no idea what "ranklist" is displaying and i don't really care but it could effect resolutions. if there is a particular reason why you cannot just use a db query to control access, then you are left with patching the code. if the current user is able to view this current user id associated data, then you could use a session variable instead. However, if all of the users id associated data is accessible to a user, then this would be too many session variables used to replace ids. use a session variable with a random get_id string id as key and user_id as value check if isset session variable $_SERVER['QUERY_STRING'] (not $_GET['id']), which is now random get_id string, then display the user_id associated results. the real id is associated with the random get_id string (= key/value) you could also use a database instead of a session variable. at login, generate a random string and insert it into the user table column, named (for example) hide_user_id then, you could use that temporarily valid id instead of a session variable. query the db when loading ranklist and retrieve the correct user id to display the asociated data using this hide_user_id in the query. just be certain that the hide_user_id column has a unique constraint applied. just use your noggin and create a patch until you can rewrite the code correctly. Best Wishes, Biff.
  10. @Barand You, Sir, are a veteran professional programmer and it always shows in your posts. Me, on the other hand, i am more of a hacker that is slowly learning from pros. Your code is a beautiful example of a well designed form and form processing script. Bravo! Hopefully, the OP can see the beauty of your work and follow this lead. Meantime, your "Judicious application of array key names" is a perfect example of how i can use this concept in future designs. I have copied this code to a text file for future reference. Pros can easily illustrate its usefulness. Thank you for educating me on this subject . Point well noted 🙂 edit: Dear Barand, please change the following sentence "Job Done." to "Job Well Done."
  11. I did not consider that someone may see my post and not understand that the code posted is just an example of how to detect empty of this array. I hope that viewers understand to escape the output after validation (code not included). I should have used the following code in my post to avoid security problems: foreach ($_POST['subquestion'] as $value) { echo htmlentities($value, ENT_QUOTES, 'UTF-8') . '<br>'; } my code sample is not a valid solution to be applied online, rather in a testing environment.
  12. I have no idea why you are using inline style to hide inputs. Are you trying to implement a rogue type="hidden" format? Makes no sense, none at all. Meantime, the subquestion array in this form will never be empty because the keys will be sent in the post (with empty values). You could hack a bit to force detection but this just illustrates that your code is sloppy and unorthodox. I suggest that you read more about html forms and structures of forms. You could make a new post in the html subforum here at phpfreaks. So to show you how subquestions could be handled, i have spent a few minutes creating a script with your messy code that i had to format in addition to hacking. Here is a working attempt to detect empty or not empty and display the results. If all values are empty then the subquestion has not been populated with values, otherwise the values will be shown. For the record, i am not a fan of form input arrays. <?php declare (strict_types = 1); switch ($_SERVER['REQUEST_METHOD']) { case 'GET': ?> <form autocomplete="off" method="post"> <label for="question">Sub Question <span class="req">*</span></label> <textarea cols="46" rows="3" name="subquestion[]" placeholder="Enter Sub question here.."></textarea> <div class="divider "></div> <div class="divider"></div> <textarea class="opt_text opt_text0 " cols="46" rows="2" name="choice0[]" placeholder="Enter Choice A here.." style="display: none;"></textarea> <label for="image" class="opt_img opt_img0" style="display: none;">Add Choice A Image(if any..)</label> <input type="file" class="opt_img opt_img0" name="o-image0[]" style="display: none;"><br><br> <textarea class="opt_text opt_text0 " cols="46" rows="2" name="choice0[]" placeholder="Enter Choice B here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img0" style="display: none;">Add Choice B Image(if any..)</label> <input type="file" class="opt_img opt_img0" name="o-image0[]" style="display: none;"><br><br> <textarea class="opt_text opt_text0 " cols="46" rows="2" name="choice0[]" placeholder="Enter Choice C here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img0 " style="display: none;">Add Choice C Image(if any..)</label> <input type="file" class="opt_img opt_img0" name="o-image0[]" style="display: none;"> <br><br> <textarea class="opt_text opt_text0 " cols="46" rows="2" name="choice0[]" placeholder="Enter Choice D here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img0" style="display: none;">Add Choice D Image(if any..)</label> <input type="file" class="opt_img opt_img0" name="o-image0[]" style="display: none;"> <li><label for="question">Sub Question <span class="req">*</span></label> <textarea cols="46" rows="3" name="subquestion[]" placeholder="Enter Sub question here.."> </textarea> <div class="divider "></div> <div class="divider"></div> <textarea class="opt_text opt_text1 " cols="46" rows="2" name="choice1[]" placeholder="Enter Choice A here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img1" style="display: none;">Add Choice A Image(if any..)</label> <input type="file" class="opt_img opt_img1" name="o-image1[]" style="display: none;"><br><br> <textarea class="opt_text opt_text1 " cols="46" rows="2" name="choice1[]" placeholder="Enter Choice B here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img1" style="display: none;">Add Choice B Image(if any..)</label> <input type="file" class="opt_img opt_img1" name="o-image1[]" style="display: none;"><br><br> <textarea class="opt_text opt_text1 " cols="46" rows="2" name="choice1[]" placeholder="Enter Choice C here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img1 " style="display: none;">Add Choice C Image(if any..)</label> <input type="file" class="opt_img opt_img1" name="o-image1[]" style="display: none;"> <br><br> <textarea class="opt_text opt_text1 " cols="46" rows="2" name="choice1[]" placeholder="Enter Choice D here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img1" style="display: none;">Add Choice D Image(if any..)</label> <input type="file" class="opt_img opt_img1" name="o-image1[]" style="display: none;"> <li><label for="question">Sub Question <span class="req">*</span></label> <textarea cols="46" rows="3" name="subquestion[]" placeholder="Enter Sub question here.."> </textarea> <div class="divider "></div> <div class="divider"></div> <textarea class="opt_text opt_text2 " cols="46" rows="2" name="choice2[]" placeholder="Enter Choice A here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img2" style="display: none;">Add Choice A Image(if any..)</label> <input type="file" class="opt_img opt_img2" name="o-image2[]" style="display: none;"><br><br> <textarea class="opt_text opt_text2 " cols="46" rows="2" name="choice2[]" placeholder="Enter Choice B here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img2" style="display: none;">Add Choice B Image(if any..)</label> <input type="file" class="opt_img opt_img2" name="o-image2[]" style="display: none;"><br><br> <textarea class="opt_text opt_text2 " cols="46" rows="2" name="choice2[]" placeholder="Enter Choice C here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img2 " style="display: none;">Add Choice C Image(if any..)</label> <input type="file" class="opt_img opt_img2" name="o-image2[]" style="display: none;"> <br><br> <textarea class="opt_text opt_text2 " cols="46" rows="2" name="choice2[]" placeholder="Enter Choice D here.." style="display: none;"> </textarea> <label for="image" class="opt_img opt_img2" style="display: none;">Add Choice D Image(if any..)</label> <input type="file" class="opt_img opt_img2" name="o-image2[]" style="display: none;"></li> <input type="submit"> </form> <?php break; case 'POST': $countQuestions = count($_POST['subquestion']); $checkEmpty = 0; foreach ($_POST['subquestion'] as $value) { if (empty($value)) { $checkEmpty++; } } if ($checkEmpty === $countQuestions) { echo 'subquestion is empty'; break; } foreach ($_POST['subquestion'] as $value) { echo $value . '<br>'; } break; default: echo 'Request Method denied'; break; } ?> Hopefully you can create a cleaner, nicer form and process the form correctly. phpfreaks has lots of professionals that can help you when you have problems along the way. I suggest that if you continue using arrays, then atleast provide keys that can be checked for empty.
  13. @gizmola I am just trying to be helpful. No need to thank me, my friend. I was going to reply to this thread with similar code to your code but mac_gyver beat me to it. Best wishes.
  14. Do not come here looking for handouts, then insult my friends for not providing free labor. So far as i can see, you have two answers that will solve your immediate problems. Update your code with the provided answers, then feel ashamed for your behavior. Meantime, shell games with variables serves no purpose here: $password=$_POST['password']; $dec_password=$password; focus on adding an exit after a redirect: $_SESSION['id']=$num['id']; $_SESSION['name']=$num['fname']; header("location:welcome.php"); exit; and including authorized and password columns in your query: $ret= mysqli_query($con,"SELECT id, fname, password, authorized FROM users WHERE email='$useremail'"); Yeah Glo!
  15. adding to Sir Barand's statements: if you cannot figure out the JavaScript code or you're too lazy to try, then you could use CSS 3 with animations which will show and hide a span inside your div. I wonder, exactly how do you plan to fit the words "Successfully Loaded" into a 10 pixel div?
  16. servers (like apache) and php have max size limits. You are trying to set a max size variable in addition to these restrictions. You will get content-length warnings regardless and POST should be empty or someone is just sending post requests to your script not using your image upload form. You are making it complicated. if (empty($_FILES['Upload']) || !empty($_FILES['Upload']['error']) && $_FILES['Upload']['error'] === 4) { //content-length warning. redirect to get } if (!is_string($_FILES['Upload']['tmp_name']) || count($_FILES) > 1) { //more than one file has been sent } if (!in_array(strtolower(pathinfo($_FILES['Upload']['name'], PATHINFO_EXTENSION)), ['jpe','jpeg','jpg','png'], true)) { //not 'jpe','jpeg','jpg','png' }
  17. once you follow the advice of this forums experts to solve your problem, you should definitely upgrade php and your code. I'm trying to be helpful and i hope that you take this advice, since your code has security issues involved. so working off of the same input names $_POST['uname'] and $_POST['pword'], you could easily switch to pdo: $dbHost = '127.0.0.1'; $dbName = 'iew'; $dbUser = 'root'; $dbPass = ''; $dbAttr = array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $dbConn = new PDO("mysql:host=$dbHost; dbname=$dbName; charset=utf8mb4", $dbUser, $dbPass, $dbAttr); $query = 'SELECT * FROM inno_school_staff WHERE uname = :PostUser'; $iew = $dbConn->prepare($query); $iew->execute(array(':PostUser' => $_POST['uname'])); $row = $iew->fetch(); keep in mind that you need to adjust the $dbHost, $dbName, $dbUser, and $dbPass variables to suit your working environment. now, you can load your session variables the same as before but we switched to pdo. $_SESSION['staff']['uname'] = $row['uname']; $_SESSION['staff']['fname'] = $row['fname']; $_SESSION['staff']['lname'] = $row['lname']; $_SESSION['staff']['type'] = $row['type']; $_SESSION['staff']['school'] = $row['school_name']; $_SESSION['staff']['email'] = $row['email']; $_SESSION['value_m'] = $row['value_m']; $_SESSION['value_p'] = $row['value_p']; $_SESSION['value_d'] = $row['value_d']; $_SESSION['value_b'] = $row['value_b']; however, i recommend that you hash user passwords before storing them in the database. example php script to show how this works: $formPass = "joDunn02024"; $showHash = password_hash($formPass, PASSWORD_BCRYPT); echo $showHash; Then, you can verify passwords without plaintext security issues: if (password_verify($_POST['pword'], $row['pword'])) { /* user passwords match */ } Meantime, your sessions could be intermittent if they are not properly coded. I've had this happen to me when i first started working with sessions. Even if you were to find a patch to make your site function again, it does not excuse the fact that you need to update your code and programming methods. This forum has professional programmers that can help you with any upgrade issues. I recommend that you try to update your code. Best wishes to you and i hope that you solve your problems soon.
  18. admin_authenticate.php has some issues that should be noted: Regarding headers already sent, I do not see the opening html and head tags in your code, so i am assuming that you have placed them before start of session. to quote the php manual: To use cookie-based sessions, session_start() must be called before outputting anything to the browser. session_start() should be placed before any output to a browser (including html and head tags). I have no idea as to why you wouldn't have had problems before now. if ($destino == 1){print "<META HTTP-EQUIV=\"Refresh\" content=\"1;URL=admin_panels.php\">";} else {print "<META HTTP-EQUIV=\"Refresh\" content=\"1;URL=admin_panels.php\">";} the else should be different from the if branch, otherwise it doesn't make sense to me. Both uris point to admin_panels.php. Furthermore, you have a meta tag placed outside of the head element and outside of the html element. it seems as though you should be showing more code than what you have posted as well. For example, what is the php code in r_open_link.php and r_declaration.php? where is the opening html and head tags? in another php file? database gurus are going to trip over that db code laying in the middle of the floor... probably switching to pdo is a good place to begin again.
  19. Post/Redirect/Get (PRG) is effective against Content-Length warnings (not visible due to the redirect) Which version of php are you using? i've tried the script on my xampp with php version 8 and only images are accepted. However, you have the acceptable image array typed twice in your script, as well as the size variable. Why even use a variable (memory consumption)? !in_array($file_extension_pp, ["png","jpg","jpeg"])
  20. just to clarify: i mean that you could build an array with name and age as keys and just loop over the data. $multi2 = array(); $multi2['name'][] = $steven['name']; $multi2['name'][] = $jason['name']; $multi2['age'][] = $steven['age']; $multi2['age'][] = $jason['age']; print_r($multi2);
  21. why not add the arrays using the assignment operator (=)? array_push doesn't do what you want for reasons that i have forgotten. You could read the manual for a better explanation anyway. I do something similar in my nature/biology website: $multi = array(); $steven = array("name" => "Steven", "age" => 34); $jason = array("name" => "Jason", "age" => 32); $multi[] = $steven; print_r($multi); echo '<br>'; $multi[] = $jason; print_r($multi); the only problem with this method is that the multi array has its own numbered keys, thus it is now a multidimensional array. So you would need to loop over the multi array with this in mind. maybe this helps? wait for other better answers from more experienced programmers.
  22. common mistake, actually. Happens to everyone somewhere along the line. However, ignoring Barand's advice is probably more of a stupid mistake because it is more efficient and logical. function GetColour($Balls, $Ball) { return in_array($Ball, $Balls) ? '#0000ff': '#c53ba1'; } echo GetColour([01, 03, 27, 38, 48, 07, 12], 27) . ' = 27<br>'; echo GetColour([01, 03, 27, 38, 48, 07, 12], 73) . ' = 73'; sorry, folks: As an American born person, I prefer the stars and stripes spelling of color[-s] over the French spelling. It drives me nuts sometimes. I can excuse the British Barand but knock it off already. 🙂 LOL Honestly. Barand is a pro and that is some good pro advice for you to follow.
  23. I want to add a notice for everyone using xampp on Windows in case someone is unaware of this vulnerability. one can read more details, for example, in the link below provided by Google News https://www.bleepingcomputer.com/news/security/php-fixes-critical-rce-flaw-impacting-all-versions-for-windows/ please update your versions of php and xampp (whenever a fix is provided). have a nice day, friends 🙂
      • 1
      • Thanks
  24. "CAN'T PHP ADD 3 STUPID SIMPLE NUMBERS!???!???" ChenXiu, seriously? you have never heard of precision before? and the output of total is not "wrong, wrong, wrong", it is a product of the mathemaical process known as rounded up. PHP, as mentioned by the always helpful Requinix, is not the only programming language that is problematic with precision. The reasons lie beyond the scope of this forum but an additional tip is that even microprocessors have limitations. Maybe you have money for a supercomputer? And fractions are not 'simple' numbers by definition and they have no brains to be 'stupid' or smart for that matter. Just poking at you a bit (making fun but not being disrespectful). anyway, bcadd will help but now you may have to add additional code to determine fractions (30.50) from integers within the array, unless you intend to maintain the same format (id est: add two integers, then add a fraction to that total.) <?php $total = 0; $numbers = array( '9780393872439', '9780134130422', '30.50' ); $integers = strval($numbers[0] + $numbers[1]); $total = bcadd($integers, $numbers[2], 2); echo $total; ?> maybe you can make use of bcadd and be satisfied. But keep in mind that you will have mathematical problems with most programming languages and software restraints do not help either.
×
×
  • 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.