PHP - Help W/age Validation & Local Storage
I am trying to do age validation for a beverage site, and losing my mind. First time trying local storage (to persist across browser sessions) and I assume I have something screwed up. Anyone able to help me figure out how to make this work? <?php if( isset( $_POST['yes'] ) ) { localStorage.setItem('age_verification', 'true'); if( isset( $_GET['url'] ) ) { die( header('Location: ' . $_GET['url'] ) ); } else { die( header('Location: index.php') ); } } elseif( isset( $_POST['no'] ) ) { localStorage.setItem('age_verification', 'false'); } var age_verification = localStorage.getItem('age_verification'); //new if (age_verification = "false" || age_verification = "null") die( header('Location: http://www.bing.com') ); ?> Above is the code for the file checkagenew.php which I call from other pages using the below: <?php if (localStorage.age_verification) { localStorage.setItem('age_verification', 'null'); } var age_verification = localStorage.getItem('age_verification'); if (age_verification = "false" || age_verification = "null") die( header("Location: checkagenew.php?url=http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]") ); ?> Obviously there is a form included in the top part (not shown) that has a submit for yes/no which triggers the $_POST validation... I did not include that for brevity. Similar TutorialsI'm busy with a small storage system for my site, but i encounter some problems with it. I have successfully managed to get all products from the order, and traced on what spots those product are in the warehouse. It looks like this atm http://img37.imageshack.us/img37/7302/tableordereng.jpg this is the code i have atm (sorry i program in dutch, i hope its abit understandable) Code: [Select] <?php $query = "select * from `orderregel` WHERE `ordernr`='".$ordernr."'"; $row = mysql_fetch_array( $query ); echo "<table border=1 width=680 bgcolor=#FFFFFF> <tr> <th width= 100>artikelnummer</th> <th width= 100>productnaam</th> <th width= 40>Plaats</th> <th width= 40>aantal in magazijn</th> <th width= 40>aantal nodig</th> </tr> </table>"; foreach ( self::find_by_sql($query) as $user) { $query2 = "select * from magazijn WHERE artikelnr = ".$user->artikelnr.""; $row = mysql_fetch_array( $query ); foreach ( self::find_by_sql($query2) as $magazijn) { echo "<table class= order_overzicht border= 0 width= 680>"; echo "<tr> <td width= 100>".$magazijn->artikelnr."</td> <td width= 100>".$magazijn->productnaam."</td> <td width= 40>".$magazijn->magazijn_plaats."</td> <td width= 40>".$magazijn->aantal."</td> <td width= 40>".$user->aantal."</td> </tr> </table>"; } } ?> The problem i have now is, that i want it to do the following. for example someone orders 430 packages of Haribo Kers Cola (see imageshack upload). I first want it to empty spot 16 in the wherehouse. Only when spot 16 is empty, i want it to go to the next spot (19) wich contains the same product. the end result would be something like this: http://img690.imageshack.us/img690/6246/tableorderneweng.jpg i hope you guys can help me out on this one, becouse i have no clue how i can resolve this problem thanks in advance (Sorry btw for my bad english ) Hi, What is a good way to store passwords using php and postgresql and what columns/column types do I need to do so? I've got a table 'users' I've tried to find a straight forward answer but am confused by 'salting' etc. Thanks My users table on my forum is what gets checked everytime a user refreshes to authentic them.
When killing a monster, I want users to be able to grab items and it will insert them into their inventory. I have this part done already. But I want them to have a plethora of loot available that drops from a mob, and once they click the specific item it will then be inserted into their inventory (server database).
I'm storing the Temporary Item Data in a PHP session variable. Once they kill a monster, the Tempory Item Data variable get's filled with the specific loot and then the user will have the option to choose what items they want to go into their inventory.
My problem is, if they open the game in a new browser they will get a new session id. Since I'm authenticating them through my users table, can I just make a new column called session_id and just use php's session_id() before every session start so no matter which browser they're on they will have the same session right?
You might think, well why dont you just store the temporary item data in a mysql field or rows instead? I want to try to minimize mysql usage as much as possible, as players will be CLICKING a lot to kill mobs, it is most likely very mysql demanding as well and I want to be intuitive about it. I just want to use temporary session data for the loot. Then once the user clicks an item they want, it is EXTRACTED from their tempory item data variable, then I will use MYSQL to insert those items into their inventory.
Is this a fair and intuitive way to do temporary data for item loot? For example, in action RPG's like Path of Exile you kill a group of mobs and you see a shit ton of loot on the floor. (I imagine that loot is just temporary waiting for someone to pick it up right?) Once you do pick it up, mysql is then called to save it right? That's the same logic I have with my web based game. Is using a session variable to store that temporay loot.
Is this an intuitive way to do this, or are there other ways?
Edited by Monkuar, 24 November 2014 - 01:24 AM. Just curious, how would you go about rendering and storing this in a database. For example a simple small maze.
With each keypress, the user is moved up,down,left,right like 1 inch. (1 block). Which is easy to do with jquery, etc. But how would go about storing the data in a databse (can update the position per update or using websockets), but essentially so maphacks are impossible and everything is saved/read from the server.
Would the storage data be something like [0,0,0,1,0,0,1,1,1,1,0,1] I imagine or what?
Edited by Monkuar, 01 December 2014 - 09:32 PM. Before reading: I already have a system in place for inventory management. I use it with a rpg_items database with a field called 'item_slot', etc and it works wonderfully. My issue is. I think it would be intuitive if I were to store a basic 20 slot 0 iteration in a field under the users table for each character. So I can just check against that, instead of querying the whole rpg_user_items table, (which will have thousands, hundreds of thousands of users items) to just check if a user's inventory is full, that is not intuitive. I'd rather just check if a field name has no open 0's instead with php. (This ofcourse will be updated dynamically upon a user moving their items to different slots). Let's say I have this array, and it's stored in a field called userinventory in the users table: 0,0,0,0,0 0,0,0,0,0 0,0,0,0,0 0,0,0,0,0This is pretty easy to read. there is 20 slots, 5 on reach row. That's 20 inventory slots a user has access to. This is supposed to represent something like this: I can store this in the MYSQL field as 'userinventory'. Now, how do I go about dynamically each specific 0 (ZERO) in this Block? I'm going to call this a block. I will need to label it accordingly. Paint time. Here u go How do I use PHP to dynamically update a block like this based upon user input? (A 1, A 2, A3, B2, B1, etc) To check if a user's inventory is full would be easy. I can just explode them by ',' and use count to see if it's greater than 20. My problem is about updating each individual block to represent a users inventory. So, if there is a 1 there, an item would be there. That's all I'm trying to do. I could ofcourse, create what 20 (5x4) if functions to place them at each individual block, but that wouldn't be intuitive and be extremely confusing. Edited by Monkuar, 23 January 2015 - 09:08 PM. Hey guys, I'm trying to build a simple 'blogging engine' as a fun side project. At the moment i'm mainly having trouble with 2 things - 1. What is the best way that the administrator can input the data (with linebreaks, etc) and then have it stored in the database with this formatting so that when it is called from the database, it shows up the same on the page? 2. How do i go about selecting only certain posts from the database? I have tried doing a /post.php?id=12 and then an SQL statement "WHERE post_id=" . $id (in the correct formatting, of course) but this didnt seem to work. Any help would be appreciated. -CynePhoba after authenticating username and password,i have a parameter like: $_SESSION['logged']=1 should i be storing this as a cookie?..if yes, then can anyone modify cookie, to have this parameter as "1", and gain access? I would like to use an external API, and access it with my 2nd IP address of the server. Is this possible? And if so, how? Example: primary ip: 4.5.6.7 secondary ip: 4.5.6.8 primary ip is used to host several websites the PHP script I made runs in CLI, I want it to access the external API from my secondary ip. Thanks! Hi ppl I have a weird error... (or at least i think its weird) I have a project with 3 forms, and at the end(the last file) will enter all data of this form in an email and sent it using PEAR smtp email. On my local server it works. Everything - from testing all the mandatory fields in each form till the sending of the email. I also receive the email using @localhost. When I upload these files to the server, every form with the testing of the mandatory fields and returning to that form, everything works, except the file where I test the last form and put all content in the email body. On the server, as soon as the last page starts to load, I get a Server Error HTTP Error 500. I really don't understand it, as everything works on my local xampp server. Please let me know of places I can search for errors... like log files on the server or something like that. Thanks PS: I also used NetBeans, with its debugger, so I am quite sure its not the code, maybe a php setting... Hi, What is the best way to print the local date and time, my website have customers from 4 or 5 countries. Saudi - UTC+3 Dubai - UTC+4 India - UTC+5.30 how to print the local time for them Thanks, Hi everyone, The website I am working on is http://teemagroup.com/puyafolder and I have a global navigation with a drop down menu. What I want to do is on the right side have a PHP code to pull sub-pages under the drop down menu that its in. I don't quite know how to write it. For example everything under "Client Services" would go on the right side of that page. You know, to make it locally available instead of a drop down. And this code would work with all other pages. It would just pull what's under that page. I've added some files for you if you need it. This is done in wordpress if you wanted to know. Hey! I'm trying to use a local server to test my site out. I'm using dreamweaver for all the coding. I installed WAMP server and have the local host working. When I preview the site, it really is messed up. For example, if I have this code: Code: [Select] <? /** * Main.php * * This is an example of the main page of a website. Here * users will be able to login. However, like on most sites * the login form doesn't just have to be on the main page, * but re-appear on subsequent pages, depending on whether * the user has logged in or not. * * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) * Last Updated: August 26, 2004 */ include("include/session.php"); ?> <table> <tr><td> <? /** * User has already logged in, so display relavent links, including * a link to the admin center if the user is an administrator. */ if($session->logged_in){ echo "<h1>Logged In</h1>"; echo "Welcome <b>$session->username</b>, you are logged in. <br><br>" ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] " ."[<a href=\"useredit.php\">Edit Account</a>] "; if($session->isAdmin()){ echo "[<a href=\"admin/admin.php\">Admin Center</a>] "; } echo "[<a href=\"process.php\">Logout</a>]"; } else{ ?> <h3>Login</h3> <? /** * User not logged in, display the login form. * If user has already tried to login, but errors were * found, display the total number of errors. * If errors occurred, they will be displayed. */ if($form->num_errors > 0){ echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>"; } ?> <form action="process.php" method="POST"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr> <tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>> <font size="2">Remember me next time <input type="hidden" name="sublogin" value="1"> <input type="submit" value="Login"></td></tr> <tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr> <tr><td colspan="2" align="left"><br>Not registered? <a href="register.php">Sign-Up!</a></td></tr> </table> </form> <? } /** * Just a little page footer, tells how many registered members * there are, how many users currently logged in and viewing site, * and how many guests viewing site. Active users are displayed, * with link to their user information. */ echo "</td></tr><tr><td align=\"center\"><br><br>"; echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>"; echo "There are $database->num_active_users registered members and "; echo "$database->num_active_guests guests viewing the site.<br><br>"; include("include/view_active.php"); ?> </td></tr> </table> I get this: Code: [Select] logged_in){ echo " Logged In "; echo "Welcome $session->username, you are logged in. " ."[username\">My Account] " ."[Edit Account] "; if($session->isAdmin()){ echo "[Admin Center] "; } echo "[Logout]"; } else{ ?> Login num_errors > 0){ echo "".$form->num_errors." error(s) found"; } ?> Username: "> error("user"); ?> Password: "> error("pass"); ?> value("remember") != ""){ echo "checked"; } ?>> Remember me next time [Forgot Password?] Not registered? Sign-Up! "; echo "Member Total: ".$database->getNumMembers()." "; echo "There are $database->num_active_users registered members and "; echo "$database->num_active_guests guests viewing the site. "; include("include/view_active.php"); ?> To me, it seems like a " problem but I don't see why it would be happening. Hello, I am having a heck of a time trying to get time right on my website lol When a user logs in, they select what timezone they are in (UTC -1,-2,-3,-4,-5,-6....) Now this is great an all, but with daylight savings time my times are off by one hour in either direction. How do sites like this get times to work for users so easily? Thanks! weee im wondering is there any easy way to echo server time and local time... without converting them from unix to timestamp i have found thi code, but i cant tell is it server or local Code: [Select] echo date("H:i" ,time()); Hey all, this is my first post ever and am not really sure if this is the right place for it or not, sorry in advance if it isn't. I'm new to PHP and trying to learn. I'm running Ubuntu 10.04 LTS and Firefox 3.6.22. I have libapache2-mod-php5 installed and running, but for some reason everytime I try to open a local .php file in firefox the download manager pops up and ask me what I want to do with the file. Has anyone else encountered this before? Is it something simple that I overlooked? Any help would be appreciated. I am trying to get local date/time. In my php file I am setting my timezone using $timezone = "America/Toronto"; putenv ('TZ=' . $timezone); Then I use the following to get current date and time print_r (getdate()); but my date displays in GMT, What am I doing wrong? As in the code above I am in Toronto and I need EST. Hey, I'm trying to code a page which is supposed to bring up the time of a person's computer. Is this possible without majorly complicated coding? I'm good with GMT offsets and stuff but I don't know how to get the time of a person's computer. I don't want other stuff, just the time so I can edit the time based on where they are. I don't know if I'm making sense so here's an example... If someone does a forum post at 2pm Sydney time but it's 5pm Perth time. How can I make it so that someone in Perth sees 5pm but someone in Sydney sees 2pm...without them manually telling me their timezone? I read about using IP addresses but don't know much (Ok anything) about this , any hints or good sites to view would be appreciated? Or the answer if it's not too complex. Preferably I'd like to get the time in the 11 digit "time()" format so I can use it in tables and translate it with an existing function. IceKat Hi all, Something that pretty much always seems to bother me when i write something for someone else is that the include path's for some reason are screwed up. Now i thought let's look in phpinfo to see what the path is: So i get the following: Local value: .:/usr/lib/php:/usr/local/lib/php:/home/godzilla4361/php Master value: .:/usr/lib/php:/usr/local/lib/php Now which one is used for what? I just can't find a way to create a way to easily transport scripts from server to server, because i always have to manually adjust the path for inclusion otherwise i get those warning: failed to open stream etc. Anyone with tips and or advice and maybe even knows what to use those local and master values for? Hi Guys,
I'm actually a .net programmer, but was asked by a local company to make some improvements / add new features to an internal web app they use to help them manage their project pipeline.
I've been working with them for about a year and learning PHP as I go along. The site was originally built in house by a keen programming hobbyist so between him and me the code is probably a bit non-standard.
I'm looking for an experienced PHPer (with the usual web dev addons: JS/JQuery, CSS, HTML, MYSQL) who would be interested in putting in some hours/days to help move the thing along and happy to pay £150/day or equivalent hours if preferred.
The project is in a Git Repository on Kiln (owned by FogCreek, who do Fogbugz if you've heard of that) but I could move it to GitHub no probs. Current dev site is hosted on Vidahost.
Thanks,
Fergus
Hello all, I'm a PHP newbie, so please pardon me if this question has already been asked somewhere in this forum. I have been reading the PHP documentation. On this page http://www.php.net/manual/en/language.references.pass.php, I came across this code: <?php ... snip ... function &bar() { $a = 5; return $a; } foo(bar()); ?> This is returning a reference to local variable $a. Coming from a C/C++ background, my intuition tells me this just shouldn't work, since the local variable $a should be deleted as soon as the function "bar" returns. The code seems to work, though. My guess is that PHP is basically ref-counting and garbage collecting local variables like $a, and so it will not be automatically cleaned up on call exit. Is this about right? Thanks! WN |