Web Design Forum: sessions are not setting - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

sessions are not setting Rate Topic: -----

#1 User is offline   lee sands 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 134
  • Joined: 14-August 10
  • Reputation: 0
  • Gender:Male
  • Location:Gosport, Hampshire, UK
  • Experience:Beginner
  • Area of Expertise:Coder

Posted 09 January 2012 - 07:50 PM

hi all this is my login code and the sessions are not being set when i echo them
<?php
	session_start();
	
	if (isset($_POST['submit'])) {
		require_once "includes/conn.inc.php";
		$email = $_POST['username'];
		$pass = $_POST['password'];
		$sql = "SELECT * FROM cms_users WHERE email='".$email."' AND password='".$pass."' AND email_activated='1'"; 
		$results = mysql_query($sql,$conn);
		$login_check = mysql_num_rows($results);
		if($login_check == 1){ 
			$row = mysql_fetch_array($results);
			
			$id = $row["id"]; 
			$pass = $row['password'];  
			$firstname = $row["firstname"]; 
			$email = $row["email"]; 	
    		
			$_SESSION['id'] = $id; 	
    		$_SESSION['firstname'] = $firstname;   	
	  		$_SESSION['email'] = $email;  
		 	$_SESSION['user_logged'] = $email;			
			
			$_SESSION['user_password'] = $pass;		 
			mysql_query("UPDATE cms_users SET last_log_date=now() WHERE id='".$id."'",$conn);	
			header ("Refresh: 5; URL=" . $_POST['redirect'] . "");
			echo "You are being redirected to your original page request!<br>";
			echo "(If your browser doesn't support this, <a href=\"" . $_POST['redirect']. "\">click here</a>)";			
		} else {	
?>
<html>
<head>
<title>Beginning PHP5, Apache and MySQL</title>
</head>
<body>
<p>
 	Invalid Username and/or Password<br>
  Not registered? 
  <a href="register.php">Click here</a> to register.<br>
  <form action="login.php" method="post">
	<input type="hidden" name="redirect" value="<?php echo $_POST['redirect']; ?>">
	Username: <input type="text" name="username"><br>
	Password: <input type="password" name="password"><br><br>
	<input type="submit" name="submit" value="Login">
  </form>
</p>
</body>
</html>
<?php
  }
} else {
  if (isset($_GET['redirect'])) {
	$redirect = $_GET['redirect'];
  } else {
	$redirect = "index.php";
  }
?>
<html>
<head>
<title>Beginning PHP5, Apache and MySQL</title>
</head>
<body>
<p>
  Login below by supplying your username/password...<br>
  Or <a href="register.php">click here</a> to register.<br><br>
  <form action="login.php" method="post">
	<input type="hidden" name="redirect" value="<?php echo $redirect; ?>">
	Username: <input type="text" name="username"><br>
	Password: <input type="password" name="password"><br><br>
	<input type="submit" name="submit" value="Login">
  </form>
</p>
</body>
</html>
<?php
}
?>


Any Ideas would Help
0

#2 User is offline   webdesigner93 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,976
  • Joined: 22-September 09
  • Reputation: 222
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 09 January 2012 - 08:33 PM

That codes a death trap for mysql injections :unsure:

This post has been edited by webdesigner93: 09 January 2012 - 08:34 PM

0

#3 User is offline   lee sands 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 134
  • Joined: 14-August 10
  • Reputation: 0
  • Gender:Male
  • Location:Gosport, Hampshire, UK
  • Experience:Beginner
  • Area of Expertise:Coder

Posted 09 January 2012 - 09:06 PM

what you mean you got a better way
0

#4 User is offline   webdesigner93 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,976
  • Joined: 22-September 09
  • Reputation: 222
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 09 January 2012 - 09:23 PM

View Postlee sands, on 09 January 2012 - 09:06 PM, said:

what you mean you got a better way

i mean your passing

 $email = $_POST['username'];
 $pass = $_POST['password'];


into your query with no protection so basically someone could inject harmful things into your query, not to mention from what i can tell the password in your database is not encrypted, but is just plain text, i'd recommend adding the protection or using PDO which is not vulnerable to mysql injections
0

#5 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,818
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 11 January 2012 - 10:35 AM

View Postlee sands, on 09 January 2012 - 09:06 PM, said:

what you mean you got a better way


http://www.lmgtfy.co...mysql+injection
0

#6 User is offline   lee sands 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 134
  • Joined: 14-August 10
  • Reputation: 0
  • Gender:Male
  • Location:Gosport, Hampshire, UK
  • Experience:Beginner
  • Area of Expertise:Coder

Posted 11 January 2012 - 05:10 PM

ok that code to seem to me working fine now got a new problem if anyone wants a look

<?php 
	
	require_once '../configs/config.php';

	function get_option( $option) {
		
		$s = "SELECT option_value FROM cms_settings WHERE option_name ='".$option."' LIMIT 1";
		$q = mysql_query($s);
		$c = mysql_num_rows($q);
		
		if($c == 1) {
			$r = mysql_fetch_array($q);
			$r['option_value'];
			return $r;
		} else {
			$r = "No Result Sorry";
			return $r;
		}
	}
		
	
	echo get_option('siteurl');
	



returns

Quote

Array



this is an adaption of the function word press uses but all my own code
0

#7 User is offline   webdesigner93 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,976
  • Joined: 22-September 09
  • Reputation: 222
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 11 January 2012 - 05:24 PM

<?php 
	
	require_once '../configs/config.php';

	function get_option() {
		
		$s = "SELECT option_value FROM cms_settings WHERE option_name ='".$option."' LIMIT 1";
		$q = mysql_query($s);
		$config = array();	
		while($r = mysql_fetch_array($q)){
		$config[$r['option_name']] = $r['option_value'];
                   }
		return $config;
	}
		
	$config = get_option(); 
	echo $config['siteurl'];
	


this should work for you

This post has been edited by webdesigner93: 11 January 2012 - 05:25 PM

0

#8 User is offline   lee sands 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 134
  • Joined: 14-August 10
  • Reputation: 0
  • Gender:Male
  • Location:Gosport, Hampshire, UK
  • Experience:Beginner
  • Area of Expertise:Coder

Posted 11 January 2012 - 05:34 PM

Notice: Undefined variable: option inC:\xampp\htdocs\cms\application\settings\settings.phpon line 8

Notice: Undefined index: siteurl inC:\xampp\htdocs\cms\application\settings\settings.phpon line 18

line 18 =
echo $config['siteurl'];



0

#9 User is offline   webdesigner93 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,976
  • Joined: 22-September 09
  • Reputation: 222
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 11 January 2012 - 05:38 PM

Use

$s = "SELECT * FROM cms_settings";


Not

$s = "SELECT option_value FROM cms_settings WHERE option_name ='".$option."' LIMIT 1";

This post has been edited by webdesigner93: 11 January 2012 - 05:39 PM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users