[PHP] order/reorder pull out data from arrays
I have an array that i would like to sort and reorder based on a simple critera. I already order the data but I would like to break the data now into sections by customer id, so one customer has 5 things and another customer has one. How can I do that with an array. $data = orders($id,$status); $c = count($data); for($i=0; $i$c; $i++) { $orderid = $data[$i]['orderid']; $customerid = $data[$i]['customerid']; $name = $data[$i]['name']; print $orderid.' - '.$customerid.' - '.$name.'br'; } What it is currently is all the orders are ordered by the customer number, however I would like to group it a little nicer on the output. Current: 1234 - blah blah blah - Y - 3, 01234 1235 - blah blah blah - N - 6, 01234 1236 - blah blah blah - N - 6, 01234 1237 - blah blah blah - Y - 6, 11256 1238 - blah blah blah - N - 6, 22589 1239 - blah blah blah - N - 6, 22589 1240 - blah blah blah - Y - 6, 22589 1241 - blah blah blah - N - 6, 22589 Would like: 01234 - The Customer 1 1234 - blah blah blah - Y - 3 1235 - blah blah blah - N - 6 1236 - blah blah blah - N - 6 11256 - The Customer 2 1237 - blah blah blah - Y - 6 22589 - The Customer 3 1238 - blah blah blah - N - 6 1239 - blah blah blah - N - 6 1240 - blah blah blah - Y - 6 1241 - blah blah blah - N - 6 Anyway I can do that?
[PHP] arrays
Banging my head against a wall with arrays, maybe someone can help me with the answer. I have a db query that returns results from 1-100 or more. I want to put the results into an array and pull them out elsewhere. I want them to be pulled out in an orderly and expected fashion. part of function $sql=Select * FROM blah Where blahid='1'; run sql while ($row=mysql_fetch_array($result)) { $oarray=array('blah1' = $row['lah1'], 'blah2' = $row['lah2'], 'blah3' = $row['lah3']); } return $oarray part of display $OLength=count($oarray); for ($i = 0; $i $OLength; $i++){ echo O1 : .$oarray['blah1'][$i].br; echo O2 : .$oarray['blah2'][$i].br; echo O3 : .$oarray['blah3'][$i].br; } this gets me nothing, and I am unsure where I am going wrong, other then all over the place.
Re: [PHP] arrays
Both work great. Thanks On 7/10/06, Brad Bonkoski [EMAIL PROTECTED] wrote: When loading the array you will only ever get the last record returned... so count($oarray) will always be 1? Perhaps something like this: Function $sql = ...; $ret = array(); while($row = mysql_feth_array($reault)) { array_push($ret, $row); } return $ret; then... $data = function(); $c = count($data); for($i=0; $i$c; $i++) { $row = $data[$i]; print_r($row); } Should give you what you want... As for your orderly fashion, I would put this load on the database, and not really PHP... if you want to make it associate you can...just push the assocative onto another array so you get the complete set... -B Dallas Cahker wrote: Banging my head against a wall with arrays, maybe someone can help me with the answer. I have a db query that returns results from 1-100 or more. I want to put the results into an array and pull them out elsewhere. I want them to be pulled out in an orderly and expected fashion. part of function $sql=Select * FROM blah Where blahid='1'; run sql while ($row=mysql_fetch_array($result)) { $oarray=array('blah1' = $row['lah1'], 'blah2' = $row['lah2'], 'blah3' = $row['lah3']); } return $oarray part of display $OLength=count($oarray); for ($i = 0; $i $OLength; $i++){ echo O1 : .$oarray['blah1'][$i].br; echo O2 : .$oarray['blah2'][$i].br; echo O3 : .$oarray['blah3'][$i].br; } this gets me nothing, and I am unsure where I am going wrong, other then all over the place.
[PHP] getting subdirectory
how do I get the subdirectory that a page is being pulled from. say I have three sites running the same script and I need to determine which site is which. http://www.domain.com/subdir1 http://www.domain.com/subdir2 http://www.domain.com/subdir3 and subdir1, subdir2 and subdir3 all need different header and different db and so on. how would i get that I am in site subdir3 and not in subdir1?
Re: [PHP] help with some logic.
Thanks makes it alot easier to follow. On 4/4/06, Dallas Cahker [EMAIL PROTECTED] wrote: Okay I'll look at that. What about switching to setting the password in md5 format in the cookie rather then a regular id. I might not call the cookie password but to me in thinking about it seems like the same thing as setting a random id and then saving the random id in the db. On 4/4/06, Dan McCullough [EMAIL PROTECTED] wrote: hey Dallas, have you thought about breaking this up and making two seperate functions one the checks the cookie and one that checks the session information? I'm not sure if that is what you were looking for as far as an answer but it might be a good start. On 4/4/06, Dallas Cahker [EMAIL PROTECTED] wrote: I've been looking at this code for a few hours now and I get the nagging feeling that I am overcomplicating something, something I never ever do. I have a login that puts some information on the session, and if the customer wants they can ask to be remembered, the cookie is given the customers user name and another cookie stores a unique id, similar to a password I could do the password in a cookie as its md5 encrypted, but I went with an a unique id which is store in the user db. Anyway here is what I am trying to do with the code below. The authorized user section requires 4 pieces of information, userid, password, username and user level, a person who logs in each time gets that information assigned to their session, that part works *knock on wood* perfectly. When a customer says remember me they go away and come back a while later they are remembered, so that part works perfectly, however I need to get the persons information and put that on the session, however I would like the function to behave in such a way as to not overwrite the information each time the page load. So for example the cookie is read the information is valid, the query to the db, the information set to the session. You might wonder why I dont set the userlevel to the cookie, well I dont want someone changing the value of a cookie and getting admin access, which reminds me I should add that as a check. Thats about it. getCookieInfo() the function inside the checkLogin function just looks up the information for the cookie in the db. I know that someone is going to say something really simple that I am going to slap my forehead over, I would like to thank that person before hand. function checkLogin () { /* Check if user has been remembered */ if (isset($_COOKIE['cookname']) isset($_COOKIE['cookid'])) { if (!isset($_SESSION['name']) !isset($_SESSION['id']) !isset($_SESSION['level']) !isset($_SESSION['password'])) { $cookieInfo=getCookieInfo($_COOKIE['cookname'], $_COOKIE['cookid']); if ($cookieInfo==0) { return 0; } if ($cookieInfo==1) { setcookie(cookname, , time()-60*60*24*100, /); setcookie(cookid, , time()-60*60*24*100, /); return 1; } if ($cookieInfo==2) { setcookie(cookname, , time()-60*60*24*100, /); setcookie(cookid, , time()-60*60*24*100, /); return 2; } } } if (isset($_SESSION['name']) isset($_SESSION['id']) isset($_SESSION['level']) isset($_SESSION['password'])) { if (loginUser($_SESSION['username'], $_SESSION['password'],'') != 1) { unset($_SESSION['name']); unset($_SESSION['id']); unset($_SESSION['level']); unset($_SESSION['password']); $_SESSION = array(); // reset session array session_destroy(); // destroy session. // incorrect information, user not logged in return 0; } // information valid, user okay return 1; } else { // user not logged in return 2; } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php, sessions and ie
Thanks for the information On 4/4/06, Chrome [EMAIL PROTECTED] wrote: I let GC and cookie expiration handle ending the session... The cookie was only set for 15 minutes Dan --- http://chrome.me.uk -Original Message- From: Dallas Cahker [mailto:[EMAIL PROTECTED] Sent: 04 April 2006 19:41 To: php-general@lists.php.net Subject: Re: [PHP] php, sessions and ie How are you destroying the sessions if they leave the site (dont logout). do you check on activity or something else? On 4/4/06, Dan Parry [EMAIL PROTECTED] wrote: I have had some issues with sessions and IE in the past and used the following code to start the session ?php if (isset($SessID)){ session_id($SessID); } session_start(); header(Cache-control: private); // IE 6 Fix. setcookie(SessID, session_id(), time() + 60 * 15); ? Now, though, I always use a DB to store sessions... Much nicer HTH Dan - Dan Parry Senior Developer Virtua Webtech Ltd http://www.virtuawebtech.co.uk -Original Message- From: Dallas Cahker [mailto:[EMAIL PROTECTED] Sent: 04 April 2006 16:19 To: php-general@lists.php.net Subject: [PHP] php, sessions and ie I've been hearing some of my friends saying there is an issue with Session in PHP and IE having problems with them. Is that true? If it is how do people get around this? Session information saved to db? Session id in cookie? __ NOD32 1.1454 (20060321) Information __ This message was checked by NOD32 antivirus system. http://www.eset.com
[PHP] php security
I was looking to see if there was a quick checklist of settings for php to be disabled/enabled in the ini file to make the application more secure. I'm making sure the apps we come out with dont allow sql injections, or form injections and so forth, I have just seen some posts about magic quotes and so on and so I was curious.
[PHP] ?=? style
What is that called and where in the php.ini file do I enable it? Sorry if this is a stupid question but since I dont know what its called it makes it difficult to google it.
Re: [PHP] server/PHP security
Is there a certain file type that you are looking for? You could restrict it to that, also you could chown the uploaded files to a no/low privelage user. On 4/6/06, Wolf [EMAIL PROTECTED] wrote: They all ended in .rar Files named: b.php.rar jpg.php.rar c99.php.rar Dan McCullough wrote: WHat types of files were they, if you dont mind me asking? On 4/6/06, Wolf [EMAIL PROTECTED] wrote: I woke up on thanksgiving morning to find my server hacked through a hole left by a file upload area of my site. I restored the backup and placed a few blocks in place on the server, so they can get in, but they can't get out ;) What I am interested in finding out is what the best way is to make sure that I can rework the upload area to allow upload and download from it while keeping script kiddies from exploiting it again. I can post the scripts (if you are interested in pulling them apart or such) as I have accumulated 3 different versions now, but I am wondering what you guys use currently as standard PHP security and still do file parsing and such. Thanks, Wolf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] help with some logic.
I've been looking at this code for a few hours now and I get the nagging feeling that I am overcomplicating something, something I never ever do. I have a login that puts some information on the session, and if the customer wants they can ask to be remembered, the cookie is given the customers user name and another cookie stores a unique id, similar to a password I could do the password in a cookie as its md5 encrypted, but I went with an a unique id which is store in the user db. Anyway here is what I am trying to do with the code below. The authorized user section requires 4 pieces of information, userid, password, username and user level, a person who logs in each time gets that information assigned to their session, that part works *knock on wood* perfectly. When a customer says remember me they go away and come back a while later they are remembered, so that part works perfectly, however I need to get the persons information and put that on the session, however I would like the function to behave in such a way as to not overwrite the information each time the page load. So for example the cookie is read the information is valid, the query to the db, the information set to the session. You might wonder why I dont set the userlevel to the cookie, well I dont want someone changing the value of a cookie and getting admin access, which reminds me I should add that as a check. Thats about it. getCookieInfo() the function inside the checkLogin function just looks up the information for the cookie in the db. I know that someone is going to say something really simple that I am going to slap my forehead over, I would like to thank that person before hand. function checkLogin () { /* Check if user has been remembered */ if (isset($_COOKIE['cookname']) isset($_COOKIE['cookid'])) { if (!isset($_SESSION['name']) !isset($_SESSION['id']) !isset($_SESSION['level']) !isset($_SESSION['password'])) { $cookieInfo=getCookieInfo($_COOKIE['cookname'], $_COOKIE['cookid']); if ($cookieInfo==0) { return 0; } if ($cookieInfo==1) { setcookie(cookname, , time()-60*60*24*100, /); setcookie(cookid, , time()-60*60*24*100, /); return 1; } if ($cookieInfo==2) { setcookie(cookname, , time()-60*60*24*100, /); setcookie(cookid, , time()-60*60*24*100, /); return 2; } } } if (isset($_SESSION['name']) isset($_SESSION['id']) isset($_SESSION['level']) isset($_SESSION['password'])) { if (loginUser($_SESSION['username'], $_SESSION['password'],'') != 1) { unset($_SESSION['name']); unset($_SESSION['id']); unset($_SESSION['level']); unset($_SESSION['password']); $_SESSION = array(); // reset session array session_destroy(); // destroy session. // incorrect information, user not logged in return 0; } // information valid, user okay return 1; } else { // user not logged in return 2; } }
Re: [PHP] help with some logic.
Okay I'll look at that. What about switching to setting the password in md5 format in the cookie rather then a regular id. I might not call the cookie password but to me in thinking about it seems like the same thing as setting a random id and then saving the random id in the db. On 4/4/06, Dan McCullough [EMAIL PROTECTED] wrote: hey Dallas, have you thought about breaking this up and making two seperate functions one the checks the cookie and one that checks the session information? I'm not sure if that is what you were looking for as far as an answer but it might be a good start. On 4/4/06, Dallas Cahker [EMAIL PROTECTED] wrote: I've been looking at this code for a few hours now and I get the nagging feeling that I am overcomplicating something, something I never ever do. I have a login that puts some information on the session, and if the customer wants they can ask to be remembered, the cookie is given the customers user name and another cookie stores a unique id, similar to a password I could do the password in a cookie as its md5 encrypted, but I went with an a unique id which is store in the user db. Anyway here is what I am trying to do with the code below. The authorized user section requires 4 pieces of information, userid, password, username and user level, a person who logs in each time gets that information assigned to their session, that part works *knock on wood* perfectly. When a customer says remember me they go away and come back a while later they are remembered, so that part works perfectly, however I need to get the persons information and put that on the session, however I would like the function to behave in such a way as to not overwrite the information each time the page load. So for example the cookie is read the information is valid, the query to the db, the information set to the session. You might wonder why I dont set the userlevel to the cookie, well I dont want someone changing the value of a cookie and getting admin access, which reminds me I should add that as a check. Thats about it. getCookieInfo() the function inside the checkLogin function just looks up the information for the cookie in the db. I know that someone is going to say something really simple that I am going to slap my forehead over, I would like to thank that person before hand. function checkLogin () { /* Check if user has been remembered */ if (isset($_COOKIE['cookname']) isset($_COOKIE['cookid'])) { if (!isset($_SESSION['name']) !isset($_SESSION['id']) !isset($_SESSION['level']) !isset($_SESSION['password'])) { $cookieInfo=getCookieInfo($_COOKIE['cookname'], $_COOKIE['cookid']); if ($cookieInfo==0) { return 0; } if ($cookieInfo==1) { setcookie(cookname, , time()-60*60*24*100, /); setcookie(cookid, , time()-60*60*24*100, /); return 1; } if ($cookieInfo==2) { setcookie(cookname, , time()-60*60*24*100, /); setcookie(cookid, , time()-60*60*24*100, /); return 2; } } } if (isset($_SESSION['name']) isset($_SESSION['id']) isset($_SESSION['level']) isset($_SESSION['password'])) { if (loginUser($_SESSION['username'], $_SESSION['password'],'') != 1) { unset($_SESSION['name']); unset($_SESSION['id']); unset($_SESSION['level']); unset($_SESSION['password']); $_SESSION = array(); // reset session array session_destroy(); // destroy session. // incorrect information, user not logged in return 0; } // information valid, user okay return 1; } else { // user not logged in return 2; } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php, sessions and ie
I've been hearing some of my friends saying there is an issue with Session in PHP and IE having problems with them. Is that true? If it is how do people get around this? Session information saved to db? Session id in cookie?
Re: [PHP] php, sessions and ie
How are you destroying the sessions if they leave the site (dont logout). do you check on activity or something else? On 4/4/06, Dan Parry [EMAIL PROTECTED] wrote: I have had some issues with sessions and IE in the past and used the following code to start the session ?php if (isset($SessID)){ session_id($SessID); } session_start(); header(Cache-control: private); // IE 6 Fix. setcookie(SessID, session_id(), time() + 60 * 15); ? Now, though, I always use a DB to store sessions... Much nicer HTH Dan - Dan Parry Senior Developer Virtua Webtech Ltd http://www.virtuawebtech.co.uk -Original Message- From: Dallas Cahker [mailto:[EMAIL PROTECTED] Sent: 04 April 2006 16:19 To: php-general@lists.php.net Subject: [PHP] php, sessions and ie I've been hearing some of my friends saying there is an issue with Session in PHP and IE having problems with them. Is that true? If it is how do people get around this? Session information saved to db? Session id in cookie? __ NOD32 1.1454 (20060321) Information __ This message was checked by NOD32 antivirus system. http://www.eset.com