Jump to content

DeanWhitehouse

Members
  • Posts

    2,527
  • Joined

  • Last visited

Posts posted by DeanWhitehouse

  1. try this and tell me what it says.

    <?php
    
    
    if ($_SESSION['logged_in'] == true){
    ?>
    You are logged in.
    <?php
    }
    elseif($_SESSION['logged_in'] == false)
    {
    ?>
    You are not logged in.
    <?php
    }
    ?>

     

  2. this code was meant to check if the email is already in use but doesn't. why?

    <?php
    // Random Game Design: PHP Website Template
    //  Version 1
    //  Copyright Dean Whitehouse, 2008
    
    require_once 'db_connect.php';
    
    // Connect to database
    mysql_connect($dbhost,$dbuser,$dbpass)
    or die('Could not connect: ' . mysql_error());
    
    $user_name = $_POST["user_name"];		
    $user_password = $_POST["user_password"];		
    $user_password2 = $_POST["user_password2"];
    $user_email = $_POST["user_email"];		
    $user_email2 = $_POST["user_email2"];
    $ip = $_SERVER['REMOTE_ADDR'];
    $success = "/reg_success.php";
    
    if ($_SESSION['is_valid'] == false)
    {
    
    //if(isset($_POST['agree'])){
    if(isset($_POST['signup']))
    {
    	if ($user_name && $user_password && $user_password2 && $user_email && $user_email2)
    	{
    	$user_check = mysql_num_rows(mysql_query("SELECT * FROM $user WHERE user_name='$user_name' AND user_email='$user_email'"));
    		if ($user_check >= 1)
    		{
    		require_once 'register.php';
    		echo "Sorry, but the username or email you requested is already in use. Please enter a different username.";
    		}
    
    			elseif ($user_password == $user_password2 && $user_email == $user_email2)
    			{
    			$salt = substr($user_password, 0, 2);
    			$userPswd = crypt($user_password, $salt);
    			mysql_query("INSERT INTO `$user` (user_id,  user_name, user_password, user_email, user_ip, userlevel) VALUES 		('','$user_name','$userPswd','$user_email','$ip','2')")
    			or die('Error ' . mysql_error());
    			echo "Succesfully Registered. You will recieve a confirmation email shortly.";
    			header ("http://".$_SERVER[HTTP_HOST]."$success");
     			}
    				else
    				{
    				require_once 'register.php';
    				echo "Either the passwords or emails you entered do not match. Please check these details and try again";
    				}
    				}
    				 else 
    					{
    					require_once 'register.php';
    					echo "Please fill in all of the required fields.";
    					}
    }
    
    ?>
    <html>
    <table bgcolor='#999999' align='center' width="400px">
    <form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'>
    <tr><td width="10px">Username: </td><td><input type='text' name='user_name' maxlength="20" width="400px" /><br /></td></tr>
    <tr><td width="10px">Maximum Length<br /> 20 characters.</td></tr>
    <tr><td width="10px">E-mail Address:</td> <td><input type='text' name='user_email' /><br /></td></tr>
    <tr><td width="10px">Confirm E-mail Address: </td><td><input type='text' name='user_email2' /><br /></td></tr>
    <tr><td width="10px">Password:</td><td> <input type='password' name='user_password' maxlength="30" /><br /></td></tr>
    <tr><td width="10px">Maximum Length<br /> 30 characters.</td></tr>
    <tr><td width="10px">Confirm Password:</td><td> <input type='password' name='user_password2'  maxlength="30"/><br /></td></tr>
    <tr><td><input type='submit' value='Complete Registration' name='signup' /></td><td><input type="reset" value="Reset Fields" name="reset" /></td></tr>
    </form>
    </table>
    </html>
    <?php
    mysql_close();
    }
    else
    {
    header("Location:http://".$_SERVER[HTTP_HOST]);
    }
    ?>

    also the header under the echo "Succesfully Registered. You will recieve a confirmation email shortly."; doesn't do anything

  3. $user_check = mysql_num_rows(mysql_query("SELECT * FROM `$user` WHERE user_name='$user_name'"));

    i need this code to be this one , but work.

    $user_check = mysql_num_rows(mysql_query("SELECT * FROM `$user` WHERE user_name='$user_name' AND WHERE user_email='$user_email'"));

  4. ok,

    at the top of everypage put session_start();

     

    put this on the login page for when they login

    $_SESSION['logged_in] = true;

     

    then on the index page put

    if ($_SESSION['logged_in] == true)

    {

    // what ever the index page is

    }

    else

    {

    //what ever if there not logged in

    }

     

  5. its not a simple task, it will take some kind of database or flatfiles storage, and it take a fair bit of code.

    If you want i can email you some of the code you will need.

  6. the commented part doesn't work when i use it, and when i go the registration page it has the data from the remember me , although i used this to kill the cookie in the logout script

    logout.php

    <?php
    require_once 'db_connect.php';
    session_unset();
    session_destroy();
    setcookie("cookname", $_SESSION['username'], time() - 3600, "/");
    setcookie("cookpass", $_SESSION['user_password'], time() - 3600, "/");
    header("Location:http://".$_SERVER[HTTP_HOST]);
    ?>

  7. i

    <?php
    // Random Game Design: PHP Website Template
    //  Version 1
    //  Copyright Dean Whitehouse, 2008
    
    require_once 'db_connect.php';
    
    // Connect to database
    mysql_connect($dbhost,$dbuser,$dbpass)
    or die('Could not connect: ' . mysql_error());
    
    $user_name = $_POST["user_name"];		
    $user_password = $_POST["user_password"];		
    $user_password2 = $_POST["user_password2"];
    $user_email = $_POST["user_email"];		
    $user_email2 = $_POST["user_email2"];
    $ip = $_SERVER['REMOTE_ADDR'];
    //if(isset($_POST['agree'])){
    if(isset($_POST['signup'])){
    if ($user_name && $user_password && $user_password2 && $user_email && $user_email2)
    {
    	$user_check = mysql_num_rows(mysql_query("SELECT * FROM `$user` WHERE user_name='$user_name'"));	
    	if ($user_check >= 1)	
    {
    require_once 'register.php';
    	echo "Sorry, but the username you requested is already in use. Please enter a different username.";
    }
    
    elseif ($user_password == $user_password2 && $user_email == $user_email2)
    {
    $salt = substr($user_password, 0, 2);
    $userPswd = crypt($user_password, $salt);
    mysql_query("INSERT INTO `$user` (user_id,  user_name, user_password, user_email, user_ip, userlevel) VALUES ('','$user_name','$userPswd','$user_email','$ip','2')")
    or die('Error ' . mysql_error());
    header("Location:http://".$_SERVER[HTTP_HOST]);//header("Location:http://".$_SERVER[HTTP_HOST])"/login.php";
     }
    else
    {
    require_once 'register.php';
    echo "Either the passwords or emails you entered do not match. Please check these details and try again";
    }
    } 
    }
    else 
    {
    require_once 'register.php';
    echo "Please fill in all of the required fields.";
    }
    //}
    ;
    ?>
    <html>
    <table bgcolor='#999999' align='center' width="400px">
    <form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'>
    <tr><td width="10px">Username: </td><td><input type='text' name='user_name' maxlength="20" width="400px" /><br /></td></tr>
    <tr><td width="10px">Maximum Length<br /> 20 characters.</td></tr>
    <tr><td width="10px">E-mail Address:</td> <td><input type='text' name='user_email' /><br /></td></tr>
    <tr><td width="10px">Confirm E-mail Address: </td><td><input type='text' name='user_email2' /><br /></td></tr>
    <tr><td width="10px">Password:</td><td> <input type='password' name='user_password' maxlength="30" /><br /></td></tr>
    <tr><td width="10px">Maximum Length<br /> 20 characters.</td></tr>
    <tr><td width="10px">Confirm Password:</td><td> <input type='password' name='user_password2'  maxlength="30"/><br /></td></tr>
    <tr><td><input type='submit' value='Complete Registration' name='signup' /></td><td><input type="reset" value="Reset Fields" name="reset" /></td></tr>
    </form>
    </table>
    </html>
    <?php 
    mysql_close();
    ?>

     

    this is my registration code. this is a link to the page. http://deanwhitehouse.awardspace.co.uk/test/register.php

     

    this is my login code.

    <?php
    require_once 'db_connect.php';
    
    if ($_SESSION['is_valid'] == false){
    if (isset($_POST['login'])){
    
    $user_name = $_POST["user_name"];        
    $user_password = $_POST["user_password"]; 
    $cookiename = forumcookie;   
    $verify_username = strlen($user_name);
    $verify_pass = strlen($user_password);
    if ($verify_pass > 0 && $verify_username > 0)
    {
    $salt = substr($user_password, 0, 2);
    $userPswd = crypt($user_password, $salt);
    $sql = "SELECT * FROM `$user` WHERE user_name='$user_name' AND user_password='$userPswd' LIMIT 1;";
    $result = mysql_query($sql);
    if (mysql_num_rows($result) == 1){
    	$row = mysql_fetch_assoc($result);
    	$user_level = $row['userlevel'];
    	if ($user_level == 1) {
    		$login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = 	'$_GET[p]'"));
    
    		$userright = array($login_check['user_name'], $login_check['userlevel']);
    		$s_userpass = serialize($userpass);
    	$_SESSION['username'] = $row['user_name'];
    	$_SESSION['user_password'] = $row['user_password'];
    	$_SESSION['user_level'] = $row['userlevel'];
    	header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);
    	$_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files
    	 if(isset($_POST['remember'])){
        	  setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/");
        	  setcookie("cookpass", $_SESSION['user_password'], time()+60*60*24*100, "/");
       		}
    	} 
    		elseif ($user_level == 2){    
    			$login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'"));
    
    			$userright = array($login_check['user_name'], $login_check['userlevel']);
    		$s_userpass = serialize($userpass);
    	$_SESSION['username'] = $row['user_name'];
    	$_SESSION['user_password'] = $row['user_password'];
    	$_SESSION['user_level'] = $row['userlevel'];
    	header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);
    	$_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files
    	 if(isset($_POST['remember'])){
        	  setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/");
        	  setcookie("cookpass", $_SESSION['user_password'], time()+60*60*24*100, "/");
       		}
    	}
    }
    else{
    	echo "Login failed. Username and Password did not match database entries.";    
    }
    }
    
    else
    {
    echo "Form was not completed. Please go back and make sure that the form was fully completed.";    
    }
    }
    ?> 
    
    <html>
    <table bgcolor='#999999' align='right'><form action="<?php $_SERVER['PHP_SELF']; ?>" method='POST'>
    <tr><td>Username: </td><td><input type='text' name='user_name' /><br /></td></tr>
    <tr><td>Password:</td><td> <input type='password' name='user_password' /><br /></td></tr>
    <tr><td><input type="hidden" name="login" value="true"><input type="submit" value="Submit"></td></tr>
    <tr><td><input type="checkbox" value="1" name="remember"> Remember Me </td></tr><tr><td><a href="register.php">[Register]</a></td></tr><tr><td><a href="forgot_password.php">[Forgot Password?]</a></td></tr></table>
    </form>
    </html>
    
    <?php 
    mysql_close();
    }
    else
    {
    header("Location:http://".$_SERVER[HTTP_HOST]);
    }
    ?>

     

    when you register it should

    1. redirect to the login page

    2.if not all fields are filled in show an echo

    3.if the passwords or emails don't match it should show an echo.

     

    this kinda works, but when i clicked remember me on the login page, it went all wrong, when i go to the registration page, it enters my username and password.

    If i delete these then fill them all in when i click submit it reloads the page, with no errors, same if i submit with nothin or different passwords.

  8. Can anyone see how to fix my login form. It now redirects striaght away.

    this is the code

    <?php
    require_once 'db_connect.php';
    
    if ($_SESSION['is_valid'] == false){
    if(isset($_POST['login'])){
    
    $user_name = $_POST["user_name"];        
    $user_password = $_POST["user_password"]; 
    $cookiename = forumcookie;   
    $verify_username = strlen($user_name);
    $verify_pass = strlen($user_password);
    if ($verify_pass > 0 && $verify_username > 0)
    {
    $salt = substr($user_password, 0, 2);
    $userPswd = crypt($user_password, $salt);
    $sql = "SELECT * FROM `$user` WHERE user_name='$user_name' AND user_password='$userPswd' LIMIT 1;";
    $result = mysql_query($sql);
    if (mysql_num_rows($result) == 1){
    	$row = mysql_fetch_assoc($result);
    	$user_level = $row['userlevel'];
    	if ($user_level == 1) {
    		$login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = 	'$_GET[p]'"));
    
    		$userright = array($login_check['user_name'], $login_check['userlevel']);
    		$s_userpass = serialize($userpass);
    	$_SESSION['username'] = $row['user_name'];
    	$_SESSION['user_password'] = $row['user_password'];
    	$_SESSION['user_level'] = $row['userlevel'];
    	$_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files
    	header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);
    	if(isset($_POST['remember_me'])){
          	setcookie("$cookiename", $_SESSION['username'], time()+60*60*24*100, "/");
          	setcookie("$cookiename", $_SESSION['user_password'], time()+60*60*24*100, "/");
       		header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);	
    	} 
    
    
    
    	elseif ($user_level == 2){    
    		$login_check = @mysql_fetch_array(mysql_query("SELECT * from `$user` WHERE user_name = '$_GET[u]' AND user_password = '$_GET[p]'"));
    
    $userright = array($login_check['user_name'], $login_check['userlevel']);
    		$s_userpass = serialize($userpass);
    	$_SESSION['username'] = $row['user_name'];
    	$_SESSION['user_password'] = $row['user_password'];
    	$_SESSION['user_level'] = $row['userlevel'];
    	$_SESSION['is_valid'] = true; //change the session variable name to what you want, just remember it for all files
    
    	if(isset($_POST['remember_me'])){
          	setcookie("$cookiename", $_SESSION['username'], time()+60*60*24*100, "/");
          	setcookie("$cookiename", $_SESSION['user_password'], time()+60*60*24*100, "/");
       		header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);	
    	} 
    	else
    	{
    	header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);
    	}
    	}
    }
    else{
    	echo "Login failed. Username and Password did not match database entries.";    
    }
    }
    
    else
    {
    echo "Form was not completed. Please go back and make sure that the form was fully completed.";    
    }
    }
    ?> 
    
    <html>
    <table bgcolor='#999999' align='right'><form action="<?php $_SERVER['PHP_SELF']; ?>" method='POST'>
    <tr><td>Username: </td><td><input type='text' name='user_name' /><br /></td></tr>
    <tr><td>Password:</td><td> <input type='password' name='user_password' /><br /></td></tr>
    <tr><td><input type="hidden" name="login" value="true"><input type="submit" value="Submit"></td></tr>
    <tr><td><input type="checkbox" value="1" name="remember_me"> Remember Me </td></tr><tr><td><a href="register.php">[Register]</a></td></tr><tr><td><a href="forgot_password.php">[Forgot Password?]</a></td></tr></table>
    </form>
    </html>
    
    <?php 
    mysql_close();
    }
    else
    {
    header("Location:http://".$_SERVER[HTTP_HOST]);
    }
    }
    ?>

     

    i added this

    if(isset($_POST['remember_me'])){
          	setcookie("$cookiename", $_SESSION['username'], time()+60*60*24*100, "/");
          	setcookie("$cookiename", $_SESSION['user_password'], time()+60*60*24*100, "/");
       		header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);	
    	} 
    

     

    for the remeber me feature

  9. if you want to make sure all fields are filled in put.

    $firstname = $_POST["firstname"]

    $lastname = $_POST["lastname"]

    $age = $_POST["age"]

    if($firstname && $lastname && $age)

    {echo "all fields are filled in";}

    else

    {

    echo "please fill in all fields";

    }

     

    this should send you in the right direction, this goes in the submit form.

    to echo onto the page add require_once 'page_name.php'; in the else curly brackets

  10. using one of them methods, is it possible to show them a message if there ip is banned and if it isn't show them something else,

    something like this

    $ip = $_SERVER['REMOTE_ADDR']; //how can i store this address to ban them as this only shows the address???
    
    if($ip == user1);
    {
    echo "go away";
    }
    
    else
    {
    echo "Hello, we like you";
    }
    
    

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