Jump to content

chriscloyd

Members
  • Posts

    488
  • Joined

  • Last visited

Posts posted by chriscloyd

  1. My Login Script is not working! Please someone help.  I am typing in the correct email and password!

    Mysql Table

    Table - Users

    email varchar 100

    password varchar 256

     

    form

    
    

    action/members.php

    <?php
    session_start();
    include("../config.inc.php");
    include("../classes/class.action.php");
    if ($_POST['login'] && $_POST['*****'] == '*****') {
    $info = array();
    $info['email'] = $_POST['email'];
    $info['password'] = hash("sha256", $_POST['password']);
    if ($Action->Login($info)) {
    	$_SESSION['CPLoggedIn'] = $_POST['email'];
    	header("Location: ../index.php");
    } else {
    	$Error[] = '- Please check you email and password!';
    	$_SESSION['CPErrors'] = $Error;
    	header("Location: ../index.php?action=LoginForm");
    }
    }
    

    classes/class.actions.php

    <?php
    class Action {
    
    var $Erros = array();
    
    function Login($info) {
    	foreach ($info as $key => $val) {
    		if ($key = "password") {
    			$$val = mysql_real_escape_string($val);
    			$password = hash("sha256", $val);
    			$values[$key] = $password;
    		} else {
    			$values[$key] = mysql_real_escape_string($val);
    		}
    
    	}
    
    	$Sql = "SELECT * FROM Users WHERE email = '{$values['email']}' AND password = '{$values['password']}'";
    	$Query = mysql_query($Sql);
    	$Num = mysql_num_rows($Query);
    	if ($Num > 0) {
    		return true;
    	} else {
    		return false;
    	}
    }
    }
    $Action = new Action;
    

  2. Question why are you putting () around your var?

    Where are you setting the var $ids?

    try this

    <?php
    $sqlout = mysql_query("SELECT * FROM `tblt` WHERE `UID` = '{$ids}'");
    while ($sqlres = mysql_fetch_assoc($sqlout)) {
         //you can use assoc or array
         //I just like using assoc
    }

  3. Do you know how sites like YouTube or even Google Analytics does it? Surely, there must be a way that's fairly accurate.

     

    Not really. You can have a single user that uses multiple IPs (work/home or gets a different IP from his provider) or you have have multiple users behind the same IP using NAT. So, using the IP address is not guaranteed. Using cookie is a little better, IMHO. But, you would get multiple hits if the same user views the same content on different machines. Also, a user could delete their cookies and that would incur an additional hit if they viewed the same content after deleting the cookie. And then there are those that set their browsers to not accept cookies which would generate a hit on every view since you wouldn't be able to set a cookie to exclude them in the future.

     

    As scootstah a login system would probably be the most reliable, but even that isn't foolproof. A user could create another account and view the same content again, which would trigger another hit.

     

    It all depends on exactly what you ar trying to ascertain from the data that should guide you in deciding the best method.

     

    Couldn't you use the ip, if you give each person a unique session attached with with ip?

  4. I dont know if this will work but there are two options you can do that works for me



    <?php
    session_start();
    // dBase file
    include "../admin/config.php";
    $User = mysql_real_escape_string($_POST["username"]);
    $Pass = mysql_real_escape_string($_POST['password']);
    if ($User == '' || $Pass == '' ?) {
    die("You need to provide a username and password.");
    } else {
    // Create query
    $q = "SELECT * FROM `nm_users` WHERE `username`='{$User}' AND `password`=PASSWORD('{$Pass}') LIMIT 1";
    // Run query
    $r = mysql_query($q);
    //you can do it two ways to make sure your even getting anything back
    $num = mysql_num_rows($r);
    if ($num > 0) {
    $obj = mysql_fetch_object($r);
    // Login good, create session variables
      $_SESSION["valid_id"] = $obj->id;
      $_SESSION["valid_user"] = $obj->username;
      $_SESSION["valid_time"] = time();

      // Redirect to member page
    Header("Location: members.php");
    } elseif ($r) {
    //or you can do this
    $obj = mysql_fetch_object($r);
    // Login good, create session variables
      $_SESSION["valid_id"] = $obj->id;
      $_SESSION["valid_user"] = $obj->username;
      $_SESSION["valid_time"] = time();

      // Redirect to member page
    Header("Location: members.php");
    } else {
      // Login not successful
      die("Sorry, could not log you in. Wrong login information.");
    }
    }
    [/Code]

  5.  
    <?php
    $users = $_POST['user'];
    foreach ($users as $key => $val) {
    $sql = "INSERT INTO options (`item_id`, `option`) VALUES ('{$key}', '{$val}' )";
    $rs = mysql_query($sql) or die ("Problem with the query: {$sql} <br />" . mysql_error());
    }
    ?>
    [/Code]

     

  6. Here create a new mysql table


    CREATE TABLE IF NOT EXISTS `pageviews` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `pageid` int(11) NOT NULL,
      `user` varchar(100) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

    [/Code]

    Here is some php code that could help with your problem

    [Code]
    <?php
    //top of your page
    session_start();
    if (!isset($_SESSION['user']) || !isset($_SESSION['guest'])) {
        $ip = $_SERVER['REMOTE_ADDR'];
        $time = date("Y-m-d H:i:s");
        $guest = "{$ip}.{$time}";
        $_SESSION['guest'] = $guest;
    }
    //define page id somehow
    $pageid = '';
    //now for you page update
    //first check to see if they have view it or not
    $User = (isset($_SESSION['user']) ? $_SESSION['user'] : $_SESSION['guest']);
    $Sql = "SELECT * FROM pageviews WHERE user = '{$User}' AND pageid = '{$pageid}' ";
    $Query = mysql_query($Sql);
    $Num = mysql_num_rows($Query);
    if ($Num < 1) {
    mysql_query("UPDATE SET page
        views=views+1
        WHERE id=1")
    or die(mysql_error());
    }
    ?>
    [/Code]

  7. well a couple things you can do.

    1. ) If the client is not logged in as a user, make a session that is unique like their ip address plus a current time stamp.  so that way whatever they do while under guest they can be logged.

    Table Views

    vID int(11) primary auto

    pageID int(11)

    user varchar(100)

    every time a user views it insert a new row into the table

    but before you update the views check to see if the user has already viewed this page by taking that new session created for all guest and matching it up with the pageid of the page they are viewing and the user row

  8. I have a login form at

    http://cloydprojects.com

    you can login with

    username: test

    password test

    If you login the script works correctly, but if you type in the wrong info my session is not showing here is that I have.

    my login script

    <?php
    session_start();
    ?>
    <link href="signUp.css" rel="stylesheet" type="text/css" />
    <?php
    include("db.php");
    include("classes/class.account.php");
    $Acc = new account;
    $u = $Acc->clean($_REQUEST['usernameLogin']);
    $password = $Acc->clean($_REQUEST['passwordLogin']);
    $p = md5($password);
    $get = mysql_query("SELECT * FROM users WHERE username = '".$u."' and password = '".$p."'");
    $find = mysql_num_rows($get);
    if ($find == 1) {
    $info = mysql_fetch_assoc($get);
    $_SESSION['LoggedIn'] = $info['uID'].'.'.$info['username'].'.'.$info['email'];
    } else {
    $_SESSION['LoggedFailed'] = '<div id="ErrorBox">Incorrect username/password!</div>';
    } 
    //there is more just not showing it
    

    here is my index script where the error should be showing!

    <div class="stylized">
    <?php if(isset($_SESSION['LoggedIn'])) {
    echo '<h1> Welcome! </h1>';
    echo '<a href="logout.php">logout!</a>';
    } else {
    echo $_SESSION['LoggedFailed'];
    session_destroy();
    ?>
        <form id="instantform" name="form" action="loginUser.php" method="post">
    
        <h1>Login</h1>
        
        <label>Username
        <span class="small">The username you created!</span></label>
        <input type="text" name="usernameLogin" id="usernameLogin" />
        
        <label>Password
        <span class="small">Case sensitive!</span></label>
        <input type="password" name="passwordLogin" id="passwordLogin" />
        
        <button type="submit">Login</button></div>
        <div class="spacer"></div>
        
        </form>
        <?php
    }
    
    ?>
    </div>
    

  9. can someone help me I am trying to call a class function using a varible.... example

    say i go to index.php?page=contact i want to pull that class with out doing a switch statement can someone help me

    <?php
    $Site = page;
    $Site->getPage($_GET['page']);
    ?>
    

    <?php
    class page extends site {
    
    function getPage($page) {
    	return $this->$page;	
    }
    function Contact() {
    	echo '<h2>Contact test</h2>';
    	echo '<form>
    
    	</form>';
    }
    
    }
    ?>

  10. Could it be that when it goes to the login page its starting a new one here my index.php

    <?php
    
    /**
    * @author Chris Cloyd
    * @copyright 2011
    */
    /** Session Start For Users */
    session_start();
    /** Load Config */
    include("load/config.php");
    /** Load Class.Site and Class.Reminder */
    include("load/class.site.php");
    include("load/class.reminder.php");
    include("load/class.users.php");
    /** Start Classes */
    $Site = new site();
    $Reminder = new reminder();
    $Users = new users();
    /** Start Html by loading $Site->DisplayHeader(); */
    $Site->DisplayHeader();
    echo $Users->user;
    /** Load Middle Content by loading $Site->DisplayContent(); */
    if (isset($_GET['page'])) {
        $Site->DisplayContent($_GET['page']);
    } else {
        $Site->DisplayContent('login');
    }
    /** End Html by loading $Site->DisplayFooter(); */
    $Site->DisplayFooter();
    ?>
    

     

    login.php

    <?php
    
    /**
    * @author Chris Cloyd
    * @copyright 2011
    */
    /** Session Start For Users */
    session_start();
    /** Load Config */
    include("../load/config.php");
    /** Load Class.Site and Class.Reminder */
    include("../load/class.site.php");
    include("../load/class.reminder.php");
    include("../load/class.users.php");
    /** Start Classes */
    $Site = new site();
    $Reminder = new reminder();
    $Users = new users();
    
    $email = mysql_escape_string($_POST['emailLogin']);
    $password = mysql_escape_string($_POST['passwordLogin']);
    $password = md5($password);
    
    $Search = mysql_query("SELECT * FROM users WHERE email = '".$email."' AND password = '".$password."' ");
    $Found = mysql_num_rows($Search);
    if ($Found > 0) {
        $UserInfo = mysql_fetch_assoc($Search);
        if ($UserInfo['status'] != 1) {
            $_SESSION['umadBroEmail'] = $email;
            header("Location: http://cloydprojects.com/index.php?page=activate");
        }
        $Users->LogIn($UserInfo['name'],$UserInfo['email'],$UserInfo['level']);
        echo $Users->user;
        $_SESSION['umadBro'] = $UserInfo['name'];
        //header("Location: http://cloydprojects.com/index.php?page=home");
    } else {
        $_SESSION['umadBroError'] = 'Incorrect User Information, Try Again!';
        //header("Location: http://cloydprojects.com/index.php?page=login");
    }
    
    ?>
    

  11. i have two classes and I am trying to call one class in through another here is my code but my welcome is not showing at all ever when i change the var's to 1

    class site {
         function DisplayContent ($page) {
            global $Users;
            echo '<div align="center">
                    <div id="Header">
                    <div id="NavBar">';
                    if ($Users->logged == 1) {
                        echo 'Welcome '. $Users->user .' - <a href="?page=viewreminders">View Reminders</a> - <a href="?page=addreminder">Add Reminder</a> - <a href="logout.php" id="Logout">Logout</a>';
                    } else {
                        echo '<a href="?page=login">Login</a> - <a href="?page=register">Register</a> - <a href="?page=forgotpassword">Forgot Password?</a>';
                    }
            echo '</div>
                </div>
                <div id="Content">';
                $this->ShowPage($page);
                echo '</div>
                <div id="Footer">Copyright © '.date('Y').'<br />
                Coded and Designed by Chris Cloyd</div>
            </div>';
         }
    }
    
    class users {
        
        var $logged;
        var $user;
        var $email;
        var $level;
        
        function LogIn ($name,$email,$level) {
            $this->logged =  1;
            $this->user = $name;
            $this->email = $email;
            $this->level = $level;
        }
        
        function LogOut () {
            $this->logged =  "0";
            $this->user = "";
            $this->email = "";
            $this->level = "";
        }
        
    }
    

  12. <html>
    <head>
    	<title>Login</title>
    </head>
    <body>
    	<hr />
    	<form method="post" action="">
    		<label>Username:</label>
    		<input type="text" name="username">
    		<br />
    		<label>Password:</label>
    		<input type="password" name="password">
    		<p>
    			<input type="submit" value="Login" name="Login" />
    			<input type="reset" value="Reset" name="Reset" />
    		</p>
    
    	</form>
    <?php
    //if username/password filled in and submitted, check db to find match login info
    if(array_key_exists("Login",$_POST) && !empty($_POST["username"]) && !empty($_POST["password"])) {
    	$attemptedUsername=$_POST["username"];
    	$attemptedPassword=crypt($_POST["password"]);
    
    	mysql_connect("localhost","root");
        mysql_select_db("db");
    
    	$getLoginInfoQuery=mysql_query("SELECT userName,userPassword FROM users WHERE userName='$attemptedUsername' AND userPassword='$attemptedPassword'");
    	$getLoginInfo=mysql_fetch_assoc($getLoginInfoQuery);
    	$getUsername=$getLoginInfo["userName"];
    	$getPassword=$getLoginInfo["userPassword"];
    
    	if($attemptedPassword==$getPassword) {
    		session_start();//NB: Start session BEFORE doing any session stuff!
    		$_SESSION["isAuthenticated"]="userAuthenticated";
    		header("Location: SecureSite.php");
    		exit;
    	}
    	else//"Please register above!"
    		print "Please register above!";
    }
    ?>
    </body>
    </html>
    

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