Jump to content

Northern Flame

Members
  • Posts

    816
  • Joined

  • Last visited

    Never

Posts posted by Northern Flame

  1. heres one problem i found,

     

    if($_SESSION['loggedin'] == 1) {
       header('Location: home');
    } 
    

     

    $_SESSION['loggedin'] is not even set yet so its going to default to NULL and later on in the code it is set to 1,

    that is why it gives you an error message first and then lets you log in....try this:

     

    <?php
    session_start();
    
    
    //This code runs if the form has been submitted
    if (isset($_POST['submit'])) { 
    
    include("includes/dbconnect.php"); 
    
    // Define $username and $password 
    $username= $_POST['username']; 
    $password= md5($_POST['password']); 
    
    // To protect MySQL injection
    $username = stripslashes($username);
    $password = stripslashes($password);
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string($password);
    
    // Retrieve username and password
    $sql="SELECT * FROM users WHERE username = '$username' AND password = '$password'";
    $result = mysql_query($sql);
    
    // Mysql_num_row is counting table row
    $count = mysql_num_rows($result);
    
    // If result matched $username and $password, table row must be 1 row
    
    if($count == 1){
    
    
    // retrieve userid from database 
    $sql = "SELECT id FROM users WHERE username = '$username' AND password = '$password'"; 
    $result = mysql_query($sql);
    
    while ($row = mysql_fetch_assoc($result)) {
       $userid = $row["id"];
    }
    
    // update lastlogin
    $llsql = "UPDATE users SET lastlogin = now() WHERE id = '$userid' AND username = '$username'";
    $llresult = mysql_query($llsql);
    
    $_SESSION['loggedin'] = '1';
    $_SESSION['userid'] = $userid;
    $_SESSION['username'] = $username;
    
    header("Location: home");
    unset($_POST['username']);
    }else {
    $message = '<div class=red><b>An error has occured.</b> Please check that you are using a valid username/password combination.</div>';
    }
    
    if($_SESSION['pleaselogin'] == 1) {
       $message = '<div class=red><b>An error has occured.</b> You must be logged in to view this page. Please login below.</div>';
       $_SESSION['pleaselogin'] = '0';
    }
    
    if($_SESSION['loggedin'] == 1) {
       header('Location: home');
    } 
    }
    
    include ("includes/nologin.php");
    include ("includes/header.php");
    ?>
    
    <img src="i/titles/login.png"><br>
    Please login to your account to participate in our plot, <i>'the Mutated Moach'</i>. If you do not have an account and would like to participate, feel free to <a href="register">create</a> one.<br>
    <div class="regvalidate"><?php print $message; ?></div>
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    
    <center><div class="logtable logfont"><table><br>
    <div style="text-align:left;">Username:</div>
    <input name="username" type="text" value="<?php echo $_POST['username'];?>" class="regbox"><br><br>
    <div style="text-align:left;">Password:</div>
    <input name="password" type="password" class="regbox"><br>
    <input type="submit" name="submit" class="regsend" value="Login" style="margin: 25px 35px;">
    </table></div>
    
    </form></center>
    
    <?php include ("includes/footer.php"); ?>
    

  2. yea i probably should have mentioned that haha. well i do enjoy doing server side coding that is why i mentioned asp.net

    i know i would probably have to go to school for that since i cant find any good  tutorials for that online. i guess what i was

    wondering was what which would benefit me more, which language is there a greater need for out in the job market. I do know

    that a asp.net programmer would make a lot more than a php programmer would make, but are languages like C & C++ in greater

    demand?

  3. i used 2 be really active on this website but about a year ago i joined the army,

    lately i have been thinking about my future after the army and thought about going

    to college and studying some programming languages, but my only problem is that

    im not sure which language would help me out the most career wise. I am already

    proficient in HTML, CSS, Javascript, and PHP/AJAX. Im thinking about studying

    languages like C & C++ or maybe even asp.net or pearl. any ideas as to which would

    benefit me the most?

  4. I know how to make search scripts in PHP,

    but can someone help me with making a script that will search for certain

    database entries that are either 5 10 or 15 miles from a zip code?

    Im guessing im going to have to have a huge list of zip codes in a database.

    hopefully i can find something on google with a huge list of zip codes, but

    if i end up getting a big list of zip codes, how can i search the locations in my

    database that are a certain distance from those zip codes? or do I even need a

    database full of zip codes? is there an easier way?

    if someone can help me out with this or show me a tutorial on this I would greatly

    appreciate it!

  5. I am developing a social networking site and i am finishing up the user profiles.

    I am currently working on the friends list of the user, but I am having trouble

    finding a way to have the friends table and on grabbing the data. Currently the

    table is like this:

     

    id

    friends

    sent

    pending

     

    id - the id of the user

    friends - list of ids of users on friends list, ex: 1,34,65,32,11

    sent - list of ids of users that current user has sent friend requests to

    pending - list of ids of users that have requested this user as a friend

     

    the problem I am having is with grabbing the information of each friend on

    the friends list when displaying the current users friends. The page will have

    pagination, it will only display about 20 users per page.

     

    I am wondering if I should do something like this:

    <?php
    
    $q = mysql_query("SELECT `friends` FROM `friends` WHERE `id` = '$id'")or die(mysql_error());
    $f = mysql_fetch_object($q);
    $array = explode(",", $f->friends);
    
    foreach($array as $key => $fid){
    $query = mysql_query("SELECT `display`, `img`, `username` FROM `users` WHERE `id` = '$fid'";
    $object = mysql_fetch_object($query);
    
    echo ''; // here i echo the users info
    }
    
    

     

    now, is this the best way to do this?

    run 20 queries in  the foreach() loop or is there a better way?

     

    Please help,

    ive also considered rearranging my table but I cant find anything  that will really work out better

    than this solution.

  6. I am using the function htmlentities() to protect my website from people

    trying to post html on my website, and also I added the ENT_QUOTES

    option to the function so that it converts double quotes to &#34; and

    converts single quotes &#039; so is there a need for my to also use

    mysql_real_escape_string? I guess what Im asking is if mysql_real_escape_string()

    protects against more than single and double quotes.

  7. thanks ill give that a try

     

     

    2. Why do you use static methods (i.e. lyrics::search()) in this sense? They look like they use instance-level data... You might want to go over the OOP Section and look at methods once more.

     

     

    I didnt know it made a big difference. I thought lyrics::search() and $echo->search() did the same thing?

    the reason I use this method, lyrics::search(), is because a lot of the times the variables inside my classes

    are established and used inside the functions of the class and I never have to call them, so I hardly ever

    do stuff like:

    $echo = new lyrics;

     

    the only reason i did it in this case is because I needed to echo out the html that is generated in

    the functions.

     

    but for future reference, is there something wrong with doing it that way?

  8. put the array in a variable,

     

    $array = array(/* your array here*/);

     

    then change:

    $strQueryString = "filetype=tab&cateogry=ALL&manufacturer=ALL&invtype=both&columndata=Array&input=SUBMIT"

     

    to:

    $strQueryString = "filetype=tab&cateogry=ALL&manufacturer=ALL&invtype=both&columndata=$array&input=SUBMIT"

  9. I have a variable that is generated in the functions in my class,

    but for some reason, I can't pass that variable in my new function

    that is made outside of the class. Here's pretty much what I'm doing:

     

    <?php
    
    include('./../_CLASSES/lyrics/view.php');
    
    $echo = new lyrics;
    
    if(!isset($_GET['lyrics'])){
    	lyrics::search();
    } else{
    	lyrics::grabInfo(mysql_real_escape_string($_GET['lyrics']));
    	lyrics::getThisEdit();
    	lyrics::filterLyrics();
    	lyrics::makeHTMLfriendly();
    	lyrics::generateHTML();
    }
    
    function pageContent($html = $echo->html){
    	echo $html;
    }
    
    include('./../templates/'. $config['template'] .'/template.php');
    
    ?>
    

     

    I also tried:

     

    <?php
    
    include('./../_CLASSES/lyrics/view.php');
    
    $echo = new lyrics;
    
    if(!isset($_GET['lyrics'])){
    	lyrics::search();
    } else{
    	lyrics::grabInfo(mysql_real_escape_string($_GET['lyrics']));
    	lyrics::getThisEdit();
    	lyrics::filterLyrics();
    	lyrics::makeHTMLfriendly();
    	lyrics::generateHTML();
    }
    
    function pageContent($html = $echo){
    	echo $html->html;
    }
    
    include('./../templates/'. $config['template'] .'/template.php');
    
    ?>
    

     

     

    **Difference:

    1)

    function pageContent($html = $echo->html){

    echo $html;

    }

    2)

    function pageContent($html = $echo){

    echo $html->html;

    }

     

     

    heres the error I receive both times:

    Parse error: parse error, unexpected T_VARIABLE in /path/to/website.com/lyrics/view.php on line 17
    

     

    heres line 17:

    function pageContent($html = $echo->html){
    

     

    can anyone please help?

  10. I am developing a website and I have a directory, _CLASSES,

    and I want to be able to include files from that directory and all its

    sub-directories, but I dont want anyone to be able to view them.

    can anyone show me a tutorial on .htaccess that deals with things

    similar to this or can someone help me out by showing me how to do this?

     

    thanks

     

     

    Edit:

     

    I dont want it to require a password to view the files in it,

    but maybe show an error page when someone tries to access

    the files in that directory or in any of its sub-directories.

  11. the {} let you add in variables inside there to echo out with the HTML

     

    example:

    <?php
    
    $variable = "test";
    
    echo <<<HTML
    
    <div>
    <p>This is a {$variable}</p>
    </div>
    
    HTML;
    
    ?>
    

     

    and _TOTAL_NUMBERS must have been defined somewhere

     

    example:

    <?php
    
    define("_TOTAL_NUMBERS", 28);
    
    echo <<<HTML
    
    <div>
    <p>Your Total Number Is: {_TOTAL_NUMBERS}</p>
    </div>
    
    HTML;
    
    ?>
    

     

    the define() function sets things just like variables do except its a constant

    instead of a variable. read this:

     

    http://php.net/define

×
×
  • 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.