cloudll
-
Posts
131 -
Joined
-
Last visited
Posts posted by cloudll
-
-
Hello,
I am comparing these 2 time stamps to see how much time has passed. They time passed is 66 seconds.
When I format them back into h:m:s, it shows 1 hour, 1 minute and 6 seconds instead of just 1 minute and 6 seconds.
I was just wondering why this was?
Thanks
$startStamp = 1487156507; $endStamp = 1487156573; $howLong = $endStamp - $startStamp; echo $howLong . "<br>"; echo(date("h:m:s",$howLong)) . "<br>";
-
Awesome, thanks guys.
So I am using it like this, is this okay?
$level = 1; $expNeeded = round(2.323 * pow($level, 3));
-
Hi guys. I'm using php to make a basic level up experience system.At the moment I'm using the following math.
$level = 1; //increments on level up
$constantValue = 150;
$level * $constantValue = $exp2level;Ideally I would like it to be a little more complicated so the exp needed to level isn't so predictable. Now, me and maths have never got along so I'm struggling.Is there a way I can generate exp results a little like FF7. Like this:Thanks for any tips
LEVEL 1: 0
LEVEL 2: 6
LEVEL 3: 33
LEVEL 4: 94
LEVEL 5: 202
LEVEL 6: 372
LEVEL 7: 616
LEVEL 8: 949
LEVEL 9: 1384
LEVEL 10: 1934
LEVEL 11: 2614
LEVEL 12: 3588
LEVEL 13: 4610
LEVEL 14: 5809
LEVEL 15: 7200
LEVEL 16: 8797
LEVEL 17: 10614
LEVEL 18: 12665
LEVEL 19: 14965
LEVEL 20: 17528
LEVEL 21: 20368
LEVEL 22: 24161
LEVEL 23: 27694
LEVEL 24: 31555
LEVEL 25: 35759
LEVEL 26: 40321
LEVEL 27: 45255
LEVEL 28: 50576
LEVEL 29: 56299
LEVEL 30: 62438
LEVEL 31: 69008
LEVEL 32: 77066
LEVEL 33: 84643
LEVEL 34: 92701
LEVEL 35: 101255
LEVEL 36: 110320
LEVEL 37: 119910
LEVEL 38: 130040
LEVEL 39: 140725
LEVEL 40: 151980
LEVEL 41: 163820
LEVEL 42: 176259
LEVEL 43: 189312
LEVEL 44: 202994
LEVEL 45: 217320
LEVEL 46: 232305
LEVEL 47: 247963
LEVEL 48: 264309
LEVEL 49: 281358
LEVEL 50: 299125
LEVEL 51: 317625
LEVEL 52: 336872
LEVEL 53: 356881
LEVEL 54: 377667
LEVEL 55: 399245
LEVEL 56: 421630
LEVEL 57: 444836
LEVEL 58: 468878
LEVEL 59: 493771
LEVEL 60: 519530
LEVEL 61: 546170
LEVEL 62: 581467
LEVEL 63: 610297
LEVEL 64: 640064
LEVEL 65: 670784
LEVEL 66: 702471
LEVEL 67: 735141
LEVEL 68: 768808
LEVEL 69: 803488
LEVEL 70: 839195
LEVEL 71: 875945
LEVEL 72: 913752
LEVEL 73: 952632
LEVEL 74: 992599
LEVEL 75: 1033669
LEVEL 76: 1075856
LEVEL 77: 1119176
LEVEL 78: 1163643
LEVEL 79: 1209273
LEVEL 80: 1256080
LEVEL 81: 1304080
LEVEL 82: 1389359
LEVEL 83: 1441133
LEVEL 84: 1494178
LEVEL 85: 1548509
LEVEL 86: 1604141
LEVEL 87: 1661090
LEVEL 88: 1719371
LEVEL 89: 1778999
LEVEL 90: 1839990
LEVEL 91: 1902360
LEVEL 92: 1966123
LEVEL 93: 2031295
LEVEL 94: 2097892
LEVEL 95: 2165929
LEVEL 96: 2235421
LEVEL 97: 2306384
LEVEL 98: 2378833
LEVEL 99: 2452783
-
Thanks for the help. I have never used switch/case/break before.
So would I need to name a new case for everypage I wanted to include?
-
I have a div on my site that is hidden on desktop then comes visable on mobile devices. Ideally I want to use the following code to include my content in both my normal content div, and my mobile div, and just have one showing at a time.
If I try to use it twice in my index.php page, the include default works but when I try to access a page it halts any content from loading.
Is there a way I can use this code twice in one page?<?php if (isset($_GET['nav'])) { if (strpos($_GET['nav'], "/")) { $direc = substr(str_replace('..', '', $_GET['nav']), 0, strpos($_GET['nav'], "/")) . "/"; $file = substr(strrchr($_GET['nav'], "/"), 1); if (file_exists($direc.$file.".php")) { include($direc.$file.".php"); } else { include("error.php"); } } else { if (file_exists(basename($_GET['nav']).".php")) { include(basename($_GET['nav']).".php"); } else { include("error.php"); } } } else { include("default.php"); } ?>
Thanks
-
I switched to time() and it all worked well, thanks
I plan to change it from sessions to a database, I just used sessions when testing it on my laptop.
I don't know why I thought I couldn't use that in the first place
Is there a way to make time() a little easier to read ?
-
I am trying to make a php timer of sorts. For a city building game web app.
I am using this code as a sort of time stamp but its very unreliable and jumpy.
When a player clicks on a building to build, it stores the following as a session variable:
$startTime = number_format($Time, 0, '.', '');
the to get the current time:
$Time = date("his");
then to see if the 30 second build time has passed I use:
if (isset($_SESSION['buildStart']) && ($Time - $_SESSION['buildStart'] > 30)) { built(); }
the rest of the code works fine, but sometimes the timer will jump from say 5 seconds to 25 seconds in an instant.
Does anyone have a more reliable way to check if the 30 seconds has passed?
Sorry if this is all crappy code, I am tryng to make this to get better
Edit: Oh, I don't think I can use time() because I am using the times to also make a progress bar:
-
Hey guys. I have this array:
$isValid = array (array(200,200), array(250,250), array(425,425) ); echo $isValid[1][0] . "<br />" . $isValid[1][1];
I tried to use array_rand but cannot get it working with more than one value. Is there a way I can randomly echo either:
200,200
250,250
or
425,425?
Thanks for any tips
-
Hey guys,
I am using this code to use javascript to send the browser window width to a php session variable.
session_start(); $parentDir = basename(dirname($_SERVER['PHP_SELF']));; if (!isset($_SESSION['screenWidth'])) { echo '<script>window.location = "' . "/" . $parentDir . "/" . '?width="+window.innerWidth</script>'; if (isset($_REQUEST['width'])) { $_SESSION['screenWidth'] = $_REQUEST['width']; header("Location: " . "http://" . $_SERVER['HTTP_HOST'] . "/" . $parentDir); } }
it works fine on my pc, however, when I try it on my phone it returns a width value of 900, which is wrong.
If i add the javascript directly it returns a true value of 350.
<button onclick="myFunction()">Get Width</button> <script> function myFunction() { alert(window.innerWidth); } </script>
I know this isn't just php but I was hoping someone would have any idea as to whats going on? Thanks for any help
EDIT: I uploaded a demo: http://www.myprimaryweb.co.uk/checkWidth/
-
Ah yes, I did mean ternary operator.
Ah ok that makes sense. Thank you.
-
Hey,
I have only recently learnt about using shorthand. I have managed to convert most of my simple if else's and isset checks to shorthand but am struggeling with a few.
Could someone show me how I would change this to shorthand, when it has two variables in the else.
if (isset($_SESSION['posY'])) { $posY = $_SESSION["posY"]; } else { $posY = 50; $_SESSION["posY"] = 50; }
Thanks
-
Hey guys,
I have this variable which i use to detect touchscreens and if i need to use touchstart or click.
var whatenemyTouch = isMobile ? 'touchstart' : 'click';
I am trying to use it with this:
window.onclick=function(e){
I would like to use it inplace of onclick but I cant get it working, any ideas?
Thanks
-
Use the datetime object, and this is pretty simple.
$date1 = new DateTime(); $date2 = date_create("2013-12-12"); $diff = date_diff($date1,$date2, true); echo $diff->format("%R%a days");
This works well to work out the difference Thanks. However I cant seem to echo $date1. Is this normal with datetime?
EDIT: Figured it out, my silly mistake
-
Hey,
I have been trying to tweak this code to tell me the days between the current date and a future date. The snippet below however sets a start date rather than using the current date.
I have been trying to format date() in a way that will work but have had no luck.
$date1=date_create("2013-03-15"); $date2=date_create("2013-12-12"); $diff=date_diff($date1,$date2); echo $diff->format("%R%a days");
Could someone tell me what I need to do to get it working please? Thank you.
-
The first example here is a nice starter into cookies.
-
Hey guys,
I was wondering if someone could tell me what I have done wrong here.
$sql = "SELECT * FROM login WHERE online='online' ORDER BY username"; $count = $sql->rowCount();
I dont know much, but shouldn't that work?
I get this message.
PHP Fatal error: Call to a member function rowCount() on a non-object in C:\wamp\www\engine\engine\engine-multi.php on line 2767
-
Got it, cheers.
-
Hey people. Firstly, sorry if my Topic Title is incorrect. I wasn't 100% sure how to word it.
In my code below, I have an if statement within an if statement.
I have an }else{ set for one of the ifs, but I would like an }else{ for the other one. I just cannot get it working. I have tried placing it everywhere I can think of.
Is it possible to have an else for this line
if (($attackverify == "yes") && ($status == "online"))
Here is my code.
<?php // HANDLE THE ATTACK if (($attackverify == "yes") && ($status == "online")) { if (!isset($_SESSION['LAST_ATTACK'])) { echo 'you attacked' . $decodedData; // ATTACK SQL QUERY GOES HERE $_SESSION['LAST_ATTACK'] = time(); // RELOAD THE PAGE AFTER ATTACK // reloadPage(); } elseif (isset($_SESSION['LAST_ATTACK']) && (time() - $_SESSION['LAST_ATTACK'] > 1)) { echo 'you attacked' . $decodedData; $_SESSION['LAST_ATTACK'] = time(); // ATTACK SQL QUERY GOES HERE // RELOAD THE PAGE AFTER ATTACK // reloadPage(); } else { // DISPLAY ERROR MESSAGE echo 'too soon to attack'; echo '<br />'; // SET SESSION echo $_SESSION['LAST_ATTACK']; echo '<br />'; // RELOAD THE PAGE AFTER ATTACK // reloadPage(); } } }
Thanks
-
Okay, this is what I came up with. It works but still lets the player attack other people by changing the information in the url bar. Is there any way to change this?
$username = null; if (isset($_REQUEST['username'])) { $username = $_REQUEST['username']; } $attackverify = null; if (isset($_REQUEST['attackverify'])) { $attackverify = $_REQUEST['attackverify']; } // SESSION USERNAME $sesusername = $_SESSION['auth']; // FIND ONLINE PLAYERS $sql = "SELECT * FROM login WHERE online='online'"; foreach($connect->query($sql) as $row) { $un = $row['username']; // CANNOT ATTACK YOURSELF if ($sesusername == $un) { echo <<<CODE // THIS CODE HAS NO ATTACK LINK <img style="position:absolute; top:{$row['pos_y']}px; left:{$row['pos_x']}px;" src="engine/img/{$row['username']}.gif"> <span style="left:{$nameposx}px;top:{$nameposy}px;color:#fff;position:absolute;">{$row['username']}</span> CODE; } else { // ATTACK THE ENEMY echo <<<CODE // THIS CODE DOES HAVE AN ATTACK LINK <a href="?attackverify=yes&username={$row['username']}"> <img style="position:absolute; top:{$row['pos_y']}px; left:{$row['pos_x']}px;" src="engine/img/{$row['username']}.gif"> </a> <span style="left:{$nameposx}px;top:{$nameposy}px;color:#fff;position:absolute;">{$row['username']}</span> CODE; } } // HANDLE THE ATTACK if ($attackverify == "yes") { echo 'you attacked' . $username; // ATTACK SQL QUERY GOES HERE // RELOAD THE PAGE AFTER ATTACK reloadPage(); } }
-
Awesome, thanks guys.
-
I was wondering if there is a way to link two arrays together. I currently have
$enemyNames = array("The Pain", "The Fear", "The End");
$enemyImage = array("img01", "img02", "img03");
I am then using array_rand to generate a random "enemy"
$enemyName = $enemyNames[array_rand($enemyNames)];
I would ideally like to have the first enemy name linked with img01, and the second linked to img02 etc. I am not sure how I would link them together while still using array_rand. Is it possible?
-
An okay, thanks. What would be the best way to pass the id variable, as part of the url? Or can it be done behind the scenes?
-
Hello,
I am working on a little multiplayer game. When a person logs in, a session is created storing their username and their character is set to "online" in the database. I then query my database and use for each to display all the characters who are set to "online" on the game map.
I'm not sure how I would go about letting the players attack each other. The attack can be used by just clicking on the other character, but I'm not sure how I would update the health in the database for the character who was attacked. does anyone have any ideas?
Sorry if this question is a bit vague, I'm confused myself.
Thanks for any tips.
-
Hey guys, this is probably a silly question but just wanted to check.
This is from the PHP manual for password_needs_rehash
if (password_needs_rehash($hash, PASSWORD_DEFAULT, $options)) { $newHash = password_hash($password, PASSWORD_DEFAULT, $options);
$options being the cost. I understand why the cost is being used for $newhash, but why is it being used for:
if (password_needs_rehash($hash, PASSWORD_DEFAULT, $options)) {
Is that actually doing anything?
timestamp showing hour which is not there
in PHP Coding Help
Posted
Thank you both for the link and example