Jump to content

object php


fife

Recommended Posts

Hi

 

I have a login script which goes at the top of several pages in my site.  It works fine but I am trying to save some coding and re-writing out my script at the top of each of the pages.  Instead I have made a page called login.php and put all of the code for the script in there. 

 

Looks like this....

<?php
//login script 
if(isset($_POST['log'])) {
$emaillog = stripslashes($_POST['emaillog']);
$passwordlog = stripslashes($_POST['passwordlog']);
$emaillog = mysql_real_escape_string($_POST['emaillog']);   
$passwordmd5 = md5($passwordlog);  
//generate random session id which i want to follow the user round the site!
$CheckUser = "SELECT * FROM members WHERE email='".$emaillog."' AND password='".$passwordmd5."'";
$userDetails2 = mysql_query($CheckUser);	
$userInfo = mysql_fetch_array($userDetails2);
$count = mysql_num_rows($userDetails2);	
		 if($count != 0) {
		 	$_SESSION['memberID'] = $userInfo['memberID'];
			$_SESSION['accesslevel']= $userInfo['accesslevel'];
			$_SESSION['email']= $userInfo['email'];

			//add an id that will be carried throughout the user until the session is destroyed
		 function getUniqueCode2($length2 = "")
 {	$code2 = md5(uniqid(rand(), true));
	if ($length2 != "") return substr($code2, 0, $length2);
	else return $code2; }

$randomKey = getUniqueCode2(25);
$_SESSION['key'] = $randomKey;

		//the user must have an access level of 2, before they can login
			if($_SESSION['accesslevel']=='2')
$url = "loggedin/index.php";        
header("Location: ".$url.""); 	 
		$success = '1';
		}
		else {
			$success = '0';			
			$logged = "incorrect login details" or die(mysql_error());
						}

						//now we need to update the login table to reflect a login
						if($success =='1'){
			$time = date("Y-m-d h:m:s");
			$qupdate_mem_logins = "INSERT INTO logindetails (`email`,`time`) VALUES ('".$emaillog."','".$time."')";
			 $rupdate_mem_logs = mysql_query($qupdate_mem_logins) or die(mysql_error());

        ?>

 

Now on the index page how do I reffer to this login script when someone fills in the form  At the minute I have the following code but it is not checking or running anything.

 

<?php
//login script 
if(isset($_POST['log'])) {
include('login.php');
}
	}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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