Jump to content

[SOLVED] Logging in


jackel15

Recommended Posts

I'm using $_SESSION to login and access my admin section. I have used this code before and it has worked. It is accepting the username and password, but kicking me back to the login page. All the admin pages check for your session and if not found then kick back to login.php.

 

Login Page code above doctype:

<?php

if(empty($_POST)) {
	$status = 'Please Enter Username and Password to Add, Edit and Remove Sermons.';
} else {
	$user = $_POST['user'];
	$pass = $_POST['pass'];

	$error_list = array();

		if(empty($user)) {
			$error_list[] = 'Please Enter Your Username';
		}

		if(empty($pass)) {
			$error_list[] = 'Please Enter Your Password';
		}

	if(empty($error_list)) {

			mysql_connect('','','');
			mysql_select_db('') or die('Could Not Connect to Database. Please email the webmaster at christensonmedia@gmail.com and try again later.');

			$sql = "SELECT id";
			$sql .= " FROM users";
			$sql .= " WHERE user='$user'";
			$sql .= " AND pass='$pass'";

			$result = mysql_query($sql);

			if(mysql_num_rows($result) == 1) {

				session_start();
				$_SESSION['logged_in'] = true;
				header('Location: index.php');

			} else {
				$status .= 'The Username and Password you entered was invalid. Please Try again.';
			}



	} else {

		foreach($error_list as $error_message) {
			$status .= "$error_message<br />";
		}

	}

}
?>

 

Code for admin index:

<?php

session_start();

if($_SESSION['logged_in'] != true) {
header('Location: login.php');
} ?>

 

Site is live at http://cocoafirstassembly.ipower.com/_admin/login.php

Link to comment
Share on other sites

Try moving the "session_start()" to the top of the php on your login page, and try echo-ing the $_SESSION variable on admin.php check if it is even being set.

Hell you could null out the redirect on login.php and check if it is being set.

 

If the data is blank, try using a string or integer value rather then a boolean. I'm not 100% sure if those steps will work or even help. That's just the first ones I would take.

Link to comment
Share on other sites

I'm using $_SESSION to login and access my admin section. I have used this code before and it has worked. It is accepting the username and password, but kicking me back to the login page. All the admin pages check for your session and if not found then kick back to login.php.

 

Login Page code above doctype:

<?php

if(empty($_POST)) {
	$status = 'Please Enter Username and Password to Add, Edit and Remove Sermons.';
} else {
	$user = $_POST['user'];
	$pass = $_POST['pass'];

	$error_list = array();

		if(empty($user)) {
			$error_list[] = 'Please Enter Your Username';
		}

		if(empty($pass)) {
			$error_list[] = 'Please Enter Your Password';
		}

	if(empty($error_list)) {

			mysql_connect('','','');
			mysql_select_db('') or die('Could Not Connect to Database. Please email the webmaster at christensonmedia@gmail.com and try again later.');

			$sql = "SELECT id";
			$sql .= " FROM users";
			$sql .= " WHERE user='$user'";
			$sql .= " AND pass='$pass'";

			$result = mysql_query($sql);

			if(mysql_num_rows($result) == 1) {

				session_start();
				$_SESSION['logged_in'] = true;
				header('Location: index.php');

			} else {
				$status .= 'The Username and Password you entered was invalid. Please Try again.';
			}



	} else {

		foreach($error_list as $error_message) {
			$status .= "$error_message<br />";
		}

	}

}
?>

 

Code for admin index:

<?php

session_start();

if($_SESSION['logged_in'] != true) {
header('Location: login.php');
} ?>

 

Site is live at http://cocoafirstassembly.ipower.com/_admin/login.php

 

I hope you know you left in your database details...

Link to comment
Share on other sites

I put

error_reporting(E_ALL);
ini_set("display_errors", 1);

at the top of the page and its giving me these errors:

 

Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_bb2a139f2f0b0baa7f1838986834bc15, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 36

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php:36) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 36

 

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php:36) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 38

 

Link to comment
Share on other sites

I've changed it to a folder that I've set up. What should the permissions be? It is giving me the same error.

 

Warning: session_start() [function.session-start]: open(//cocoafirstassembly.ipower.com:21//php_sessions/sess_bb2a139f2f0b0baa7f1838986834bc15//sess_bb2a139f2f0b0baa7f1838986834bc15, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 38

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php:38) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 38

 

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php:38) in /hermes/bosweb/web293/b2934/ipw.cocoafirstassembly/public_html/_admin/login.php on line 41

 

i used at the top of the login page:

$path = '//cocoafirstassembly.ipower.com:21//php_sessions/sess_bb2a139f2f0b0baa7f1838986834bc15/';
session_save_path($path);

 

folder structure:

 

index.php

_admin/index.php

_admin/login.php

_admin/logout.php

 

I'm trying to get to index.php in the admin folder, but when i get there, the login check at the top of the page is kicking me back to the login.php page.

 

session_start();

if($_SESSION['access'] != TRUE) {
header('Location: login.php');
}

 

Link to comment
Share on other sites

changing the path on every page I check for the session made it work. Thanks so much for your help. I would still be beating my brains out wondering what's going on if it wasn't for this forum. Thanks Again Daniel0.

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.