functions.common.cookie.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /* $Id: functions.common.cookie.php 3178 2007-08-14 16:52:01Z munk $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. /**
  16. * get cookie
  17. *
  18. * @param $cid
  19. * @return string
  20. */
  21. function getCookie($cid) {
  22. global $cfg, $db;
  23. $rtnValue = "";
  24. $sql = "SELECT host, data FROM tf_cookies WHERE cid=".$db->qstr($cid);
  25. $rtnValue = $db->GetAll($sql);
  26. return $rtnValue[0];
  27. }
  28. /**
  29. * Delete Cookie Host Information
  30. *
  31. * @param $cid
  32. */
  33. function deleteCookieInfo($cid) {
  34. global $db;
  35. $sql = "delete from tf_cookies where cid=".$db->qstr($cid);
  36. $result = $db->Execute($sql);
  37. if ($db->ErrorNo() != 0) dbError($sql);
  38. }
  39. /**
  40. * Add New Cookie Host Information
  41. *
  42. * @param $newCookie
  43. */
  44. function addCookieInfo( $newCookie ) {
  45. global $db, $cfg;
  46. // Get uid of user
  47. $sql = "SELECT uid FROM tf_users WHERE user_id = ".$db->qstr($cfg["user"]);
  48. $uid = $db->GetOne( $sql );
  49. $sql = "INSERT INTO tf_cookies ( uid, host, data ) VALUES ( ".$db->qstr($uid).", ".$db->qstr($newCookie["host"]).", ".$db->qstr($newCookie["data"])." )";
  50. $db->Execute( $sql );
  51. if ($db->ErrorNo() != 0) dbError($sql);
  52. }
  53. /**
  54. * Modify Cookie Host Information
  55. *
  56. * @param $cid
  57. * @param $newCookie
  58. */
  59. function modCookieInfo($cid, $newCookie) {
  60. global $db;
  61. $sql = "UPDATE tf_cookies SET host=".$db->qstr($newCookie["host"]).", data=".$db->qstr($newCookie["data"])." WHERE cid=".$db->qstr($cid);
  62. $db->Execute($sql);
  63. if ($db->ErrorNo() != 0) dbError($sql);
  64. }
  65. ?>