Jump to content

Klaas

WFG Retired
  • Posts

    3.116
  • Joined

  • Last visited

Posts posted by Klaas

  1. Lessie is a Collie, mine is a Border Collie (the Scottish sheep-herding version).

    We're not sure she's a real Border Collie though. Our previous one was a real one from Scotland and was a bit bigger and had a much different character. She's very playful, always wants to play and fight with me, and she doesn't like strangers. The only people who can touch here are me, my parents, my eldest brother and sometimes my gf. The only real Border Collie things she has is the looks (aside from being a bit too small), being a bit stressed easily, running a lot and really fast (she needs tons of space), needs a lot of attention and likes walking circles around our sheep :D

    Border Collies are rarely aggressive or playfull though, so that's the difference. Fortunatly she would only bite when you touch her, she never attacks.

    But I like her being like that, I can really scare off people when I play with her. Growling extremely loud, jumping and biting at me, making all kind of funny jumps (even small saltos ;), it's like a circus dog).

    Oh and a recent study showed that they're the smartest dogs in the world, able to remember a few thousand commands. I've seen a Border Collie show once and it's really amazing how the farmer commands them by whistles. They respond differently to each type of whistle.

  2. What do you mean exactly? The coding part: xhtml, css; or the graphical part?

    In fact there are no tutorials for that (graphical), except photoshop techniques to make common graphical elements (buttons, backgrounds, etc.), or design theory.

    But I'll explain how I learned it (and I'm still far from making a professional layout imo):

    First of all: master the technology. It's essential that you know the ins and outs of photoshop (or fireworks). Some important points:

    - use of layers: layer effects, grouping layers, selecting layers, editing layers, etc. (tip: to make a selection around a layer CTRL+click it in the layer window, that's extremely handy)

    - editing/making your own gradients: you can make all kinds of gradients with as many colors you want, and even transparency gradients.

    - the selection tool: you're going to use that a lot. Important is the polygonal selection tool, especially for cutting stuff out of photos (like the truck in my last layout)

    - zooming: using the zoom is very handy when editing small things or when using the polygonal selection tool

    - hue/saturation: you'll find this in the image -> adjusments menu, really handy for changing colors, lightness and saturation

    - using tools like the clone-stamp (and any other tool for that matter :D)

    Now, next to mastering photoshop you should have a little understanding of design theory. I don't know much about that anyway, nor any tutorials, but in the tutorial that's coming with Inkscape (SVG graphics program) you'll find a nice summary. I also recommend this book: The Zen of CSS Design by David Shea, it's a book featuring websites from the CSS Zen Garden with many nice comments explaining you everything from typography to graphic design (not technical) to CSS.

    And last but not least: spend much time admiring beautiful layouts, but also things around you (a beautiful designed piece of furniture, a painting, flowers, etc.)

    Sites you should check often for great layouts:

    http://www.cssvault.com/

    http://www.csszengarden.com/

    I always start looking at all those layouts before I start designing one, it's really useful.

    Some additional tips:

    - Use nice photographs in your layouts. They can really spice up the design a lot. What's essential here is that you know a bit about photo-editing: giving it another color/saturation/lightness, resizing, cutting out stuff, layer masks, gradient overlays, blend mode, etc.

    - Use the shadow layer effect. This one's really nice, but use it moderatly. Make your shadow not too strong (adjust its transparency) and not too far from the source

    - Use the outer glow layer effect. Set blend mode to normal, use a dark color and adjust the size. Really useful to accomplish this:

    http://www.vvb.org/ (the shadowy borders around the layout at the left and right side).

    Anyway, it took me quite some time to create the layouts I'm making now. The last one for example (the slaughterhouse) took me a few weeks and much experimenting (as you can see in the 4 layouts I made). The key is practice and willing to do everything all over again. I never stick to my first idea actually, I always try something different until I'm satisfied.

  3. That depends what you prefer: more readable code or better performance. You won't gain much performance like this anyway. I always use double quotes for my SQL, because it usually contains single quotes and don't want all that escaping mess.

    But if you're writing an application with tons of SQL (with tons I really mean thousands with many users) then it's a better idea to stick to single quote.

    btw, it's not because you use double quotes to encapsulate your SQL that you are obliged to use double quotes for your arrays. So in the second example keep using $_SERVER['REMOTE_ADDR'] and date('U').

    @Tim

    yeah, that looks much better. I always did it like that but at school all the C code we got and the teacher wrote was like the first example, so I got used to it. Guess I'll have to go back to better practices again :D

    Well, the thing with C is that it's compiled anyway so increased file size because of white space doesn't really matter because the compiler ignores it.

  4. Btw, there's another thing you should pay attention too: use of double and single quotes:

    1: 
    2: $var= 'test';
    3: 
    4: echo '$var'; // will echo $var
    5: echo "$var"; // will echo test
    6: echo '$var\n'; // will echo $var\n
    7: echo "$var\n" // will echo test with a linebreak
    8: 

    Same goes with assigning values to variables and such.

    So what's between single quotes isn't going to be parsed by PHP, if it's between double quotes it will be parsed. The biggest advantage of using the correctly is saving server resources: parsing a big block of text that doesn't contain stuff to be parsed anyway (linebreaks, variables, ...) is a bit overkill.

  5. Klaas:

    You need to review your posts, Klaas. If you do so, you can see that you act as if evolution has already been proved, when talking about the 2 different kinds of "scientists."

    That's excactly what you're doing. Sir Arthur Kieth, evolutionist, makes it sound like that, too (see previous quotes by him that I posted.). As for the alternative, evolution is the only other option.

    Clodhopper, I'm not going to explain everything two or three times just because you want to read something in my posts that's not there. You take one part of my posts and you criticise it while you're not answering the rest (difference between science and creationism).

    So for the third time:

    Evolution as a theory has only been proved with what we have, I'm not saying evolution is right. I said many times now that if they find exceptions to the evolution theory they'll adapt that theory.

    I'll again make a comparison to historical research. So the historian uses sources in trying to find out what happened in the past, much like a scientist uses observation, deduction, etc. to make a theory. But since you can't have all the sources, since those sources aren't always that relieable a historian will never say that his findings are absolutely correct. They are only correct in the context of those sources that are available. So the same goes for evolution, it's not set in stone, it's just what we now up til now, but that can always change.

    Let's take this phrase here: "It isn't as wild as what creationists do" Basically, you said: This is wild, but the opponent's is also wild, if not wilder. That is a "Two wrongs make a right" fallacy.

    Look, you take the first sentence I say while I'm explaining everything in the following sentences. I explained why it isn't wild in the text above again: it's not wild because evolutionism and related theories are based upon what we know now, I'm not saying it is set in stone.

    I wrote about creationism because it is creationism, not evolutionism, that's being wild, because creationism uses the theory as base, not the observation, and it is a fixed theory, not a dynamic one like any theory is in science. So it's not two wrongs I'm talking about.

    If you will notice, Radiocarbon dating was invented in the year of Sir Arthur Keith's death in 1955. So why would anyone want to keep something for 15 years without any reason to do so? Plus, where are these tons of specimens, anyway?

    Ever heard of museum depots containing many old organic specimens? In the Belgian museum of Tervuren for example the whole (huge) cellar is filled with organic material dating between 1908 - 1963, all found in Congo.

    Or lets make it easier: what about a graveyard? In the Westhoek region of Belgium a few hundred thousand WW1 soldiers are burried. That's quite a bit of specimens there :D

    So who's wrong? Your site or Mythos'?

    From Mythos his site:

    "A study in the 1960s showed that the decrease in the dipole component since the turn of the century had been nearly completely compensated by an increase in the strength of the nondipole components of the field."

    So they're saying the same aren't they.

  6. The Elder Scrolls: Oblivion is probably coming out too around that period.

    I really hate it that they launch those games during the winter since it's an exam period. Why not during july/august? Got plenty of time then to play a game :/

    Well maybe I should just be patient and wait to buy them during summer holidays (next year), and they'll probably be a bit cheaper by that time :D

  7. Ugo... write a book, man! Wow, every one of your posts is as long as a chapter! :D You're not as long winded as [you], though.

    Okay, back to flag burning. Surely, no one on this board would be upset about the burning of a Nazi flag?

    Rofl, I thought you were talking about me (which is true though), clever use of those tags, [you] ;)

  8. You could shorten it quite a bit by using some more advanced SQL:

    SELECT DISTINCT ip FROM useronline

    What this does is selecting only rows containing a different ip, it won't select a row containing an ip that is already selected.

    an example using it (got it from phpclasses.org, very useful site):

     1: 
     2: function new_user() {
     3:   $insert = mysql_query ("INSERT INTO useronline(timestamp, ip) VALUES ('$this->timestamp', '$this->ip')");
     4:  }
     5: 
     6:  function delete_user() {
     7:   $delete = mysql_query ("DELETE FROM useronline WHERE timestamp < ($this->timestamp - $this->timeout)");
     8:  }
     9: 
    10:  function count_users() {
    11:   $count = mysql_num_rows ( mysql_query("SELECT DISTINCT ip FROM useronline"));
    12:   return $count;
    13:  }
    14: 
    15: 
    16: 

    So very short, though it's doing almost the same as your script.

    Another note on your sql though the script above alone is fine:

    1: 
    2: $sql = "SELECT count(*) AS users_online FROM online_list";
    3: $result = database ($sql);
    4: $online_users = $result['users_online'];
    5: 

    It's much more lighter than your version because it only counts, it doesn't select all the data (ip and last_active)

    There's another method here (too long imo but worth the read, especially the comments on the last page):

    http://www.phpfreaks.com/tutorials/62/0.php

  9. Well if you just started using tableless websites you've only been using xhtml 1.1 since then :D

    The thing is that xhtml, and especially xhtml 1.1, isn't xhtml persé if the validator validates it. The next step is semantics, and if your website's code isn't semantically correct you can't say it's xhtml 1.1 in theory. So tables for layout isn't semantic use of xhtml, tables are only for tabular data.

    Anyway, I really advise you not to use XHTML 1.1 or to serve it, even if you serve it only to compliant browsers/user agents. It's just like using CSS 5 or 6 years ago, the technology isn't mature enough yet. It's of course very good that you're learning it, you'll benifit from that in the future, but you should stick to xhtml 1.0 Strict for the time being.

  10. Hmm why aren't there line break anyway? The easiest sollution is just adding linebreak in your template itself or when you're generating your layout with your template engine.

    So let's say you're outputting this a few times

    1: 
    2: <p>blablabla</p>
    3: 

    Just let your script add \n each time you output that chunk (stupid example):

    1: 
    2: foreach ($var as $value)
    3: {
    4: echo $value."\n";
    5: }
    6: 

    Doing it afterwards seems a bit overkill to me.

  11. You shouldn't serve your pages as application/xhtml+xml, except if you wish to experiment with xhtml1.1 (which really isn't worth your time right now).

    In a production environment (a live website) you shouldn't do this because there aren't many browsers supporting xhtml+xml, except maybe Firefox.

    So I suggest you wait another year or two/three, when Firefox and IE7 are the mainstream browsers.

    I also don't think there are any open source/free WYSIWYG editors available that are written for xhtml1.1, you better stick to what you're using now.

  12. Well there are a few possibilities. The best one is using regex, but since my knowledge is a bit rusty in that area try this:

    http://be.php.net/manual/en/function.explode.php

    This might be a bit too large for what you try to accomplish but it'll do the trick:

     1: 
     2: $string  = "<p>link<br />link<br />link<br /></p>";
     3: $pieces = explode('<br />', $string);
     4: $lastkey = count($pieces);
     5: for ($i=0;$i < $lastkey;$i++)
     6: {
     7: $strippedstring .= $pieces[$i];
     8: if ($i != ($lastkey - 1) && $i != ($lastkey - 2))
     9: {
    10: $strippedstring .= '<br />';
    11: }
    12: }
    13: 

    Not sure if it works, but you get the idea. It simply chops the string in an array, each array element contain a string that was separated by a <br />. Then the loops reconstructs the string but doesn't add a <br /> for the last array element and the one before. Those two because the last part of the array didn't have a <br /> at the end anyway (<p>) and the one before it because that's the <br /> you want to remove.

    Their might be a function for that though, you should look through the string functions documentation.

  13. I think what they mean is that it continues the session already started. It doesn't mean that you can do session_start() twice at the same time (eg. in the same script. So what they mean with resuming is a session that was started the previous time the script was loaded.

    In my CMS I have session_start() (well new Session(); actually, as you can see in the session class I posted) at the top of the main script:

    $session = &new Session();

    the same as

    session_start();

    So just put this at the top of your main script/php file and all should be well.

    If not the problem is your installation, maybe sessions aren't configured (check php.ini).

  14. Well it is forbidden in Belgium. In Spain it is/was too, Salvador Dali sat in prison for a while because he burned the Spanish flag in Madrid.

    Really, I think it's rediculous that people make such laws or amendments. As if it would stop people from being against the state. It's a matter of freedom of speech, it should be anyone's right to think good/bad/nothing about the state. If not you're evolving indeed to a totalitarian regime where only one opinion is allowed.

  15. Klaas:

    Nonsense, Klaas, that's just the nature of man. The fact is, you're very biased in your opinions. Now that is hard to discuss if you're acting as if evolution has been proved, and yet you have not presented conclusive evidence. You can go on and on about how there are only 2 kinds of scientists and all that, but this is a disscussion of whether or not evolution is true, not an "evolutiontruesoletsdisscusswhatkindofscientistsareoutthere" disscussion, because that is your opinion.

    Well we're all biased here, that's not the point of discussion.

    I'm not acting as if evolution has been proved, what I'm telling is that science is based on deduction, observation and reasoning, that's the way how theories like evolutionism were created. You make it sound as if evolution was invented by atheist scientists who wish to find an alternative to the creationist belief.

    Really, just like at Darwin's theories. There isn't one scientist on this planet that would say Darwin was absolutely right, simply because the evolutionist theory has evolved. Scientific theories simply adapt to new observations or findings, they aren't set in stone as opposed to the Bible.

    I don't know much about science but I do know a bit about historical science which is quite related. The thing with historians too is that there are two types: those who are serious about their profession and those who abuse it (either for their ideology or career).

    The best thing to illustrate it is 19th century historical research. What historians did back then was using their ideology as the base for their historical research. I'll use such an ideological axiom as example: Belgium and the urge to create this country has been existing among the Belgian people for many years before the Belgian revolution.

    So, they take this axiom and then the historian takes the sources and tries to use the sources to prove this axiom. That's extremely easy, but it's a fallacy.

    Modern age historians don't (or shouldn't) do that. They first take the sources and from the sources they create a theory, and that's how science works.

    So I hope you see the similarity with the science vs. creationism discussion. Science goes from observations and then theories are written. Creationism however starts with the Bible, and observations or fallacies in scientific theories are used to prove the Bible is right.

    Whoa, whoa, whoa. First of all, that is not just a "bit wild", but very, very wild. It's absolutely not safe to say that. Frankly, not even 25% of the earth has been excavated, and if even if it was, that would leave 75% of the earth unexcavated, and 75% of the earth can hold quite a bit of fossils, as you can guess. Secondly, you just commited a "two wrongs make a right" fallacy, (clicky[) which is not very good. Or simply, it's blameshifting.

    It is absolutely safe to say that because no exceptions have been found, yet. If they are ever found the theory should be adapted indeed. Again, that's how science works. The theory isn't written in stone, it will be adapted to new findings.

    And I'm not trying to use the two wrongs make a right. I'm illustrating that you're turning it upside down: it is creationism that's doing this, since they only have the Bible as proof and the theory is written in stone. It won't and will never be adapted to new findings.

    Of course Yiuel was trying to make a point, I think that's what we're all trying to do. Right... like we have tons of stuff to use to date with that died before the 1940's... that doesn't make a very strong argument. So remind me again: What is the core issue here? Is it the geologic column? Or evolution? But let me ask you something: Where did Yiuel get that info anyway? Or I could ask Yiuel...

    We do have tons of stuff to use to date that died before the 1940s and it does make a strong argument. If it works, it works, so care to explain why it doesn't instead of calling it a weak argument.

    I don't know where Yiuel got his info, maybe he just didn't take that into account?

    First of all, C-14 is produced in the atmosphere when cosmic rays hit oxygen and nitrogen. Here's some more info.

    http://www.creation-science-prophecy.com/C14b.htm

    http://www.vuletic.com/hume/cefec/2.html#2_6

    Seems it remains almost constant.

  16. You know, what you really need is some kind of page controller mechanism. Usually this is accomplished with complicated classes and such, but to give a very easy version:

    Let's say someone accesses your site:

    http://www.mysite.com/index.php

    this gives the frontpage

    http://www.mysite.com/index.php?display=login

    this is the login page

    http://www.mysite.com/index.php?display=page&id=5

    this displays the page with id 5 in the database

    The core of your script would do this:


    switch ($_GET['display'])
    {
    case 'login':
    admin_login();
    case 'page':
    process_page($_GET['id']);
    case 'logout':
    admin_logout();
    default:
    frontpage();
    }

    So what it does is calling a function based on the display variable. What I'm showing is extremely basic of course but it really separates the things that your script is doing, instead of doing everything in one function or script.

  17. Well that explains everything. You are making a call to both admin_login and admin_logout here:


    $page[1] = str_replace ("[admin_login]", admin_login ($database), $page[1]);
    $page[1] = str_replace ("[admin_logout]", admin_logout ($database), $page[1]);

    Doing that will execute all the code in both those functions, not only return the data.

    btw thanks for the rep :D

  18. Is that open source? I like Filezilla myself, it is a great program, I just dunno about an FTP server...

    http://filezilla.sourceforge.net/

    As the text on the page sais:

    "FileZilla is a fast and reliable FTP client and server with lots of useful features and an intuitive interface."

    dunno how to use the server though. But IIRC XAMPP had something called Filezilla server, you might want to look into that:

    http://www.apachefriends.org/

  19. But I don't see any code related to admin_logout or admin_login in index.php, not even a require or include. Could you give the code or page where you are implementing or including/requireing these login/logout functions?

    You must have made an error in another file.

    Btw, could you test your script on a real server? It could also be related to your own php installation on windows.

  20. Oh yeah, it is still telling me the destruction of the session has failed even though I have not called the function, how do I sort taht out?

    Could you give the code of the page that outputs the error? It can't be index.php I think since it doesn't contain any code related to sessions.

  21. Klaas:

    I never said it was a conspiracy, Klaas. I believe this is what Mythos would call a "strawman argument." (clicky) By the way, the "Evolution v Creation" issue needs to be correctly called "Naturalism v Theism", not "Science v Religion."

    I said that in reply to this:

    Evolutionist scientists (In general) do not want to believe that God created them and that they have a responsibility to him. There is always something else to believe than Creationism, and they would rather believe that then Creationism.

    So if what you wrote would be true this implies that those so-called evolutionist scientists form some kind of conspiracy to push their atheist agenda.

    Anyway, it's not easy to discuss something if you don't answer the argument itself: that there are no evolutionist scientists but only scientists just doing their job and scientists looking for a career.

    It has happened that an archaeologist found a site with remains of some kind of humanoid and immediatly claimed that they were the oldest remains. That is just a scientists looking for a career, not a serious one. That isn't based on attacked creationism but based on getting famous as a scientist. So it has absolutely nothing to do with creationism vs evolutionism, that's just something creationists invented.

    That's a very wild claim, Klaas. So, you've searched everywhere on earth for these remains, or you know someone who's searched everywhere on earth for these remains, or you know a collection of people who have searched everywhere on earth for these remains?

    It is a bit wild but at this point it's very safe to say that. It isn't as wild as what creationists do since they have absolutely no proof for their theories except the Bible which cannot be considered as a relieable source in historical criticism.

    Anyway if they ever find remains of home sapiens sapiens that are that old science will just adapt its theories to it, that's the way science works.

    Let's take a quote from Yiuel here:

    And try to reconcile it to the website you suggested: here. It says, and I quote: Now you can also say that since radioactivity is such a problem, guess where all the lead can from? We have lost almost half of our uranium deposits to radioactive decay, and that is quite a bit of radioactive material, and it probably affects Carbon dating, if anything does.

    I believe Yiuel was only trying to make a point, but it indeed failed by using our own bones as an example. Anyway, if he said the bones of something that died before radioactive tests his argument is correct, so maybe take your time answering that instead of pointing out the little errors. Again, it's not easy to discuss something if you're neglecting the core of the argument.

    Now we can also take this one here, from the site that Mythos Ruler gave us, which can be found here:

    Nevertheless, even if earth's magnetic field is not decreasing, they claim it is fluctuating. This means that Carbon-14 production is also fluctuating!

    Hmmm, where does it say that this is related to C-14 dating?

  22. Well, I'm absolutely not sure but in admin_login.php I see that you're destroying the session when a session hasn't been started. It's at this comment:

    // Session data is not valid, destroy session and start again

    So you should have session_start() at the beginning of the script I think.

    There are better methods for login/logout than that though. Since your script is so big you're taking the risk that you might oversee security flaws.

    I suggest your read the sample chapters of this book:

    http://www.sitepoint.com/books/phpant1/

    I've used those methods provided there and it's really useful.

    Here's how I did it:


    <?php
    /*****************************************************************************
    * Algemeen Boerensyndicaat Website
    * File: includes/auth.php
    * Desc: authentication class
    * Date: 21-07-2004
    * Author and Copyright: Klaas Van Waesberghe
    * Client: Algemeen Boerensyndicaat
    *****************************************************************************/

    // security measure preventing script being executed when not allowed
    if (!defined('IN_ABS')) {
    exit('Toegang geweigerd');
    }

    class Auth {
    var $db;
    var $session;
    var $hashKey;
    var $md5;
    var $config = array();
    var $error;

    function Auth (&$db, $hashKey, $config, &$session, $md5 = true) {
    $this->db = &$db;
    $this->config = $config;
    $this->hashKey = $hashKey;
    $this->md5 = $md5;
    $this->session = &$session;
    $this->login();
    } // END Auth()

    function login () {
    if ($this->session->get('login_hash')) {
    $this->confirmAuth();
    return;
    }

    if (isset($_COOKIE[USER_LOGIN_VAR]) AND isset($_COOKIE[USER_PW_VAR]) AND $_COOKIE[USER_LOGIN_VAR] != '0' AND $_COOKIE[USER_PW_VAR] != '0') {
    $this->md5 = false;
    $_POST[USER_LOGIN_VAR] = $_COOKIE[USER_LOGIN_VAR];
    $_POST[USER_PW_VAR] = $_COOKIE[USER_PW_VAR];
    }

    if ($this->session->get(USER_MULTI_LOGIN) == USER_MAX_LOGIN) {
    @setcookie(USER_MULTI_LOGIN, '1', time()+600, '/', $this->config['cookie_domain']);
    $this->session->del(USER_MULTI_LOGIN);
    $this->error = '0';
    return;
    }

    if (isset($_COOKIE[USER_MULTI_LOGIN])) {
    $this->error = '0';
    return;
    }

    if (!isset($_POST[USER_LOGIN_VAR]) || !isset($_POST[USER_PW_VAR])) {
    $this->error = '1';
    return;
    }


    if ($this->md5) {
    $password = md5($_POST[USER_PW_VAR]);
    }
    else {
    $password = $_POST[USER_PW_VAR];
    }

    $login = safe_input($_POST[USER_LOGIN_VAR]);
    $password = safe_input($password);

    $sql = "SELECT COUNT(*) AS num_users
    FROM " . DB_MEMBERS_TBL . "
    WHERE
    " . DB_MEMBERS_TBL_LOGIN . "='$login' AND
    " . DB_MEMBERS_TBL_PW . "='$password'";

    $result = $this->db->Query($sql);
    $row = $result->fetch();

    if ($row['num_users'] != 1) {
    // prevent too many logins
    if (!$this->session->get(USER_MULTI_LOGIN)) {
    $this->session->set(USER_MULTI_LOGIN, 1);
    }
    else {
    $multi_login = $this->session->get(USER_MULTI_LOGIN);
    $multi_login++;
    $this->session->set(USER_MULTI_LOGIN, $multi_login);
    }
    // end prevent too many logins
    $this->error = '2';
    return;
    }
    else {
    $sql = "SELECT usr_id, " .DB_MEMBERS_TBL_LOGIN. ", " .DB_MEMBERS_TBL_PW. "
    FROM " . DB_MEMBERS_TBL . "
    WHERE
    " . DB_MEMBERS_TBL_LOGIN . "='$login' AND
    " . DB_MEMBERS_TBL_PW . "='$password'";
    $result = $this->db->Query($sql);
    $row = $result->fetch();
    $id = $row['usr_id'];
    $this->storeAuth($login, $password, $id);
    }

    } // END login()

    function storeAuth($login, $password, $id) {
    $login = safe_output ($login);
    $password = safe_output ($password);
    $this->session->set(USER_LOGIN_VAR, $login);
    $this->session->set(USER_PW_VAR, $password);
    $this->session->set(USER_ID_VAR, $id);
    $hashKey = md5($this->hashKey . $login . $password . $id);
    $this->session->set('login_hash', $hashKey);

    if ($this->session->get(USER_MULTI_LOGIN)) {
    $this->session->del(USER_MULTI_LOGIN);
    }

    if (!isset($_POST[USER_COOKIE_VAR])) {
    $_POST[USER_COOKIE_VAR] = '0';
    }
    if ($_POST[USER_COOKIE_VAR] == '1') {
    @setcookie(USER_LOGIN_VAR, $login, time()+31536000, '/', $this->config['cookie_domain']);
    @setcookie(USER_PW_VAR, $password, time()+31536000, '/', $this->config['cookie_domain']);
    }
    } // END storeAuth()

    function confirmAuth() {
    $login = $this->session->get(USER_LOGIN_VAR);
    $password = $this->session->get(USER_PW_VAR);
    $id = $this->session->get(USER_ID_VAR);
    $hashKey = $this->session->get('login_hash');
    if (md5($this->hashKey . $login . $password . $id) != $hashKey) {
    $this->error = '3';
    $this->logout();
    }
    } // END confirmAuth()

    function logout() {
    $this->session->del(USER_LOGIN_VAR);
    $this->session->del(USER_PW_VAR);
    $this->session->del(USER_ID_VAR);
    $this->session->del('login_hash');
    $this->session->destroy();
    @setcookie(USER_LOGIN_VAR, '0', time()+31536000, '/', $this->config['cookie_domain']);
    @setcookie(USER_PW_VAR, '0', time()+31536000, '/', $this->config['cookie_domain']);
    $this->error = '4';
    } // END logout()

    function isError() {
    if (empty($this->error)) {
    return false;
    }
    else {
    return true;
    }
    } // END isError()

    } // End Auth
    ?>

    To implement it (really, that's all you need):


    $db = &new MysqlDB($config);
    $session = &new Session();
    $auth = &new Auth($db, 'your favorite hashstring here', $config, $session);
    if ($auth->isError()) {
    // here goes the code for people who're not logged in
    }
    else {
    // here goes the code for people who're already logged in
    }

    Now, that MysqlDB class and Session class is this code:


    <?php
    /*****************************************************************************
    * Algemeen Boerensyndicaat Website
    * File: includes/mysql.php
    * Desc: mysql db class
    * Date: 20-07-2004
    * Author and Copyright: Klaas Van Waesberghe
    * Client: Algemeen Boerensyndicaat
    *****************************************************************************/

    // security measure preventing script being executed when not allowed
    if (!defined('IN_ABS')) {
    exit('Toegang geweigerd');
    }

    class MysqlDB {
    var $host;
    var $user;
    var $db;
    var $pw;
    var $error;
    var $dbConn;
    var $query_count;


    function MysqlDB ($cfg_db) {
    $this->host = $cfg_db['db_host'];
    $this->user = $cfg_db['db_user'];
    $this->db = $cfg_db['db_name'];
    $this->pw = $cfg_db['db_pw'];
    $this->query_count = 0;

    $this->_Connect();
    } // END MysqlDB

    function _Connect() {
    // Make connection to MySQL server
    if (!$this->dbConn = @mysql_connect($this->host, $this->user, $this->pw)) {
    $this->error = 'FOUT: Verbinding met database geweigerd';
    exit ($this->error);
    // Select database
    }
    elseif (!@mysql_select_db($this->db, $this->dbConn)) {
    $this->error = 'FOUT: De database kon niet geselecteerd worden';
    exit ($this->error);
    }
    } // END Connect

    function &Query($sql) {
    if (!$queryResource = mysql_query($sql, $this->dbConn)) {
    $this->error = 'FOUT: Database query mislukt:' . $sql;
    $sql_error = mysql_error ();
    exit ($sql_error.'<br />'.$this->error);
    }
    else {
    $this->query_count++;
    return new MySQLResult($this, $queryResource);
    }
    } // END Query

    function IsError() {
    if (empty($this->error)) {
    return false;
    }
    else {
    return true;
    }
    } // END IsError

    function get_query_count () {
    $count = $this->query_count;
    $this->query_count = 0;
    return $count;
    }

    } // END MysqlDB

    class MySQLResult {
    var $mysql;
    var $query;

    function MySQLResult(&$mysql, $query) {
    $this->mysql = &$mysql;
    $this->query = $query;
    } // END MYSQLResult

    function fetch() {
    if ($row = mysql_fetch_array($this->query, MYSQL_ASSOC)) {
    return $row;
    }
    else if ( $this->num_rows() > 0 ) {
    mysql_data_seek($this->query, 0);
    return false;
    }
    else {
    return false;
    }
    } // END fetch

    function num_rows() {
    return mysql_num_rows($this->query);
    } // END fetch

    function isError() {
    return $this->mysql->isError();
    } // END isError
    } // END MYSQLResult
    ?>


    <?php
    /*****************************************************************************
    * Algemeen Boerensyndicaat Website
    * File: includes/session.php
    * Desc: session class
    * Date: 20-07-2004
    * Author and Copyright: Klaas Van Waesberghe
    * Client: Algemeen Boerensyndicaat
    *****************************************************************************/

    // security measure preventing script being executed when not allowed
    if (!defined('IN_ABS')) {
    exit('Toegang geweigerd');
    }

    class Session {

    function Session () {
    session_start();
    }

    function set ($name, $value) {
    $_SESSION[$name] = $value;
    }

    function get ($name) {
    if (isset($_SESSION[$name])) {
    return $_SESSION[$name];
    }
    else {
    return false;
    }
    }

    function del ($name) {
    unset($_SESSION[$name]);
    }

    function destroy () {
    $_SESSION = array();
    session_destroy();
    }
    }
    ?>

    The config variabeles and constants are just things declared first, so that something you do yourself.

×
×
  • Create New...