Jump to content

criostage

Members
  • Posts

    42
  • Joined

  • Last visited

Everything posted by criostage

  1. Hi, i m playing arround with php sessions and just started afew testing on it (i never actually used them so i m discovering something new) and i would like to know how can you terminate an PHP Session without closing your browser. For testing i did this small code, just to see the behavior: <?php session_start(); $id = session_id(); echo $id; session_unset(); session_destroy(); ?> The code above seens only to kill the $_SESSION's variables but what i would like is to Kill the PHPSESSID cookie/session cookie. is there anyway you can achive that? thanks in advance
  2. Every single configuration you do to apache (even if you add or remove a dot) in the config you MUST restart the apache service on your computer otherwise your apache server wont assume the new settings.
  3. i dont think that the the action like your doing is going to to work, from your code: <form action="switch.php?id=<?php echo $row['ID']?> action=edit_ok" method="post"> try this way add something like this in your form: <form action="switch.php" method="post"> <input type='hidden' name='action' value='edit_ok'> (...) </form> On the switch use $_POST['action'], i was testing out this today and this is how i made my code to work hope it helps...
  4. cssfreakie thank you my mistake ;X
  5. Hi, i know this ain tan "BIG" question but ever since i started to play with php and mysql i noticed this. while testing values etc ... every time i delete an registry and re-add it later the id (as auto incremental) will add the registry normaly but will leave an "blank" id between 2 entries for example: id name profession 1 john programmer 2 mario plummer 5 Samus Bounty Hunter Is there anyway to fill up the gaps or remove them? are these gaps "harmfull" to the database search's? thanks in advance
  6. So your just using PHP SESSIONS to login ? then just do this: if( isset($_SESSION['Username']) && isset($_SESSION['LoggedIn']) ){ $link = '<a href="logout.php">Logout</a>'; }else{ $link = '<a href="login.php">Logout</a>'; } In you case you probably would just use the $_Session["LoggedIn"] but i like to verify more than 1 thing before i can actually log 1 person on ... i m an noob also if you use an cookie you do the same thing but for the $_COOKIE['name_of_the_cookie'] variable. EDIT: heres afew links with help on the $_SESSION and $_COOKIE variables: http://php.net/manual/en/reserved.variables.session.php http://php.net/manual/en/reserved.variables.cookies.php
  7. Hello i would like to as a little help on how to proper format an foreach output into an HTML table. I have a small function inside an class, that will retrieve the data of an MySQL table and return the result in 1 array, Outside that function i can get the values displayed i only need to format it to show in an table here's what i have: function that gets the data function getfansub(){ $subfanarray = array(); $query = mysql_query("SELECT * FROM anr_fansub WHERE 1"); while($result = mysql_fetch_array($query)){ $subfanarray[] = $result; } return $subfanarray; } Outside the funtion/class $fansubarray = $mysql->getfansub(); VAR_DUMP( $fansubarray ); echo "<br><br>"; foreach($fansubarray as $name){ echo $name['FansubID'] ." ". $name['Designation'] ." ". $name['Website'] ." ". $name['tracker'] ." ". $name['irc'] ."<br>"; } The problem i have with the formating (i really dont know who i can do it) is when he reaches the IRC link he needs to open and close the td and tr brakets of the table. any help or tip is apreciated, thanks in advance
  8. I m a person still learning php (fairly new) but i dont think it's an good idea to store your password in a cookie because of the "cookie jacking" issue, give it a search in google if you dont know what it is, but basically its an attack that steals the victim all its cookies, and from that moment a person can use your account in that site as if was you. I m still researching this but here's something i did on wanna-be site: - Password is only used on the login upon the user logon an cookie will be created with an unique ID; - Use the cookie ID and compare it with the database to see if the cookie is valid (at least u wont be exposing the user password); - Every time an person login an new cookie ID is generated and updated in the database. - My cookies only lasts for 60 min top's. Something i m thinking to do: - Storing the time when the cookie was created and compare it when the person access's the site example: -- if the (current_time+cookie_time) is igual or higher then the cookie_creation_time then destroy the current cookie and ask the user for new authentication. Hope it helps
  9. I been having this small curiosity "how to" for some time hope any one could give me an orientation. I m doing an website (from scratch as a self learning project) to "host" a list of movies and at the moment i m using the $_GET variables as navigation indicators (for example http://server/?go=settings, page will display the user settings) and the $_POST variables to pass all kind of form related data. At the moment i m done with all the authentication part (PHP,MySQL + cookies), but what m missing is a way to tell the user that "well your username or password is wrong", sounds silly i know ... i looked an fancy way of sending an user the warning and i found this small project of jquery called pnotify, where a small ballon will show on the page an message. My problem is to make the ballon apear upon an error of the authentication (if i just paste the code into the body it works). Besides the $_POST or $_GET is there anyway to pass an error code to an object? This is the code i have for the menu that decides all page navigation: page.php <?php session_start(); $mysql = new mysql($dbhost,$dbuser,$dbpwd,$dbname,$seckey); $auth = new authentication(); require_once(INCLUDES_PATH.'page.header.php'); require_once(INCLUDES_PATH.'inc.actions.php'); require_once(INCLUDES_PATH.'page.footer.php'); action.php <?php $do = isset($_GET["do"])?$_GET["do"]:""; switch ($do) { case "login": if( isset( $_POST['usr'] ) && isset( $_POST['pwd'] ) ){ $login = $auth->login( $_POST['usr'], $_POST['pwd'], $mysql); header( "Location:$_PATHS[home]" ); } else{ require_once(INCLUDES_PATH.'page.login.php'); } break; case "logout": $auth->logout(); header("Location:$_PATHS[home]"); break; default: require_once(INCLUDES_PATH.'page.body.php'); break; } ?> Thank you in advance.
  10. Yes you are right, i just tested it out and the out put was perfect on the 1st try ... tyvm for the help i cant belive i didnt saw that one ..... ;p
  11. Hello, i m doing a small site for personal use where i m using php and mysql as a database. I m still learning how to proper doing things so far so good but i been bashing my head against this small issue. I have mainly 1 class for all MySQL queries inserted into functions for example connect() will start the mysql connection uppon the Class/Object creation, safequery() will clear out the mysql injection problem, so on so on ... what i m trying to do, and its where i m stuck, is get a list (array) of data from MySQL to build an drop down menu, but i m not able to pass the total of the array values into the external piece of code that builds the combobox. If i do this i can get the list of all the values inside the array (witch are correct): function getanimestatus(){ $query = mysql_query("SELECT designation FROM agi_status"); while($result = mysql_fetch_array($query)){ echo $result['designation']."<br>"; } return $result; } so i changed the function to send out the array: in the class function getanimestatus(){ $query = mysql_query("SELECT designation FROM agi_status"); $result = mysql_fetch_array($query); return $result; } where i m calling the function in the class $mysql = new mysql($dbhost,$dbuser,$dbpwd); var_dump( $mysql->getanimestatus()); But for the reason i dont understand i only get the 1st value of the array. array(2) { [0]=> string(6) "Airing" ["designation"]=> string(6) "Airing" } Any help or tips would be deeply apreciated. Full class code: <?php # Classe que contem todas as operações relacionadas com a interação do site com o Servidor MySQL class mysql{ # Váriaveis necessárias para a ligação á base de dados MySQL private $dbname = 'phpMyAnimeList'; private $dbhost = ''; private $dbuser = ''; private $dbpwd = ''; private $dblink = ''; private $tblink = ''; # Váriaveis necessárias para as funções da classe private $saltkey = '15e1065fea'; private $safequeryvar = ''; private $safequeryvar2 = ''; # Quando objecto da class mysql é criado as variaveis $dbhost,$dbuser e $dbpwd são alimentadas pelos valores # definidos pelo utilizador no ficheiro config.php function __construct($host,$user,$pwd) { $this->dbhost = $host; $this->dbuser = $user; $this->dbpwd = $pwd; $this->connect(); } # Função de ligação ao servidor de MySQL e selecção da base de dados phpMyAnimeList function connect(){ $this->dblink=mysql_connect($this->dbhost, $this->dbuser, $this->dbpwd); if( !$this->dblink ){ die( "<b>Unable to connect to the database</b>:" . mysql_error()); $this->close(); }else{ $this->tblink = mysql_select_db($this->dbname,$this->dblink); if( !$this->tblink ){ die( "<b>Unable to select the database</b>:" . mysql_error()); $this->close(); } } } # Pequena função para prevenir mysql injection function safequery($input){ $safeinput = mysql_real_escape_string(stripslashes($input)); return $safeinput; } # Função para limpar o conteudo das variaveis caso já não sejam necessárias function cleanvar(){ unset($this->safequeryvar); unset($this->safequeryvar2); } # Termina a ligação ao servidor MySQL function close(){ mysql_close( $this->dblink ); } # Verifica se o utilizador e password's inseridos pelo utilizador estão na base de dados e se estão correctos function logincheck($username,$password){ $this->safequeryvar = $this->safequery($username); $this->safequeryvar2 = sha1(md5($this->safequery($password).$this->saltkey)); $query = mysql_query("SELECT username FROM usm_user WHERE Username='$this->safequeryvar' AND Password='$this->safequeryvar2'"); $rows = mysql_num_rows($query); if($rows == 1){ $this->cleanvar(); return $rows; }else{ $this->cleanvar(); return false; } } function setcookieid($idcookie,$username){ $this->safequeryvar = $this->safequery($username); mysql_query("UPDATE usm_user SET Cookieid='$idcookie' WHERE Username='$this->safequeryvar'"); $this->cleanvar(); } # Queries relacionadas com o Theme do site & user function setsitetheme($themeid){ $this->safequeryvar = $this->safequery($themeid); mysql_query("UPDATE wsm_theme SET `Default`='0' WHERE `Default`='1'"); mysql_query("UPDATE wsm_theme SET `Default`='1' WHERE `ThemeID`='$this->safequeryvar'"); $this->cleanvar(); return 0; } function setusertheme($themeid,$cookieid){ $this->safequeryvar = $this->safequery($themeid); $this->safequeryvar2 = $this->safequery($cookieid); mysql_query("UPDATE usm_user SET `ThemeID`='$this->safequeryvar' WHERE `Cookieid`='$this->safequeryvar2'") or DIE(mysql_error()); $this->cleanvar(); } function getusertheme(){ $query = mysql_query("SELECT wsm_theme.Designation FROM wsm_theme LEFT OUTER JOIN usm_user ON ( usm_user.ThemeID = wsm_theme.ThemeID ) WHERE usm_user.ThemeID = wsm_theme.ThemeID"); $result = mysql_fetch_array($query); return $result['Designation']; } function getsitetheme(){ $query = mysql_query("SELECT Designation FROM wsm_theme WHERE `Default` = '1'"); $theme = mysql_fetch_array($query); return $theme['Designation']; } # Funções para ir buscar informação de categorização e identificação dos titulos function getanimestatus(){ $query = mysql_query("SELECT designation FROM agi_status"); $result = mysql_fetch_array($query); return $result; } # Funções relativas aos insert's na base de dados function insertanime(){ } function insertfansub(){ } function insertcategory(){ } function showanime(){ } function showfansub(){ } function showcategory(){ } } ?>
  12. try <?php echo 'Now: '. date('Y-m-d') ."\n"; echo 'in 30 days: '. date('Y-m-d', strtotime('+30 days')) ."<br>"; // Or echo 'in 30 days: '. date('Y-m-d', time() + 2592000) ."<br>"; ?> my output was: Now: 2011-08-18 in 30 days: 2011-09-17 in 30 days: 2011-09-17 More Information on the functions: TIME() - http://php.net/manual/en/function.time.php strtotime() - http://php.net/manual/en/function.strtotime.php
  13. Hello, I m doing an small page as a side project of mine to learn php. So far so good, i been able to find what i need in order to advance but i this time i have hitted a wall on the login, in the security side (i can make it work but not as secure as i would like). Ok so heres the code i have: I have all things related to mysql in an class called mysql, where i m going to put all the queries to the database including the password and username check function logincheck($username,$password){ $this->safeusername = $this->safequery($username); $this->safepassword = $this->safequery($password); $query = mysql_query("SELECT username FROM usm_user WHERE Username='$this->safeusername' AND Password='$this->safepassword'"); $rows = mysql_num_rows($query); if($rows == 1){ return $rows; }else{ return false; } } function safequery($input){ $safeinput = mysql_real_escape_string(stripslashes($input)); return $safeinput; } then i have an page where i setup all the actions that the site can do (with an switch) require('../config.php'); require('inc.functions.php'); require('inc.mysql.php'); $mysql = new mysql($dbhost,$dbuser,$dbpwd); $authentication = new authentication; $do = isset($_GET["do"])?$_GET["do"]:""; switch ($do) { case "login": if(isset($_GET['usr'])) { $mysql->logincheck($_GET['usr'],$_GET['pwd'],$mysql,$_GET['rm'] = false); } break; case "logout": $authentication->logout(); break; On the final page i have a small form that will set the login info. My question here is how to send the password safely from the login form to the page that will call the function that will check the username and password. Like i said i can pass it through the $_GET, and i tough in using $_POST just for the password, but i would like to know if there is an better way to do it so. Thanks in advance.
  14. Use another table. tvshow | genre -------+------ 10 | 10 10 | 12 10 | 13 lol damn the solution was pretty simple ... tyvm for your help man =)
  15. Hi, i m doing a small project of mine to learn PHP and MySQL as a hobby, i did some PHP scripts or utilities in the past but never had actually to use an database until now (i only have some experience in creating databases, tables and perform backups and restores on the database), in this project i m trying to do an TV Show database to store and keep track of what i have. I started to write down what i needed to know about an certain show and i came to this list: - Name, Alternative Name, Genre, Relation with other series or seasons, description, number of episodes etc ... and would translate into something like this in tables: ID | Name | AlName | Relation | Description | Episodes | Genre So Far so good, inserting just 1 data field from php to the database isnt that hard, but then since i watch Japanese, Korean and sometimes chinese movies there are a few genre's (especially in japanese Anime) that i would like to store an small description to the term to know what it means so i had to do an 2nd table just for the Genre's (this would help me to insert more genre's to the database later on as well) so the database would be like this: TV Show Table ID | Name | AlName | Relation | Description | Episodes Genre Table ID | Genre | Description My Question is (and sorry for long description ...) whats the best way to store in the database the relation between the 2 tables to say that the TV Show With the ID 10 have the Genre ID 10, 12 and 13? thank you in advance. PS: i dont have any SQL code to show yet since all my "drawing" are all still on paper ... truly sorry about that but if needed i will do the code with what ever i already have.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.