Jump to content

[SOLVED] error with protecting webpage


runnerjp

Recommended Posts

<?php
	if ( $_SESSION['logged_in'] ){
?>

welcome member 


<?php  
endif;
?>

 

here is the code to prevent users from viewing page. yes simple i know but this is not the problem

 

for the life of me i cant do it lol what i want is an error message to show if the user is not logged in.

 

i have tried adding

<?php

}
else {

?>

<p>This is the protected page. Your private content goes here.</p>

<?php

}

?> 

 

and verius other methords and know luck... i should now how to do this but its not there lol 

Link to comment
Share on other sites

yeah that is pretty much the same as what i put. The extra bit is just an or statement incase the first check fails. No idea why its there to be honest. It was just in the tutorial i followed.

 

If you dont want a re direct you can remove

header("Location: http://www.runningprofiles.com");


and put

echo blah blah blah;
exit;

 

I think that will work. Not 100% sure though

 

Link to comment
Share on other sites

nope something aint right

 

 <?php
if (!isset($_SESSION['logged_in']) 
   || $_SESSION['logged_in'] !== true) {

   // not logged in, move to login page
   echo "your not allowed in" ;
   exit;
}
?>

 

see if you are not logged in and try accessing the page it reads the echo "your not allowed in"

 

but when logging in you get redirected to the page it still reads "your not allowed in"

 

 

thanks for help hard getting to grips with this stuff aint it lol

Link to comment
Share on other sites

here is login form

 

<?php
require_once ( 'settings.php' );

if ( array_key_exists ( '_submit_check', $_POST ) )
{
	if ( $_POST['username'] != '' && $_POST['password'] != '' )
	{
		$query = 'SELECT ID, Username, Active, Password FROM ' . DBPREFIX . 'users WHERE Username = ' . $db->qstr ( $_POST['username'] ) . ' AND Password = ' . $db->qstr ( md5 ( $_POST['password'] ) );

		if ( $db->RecordCount ( $query ) == 1 )
		{
			$row = $db->getRow ( $query );
			if ( $row->Active == 1 )
			{
				set_login_sessions ( $row->ID, $row->Password, ( $_POST['remember'] ) ? TRUE : FALSE );
				header ( "Location: " . REDIRECT_AFTER_LOGIN );
			}
			elseif ( $row->Active == 0 ) {
				$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link.';
			}
			elseif ( $row->Active == 2 ) {
				$error = 'You are suspended!';
			}
		}
		else {		
			$error = 'Login failed!';		
		}
	}
	else {
		$error = 'Please use both your username and password to access your account';
	}
}
?>

 

and sessions are

 

 function checkLogin ( $levels )
{
	session_start ();
	global $db;
	$kt = split ( ' ', $levels );

	if ( ! $_SESSION['logged_in'] ) {

		$access = FALSE;

		if ( isset ( $_COOKIE['cookie_id'] ) ) {//if we have a cookie

			$query =  'SELECT * FROM ' . DBPREFIX . 'users WHERE ID = ' . $db->qstr ( $_COOKIE['cookie_id'] );

			if ( $db->RecordCount ( $query ) == 1 ) {//only one user can match that query
				$row = $db->getRow ( $query );

				//let's see if we pass the validation, no monkey business
				if ( $_COOKIE['authenticate'] == md5 ( getIP () . $row->Password . $_SERVER['USER_AGENT'] ) ) {
					//we set the sessions so we don't repeat this step over and over again
					$_SESSION['user_id'] = $row->ID;				
					$_SESSION['logged_in'] = TRUE;

					//now we check the level access, we might not have the permission
					if ( in_array ( get_level_access ( $_SESSION['user_id'] ), $kt ) ) {
						//we do?! horray!
						$access = TRUE;
					}
				}
			}
		}
	}
	else {			
		$access = FALSE;

		if ( in_array ( get_level_access ( $_SESSION['user_id'] ), $kt ) ) {
			$access = TRUE;
		}
	}

	if ( $access == FALSE ) {
		header ( "Location: " . REDIRECT_TO_LOGIN );

Link to comment
Share on other sites

that didnt chnage anything as . REDIRECT_AFTER_LOGIN  is a command to go to page i want (i did chnage it to try and did same)  something to do with the on page code i think thats stoppin this (this beeing

<?php
if (!isset($_SESSION['logged_in']) 
   || $_SESSION['logged_in'] !== true) {

   // not logged in, move to login page
   echo "your not allowed in" ;
   exit;
}
?>

Link to comment
Share on other sites

:o dam... lol why didnt i add that, been looking at ocde you gave not getting why it would not work snd i didnt even start the session even looked at it in function checkLogin ( $levels )

{

session_start ();< --- right infront of my eyes lol

 

 

thanks for help!! if u ever need help i will return favour lol

Link to comment
Share on other sites

<?php
	if ( $_SESSION['logged_in'] ){
?>

welcome member 


<?php  
endif;
?>

 

here is the code to prevent users from viewing page. yes simple i know but this is not the problem

 

for the life of me i cant do it lol what i want is an error message to show if the user is not logged in.

 

i have tried adding

<?php

}
else {

?>

<p>This is the protected page. Your private content goes here.</p>

<?php

}

?> 

 

and verius other methords and know luck... i should now how to do this but its not there lol 

 

 

<=$_SESSION['logged_in']?'You are logged in.':'You are not logged in.';?>

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.