Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 i think the cookie should have the players data and the npcs data i would think i could be wrong Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-708993 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 Now before we can do anything you need to backtrack and find where the cookie is set - looks like it'll be in another script somewhere BUT... as I said earlier, you're not accessing it. Â You could fill it with some junk at the start of the script just to test but if that cookie is empty chances are the rest are also empty which is why you need to back track - Maybe start the whole site again so it is defined? Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-708994 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 you mean i have to start my game over from the beginning? is there another way i could create this battle script without having to start all over again?? Â oh is this what you wanted to see for the cookie?? Â echo "3"; Â $UserSQuery = mysql_query("SELECT * FROM `users` WHERE username='$username'"); Â $UserS = mysql_fetch_array($UserSQuery); Â $NPCSQuery = mysql_query("SELECT * FROM `npc` WHERE npcname='$NPC'"); Â $NPCS = mysql_fetch_array($NPCSQuery); Â setcookie('NPC', $NPC, 2400); Â setcookie('health', $UserS['health'], 2400); Â setcookie('skill', $UserS['skill'], 2400); Â setcookie('NPCH', $NPCS['health'], 2400); Â } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-708995 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 No, just "mentally" read through the other scripts and see what data is being set inside the cookies - I'm thinking they've "expired" while you were writing some code, easy mistake to make. Â I see you're writing a game so you'll have a few scripts - I don't know what they are so I can't say what ones you need to check. Are they set when a user logs in? Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-708996 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 yea i have a cookie created for when the user logs in would it help to see that script too? Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-708998 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 The issue is not the cookie but how you are setting it.  setcookie  Set it with all the values, domain (make sure it is either domain.com or www.domain.com) and a "/" for the directory. Doing that should set the cookie properly.  You are only setting the time, value and name, nothing else. This can cause issues on some/most servers. Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-708999 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 I'd prefer to use sessions instead - I've never touched cookies and don't know how to use them. Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709002 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 I'd prefer to use sessions instead - I've never touched cookies and don't know how to use them. Â I would agree, but without him re-doing the script to use sessions instead, this should solve the problem until he decides to re-do it. Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709004 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 how do i reset the cookies to do what i need? i have very little knowlege with this and only have a few pages i think that actually use the cookies Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709007 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 Jiraiya, I started writing my 3rd online game  http://game.pictureinthesky.net  I never got around to finishing it but you're more than welcome to ALL the source to look at and play with.  I've just PM'd you with the admin logon information - not all the links in there work.  Don't be afraid to make new topics in the forums and click things. Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709009 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 k thanks, Yesideez. but i really just need to get this script working is there any possible way of getting it fixed quick and easy? Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709018 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 Only as premiso has said - check your login script and make sure you're using the setcookie() properly. Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709022 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 is this what you meant about setting the cookie right? Â Â setcookie('narutotalesofthesannin.com); Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709025 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 this is my login script is it set right? Â Â /Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: player.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=http://narutotalesofthesannin.com/join.php>Click To Sign Up</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: player.php"); } } } else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709029 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 No idea, as I said earlier, I've not used cookies before and don't know how to use them - check premiso's reply showing a link to the instructions for setcookie() Â Quick question - how many scripts have you written so far? Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709030 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 a few bout i only think about like 3 of them actually use cookies i think Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709032 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 You're setting the cookie to expire in only 1 hour which I don't think is long enough tbh. Â If you've only made about 3 that use cookies now might be a good time to edit them to use session variables instead - ever used them before? Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709036 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 i have no idea on how to use sessions Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709037 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 Add session_start() at the start of each script that uses them. Â Here's a quick run-down seeing you're pressed for time. Â Make & set a session var $_SESSION['username']=$_POST['username']; Â To read a session var echo $_SESSION['username']; Â When the user logs out: $_SESSION=array(); Â This link has all the information you'll need: http://uk3.php.net/session Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709044 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 and how exaclty do i use sessions with out screwing up my scripts im so confused, Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709047 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 You would use them like you would any other variable. Â Say you have a user that logs in - all you'd need to do is store their user ID number in a session variable. $_SESSION['id']=$playeruserid; Â Then for example, if you need to get all the information on them use something like this: $usr=mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `userid`='".$_SESSION['id']."' LIMIT 1")); Then you can use $usr like you would normally. Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709052 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 im afraid i still dont follow  i only have 3 pages using cookies the reset are just fetching data from mysql databases Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709055 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 Let's say in the "users" table you've got a field called "accesslevel" which says whether they're a standard player (1), help desk operator (2), moderator (3), head moderator (4) or admin (5). You can check in a small include file if their access level lets them access certain pages. <?php $usr=mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `userid`='".$_SESSION['id']."' LIMIT 1")); if ($usr['accesslevel']<2) { //must be a member of staff  header("Location: accessdenied.php");  exit; } // if accesslevel is 2 or higher the script continues here Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709057 Share on other sites More sharing options...
Jiraiya Posted December 8, 2008 Author Share Posted December 8, 2008 k im going to look into that thanks but for now i really just need to get the cookies going thanks again Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709058 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 If you still cannot figure it out with the above post the 3 pages and I will get it to use sessions. Quote Link to comment https://forums.phpfreaks.com/topic/135803-need-help-fixing-this-php-script/page/2/#findComment-709060 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.