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
https://forums.phpfreaks.com/topic/221754-object-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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