Jump to content


Photo

Session help please. early post Still unsolved!


  • Please log in to reply
17 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 02 September 2006 - 09:44 AM

Hi,

I've built a login system that once the user has entered in his usname and pword it will take
them to the next page.

This was all working earlyer today, but has since stop. Which means there must be something
wrong with my code.

Could someone please have a quick look?

<?php
session_start();
if(session_is_registered(username)) {
header('Location: add_banner.php');
}
include('dbconnect.php');
?>
<?php

	$bodyErrors = array();

if (!empty($_POST['submit_butt'])) {
	if ($_POST['username']=='')
		$bodyErrors['username'] = 'Add Your Username';
	if ($_POST['password']=='')
		$bodyErrors['password'] = 'Add Your Password';

		if (count($bodyErrors) == 0) {
			
			$username=$_POST['username'];
			$password=$_POST['password'];
			
			$sql="SELECT * FROM user_info WHERE username='$username' and password='$password'";
			$result = mysql_query($sql);
			$count = mysql_num_rows($result);
			
			
						
				if ($count == 1) {
					session_register('username');
					session_register('password');
				header('Location: add_banner.php');
					
				} else {
				$noinput = '<div class="white2">Sorry. You have entered an incorrect username or password,<br> please try again';
				}
				
		  } else {
			if (empty($username) || empty($password)) {  
				$bodylogErrors = '<div class="error">'; 
				foreach ($bodyErrors as $log_error) {
					$bodylogErrors .= "<li>$log_error</li>";
				}
			$bodylogErrors .= '</div>';
		   }
	}		
	
}

include('functions/wrapper1.php');
include('functions/dropdowns.php');
include('functions/random_images.php');

?>

Now, here is the strange part.
The page is being directed to add_banner.php but then comes back because i have a:
session_start();
if(!session_is_registered(username)) {
header('Location: add_a_banner.php');
}
This means that the sessions are not registering.

Also, if i echo out the username inbetween session_register and the header
e.g
					session_register('username');
					session_register('password');
                         echo $username;
				header('Location: add_banner.php');
The session DO register, but then the header dont work because something is being printed to screen.

Has anyone seen this before?
any help please.

:D
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 September 2006 - 09:58 AM

Use this:
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

Instead of
session_register('username');
session_register('password');
Also all what session_register does is setup a blank username/password session variable. It doesnt pupulate the session with anything. Also session_register is depreciated. You should use the code provided above to create your session variables.

In add_banner.php you should use this:
session_start();
if(!isset($_SESSION['username'])) {
header('Location: add_a_banner.php');
}


#3 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 02 September 2006 - 10:06 AM

Cheers mate.
You've been a great help.

Thanks again.
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#4 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 02 September 2006 - 05:23 PM

I Cant for the life of me see whats wrong.

Has anyone every come across this problem when the sessions will not register.
It seems as though the header is kicking in before the session registers?

Any more suggestion please.
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 September 2006 - 05:28 PM

post all your code you got now please cheers.


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 02 September 2006 - 05:51 PM

Thanks for looking
Here you go

login page
<?php
session_start();
if(isset($_SESSION['username'])) {
header('Location: add_banner.php');
}

include('validation.php');
include('dbconnect.php');
?>
<?php
	$bodyErrors = array();

if (!empty($_POST['submit_butt'])) {
	if ($_POST['username']=='')
		$bodyErrors['username'] = 'Add Your Username';
	if ($_POST['password']=='')
		$bodyErrors['password'] = 'Add Your Password';

		if (count($bodyErrors) == 0) {
			
			$username=$_POST['username'];
			$password=$_POST['password'];
			
			$sql="SELECT * FROM user_info WHERE username='$username' and password='$password'";
			$result = mysql_query($sql);
			$count = mysql_num_rows($result);
			
			
						
				if ($count == 1) {
					session_register('username');
					session_register('password');
				header('Location: add_banner.php');
					
				} else {
						$noinput = '<div class="white2">Sorry. You have entered an incorrect username or password,<br> please try again';
				}
				
		  } else {
			if (empty($username) || empty($password)) {  
				$bodylogErrors = '<div class="error">'; 
				foreach ($bodyErrors as $log_error) {
					$bodylogErrors .= "<li>$log_error</li>";
				}
			$bodylogErrors .= '</div>';
		   }
	}		
	
}

include('functions/wrapper1.php');
include('functions/dropdowns.php');
include('functions/random_images.php');

?>


second page
<?php
session_start();
if(!isset($_SESSION['username'])) {
header('Location: add_a_banner.php');
}


include('validation.php');
include('dbconnect.php');
?>

How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 September 2006 - 05:58 PM

i think if you look into the other included files.

your see that they have no session_start() in so, I think you should add them and try also i strongly recomend you change all the session register to the way as posted  above ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 02 September 2006 - 06:15 PM

Sorry, i thought i had changed it all. silly me.  :P

So, you have to have a session_start on every page related?
That could very well be the problem. I shall go try it out and let you know how i get on.

Cheers mate.
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#9 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 02 September 2006 - 06:31 PM

Ok, I've added session_start() to every page that is included.
and changed all of the sessions as recommended above.
But i still not registering, i can see the address bar change which means the header is working.

here is the web address
http://www.theevento...dd_a_banner.php

here the code for the page the whole php
<?php
session_start();
if(isset($_SESSION['username'])) {
header('Location: add_banner.php');
}

include('validation.php');
include('dbconnect.php');
?>
<?php
	$submit_cat = $_POST['cat'];			
	$loginErrors = array();

if (!empty($_POST['Submit'])) {
	if ($_POST['username']=='')
		$loginErrors['username'] = 'Add Your Username';
	if ($_POST['password']=='')
		$loginErrors['password'] = 'Add Your Password';

		if (count($loginErrors) == 0) {
			
			$username=$_POST['username'];
			$password=$_POST['password'];

			
			$sql="SELECT * FROM user_info WHERE username='$username' and password='$password'";
			$result = mysql_query($sql);
			$count = mysql_num_rows($result);
			
			
						
				if ($count == 1) {
					$_SESSION['username'] = $username;
					$_SESSION['password'] = $password;
					header("Location:profile.php");
					
				} else {
						$noinput = '<div class="white2">Sorry. You have entered an incorrect username or password,<br> please try again';
				}
				
		  } else {
			if (empty($username) || empty($password)) {  
				$strLogError = '<div class="white2">'; 
				foreach ($loginErrors as $log_error) {
					$strLogError .= "<li>$log_error</li>";
				}
			$strLogError .= '</div>';
		   }
	}		
	
}


	$bodyErrors = array();

if (!empty($_POST['submit_butt'])) {
	if ($_POST['username']=='')
		$bodyErrors['username'] = 'Add Your Username';
	if ($_POST['password']=='')
		$bodyErrors['password'] = 'Add Your Password';

		if (count($bodyErrors) == 0) {
			
			$username=$_POST['username'];
			$password=$_POST['password'];
			
			$sql="SELECT * FROM user_info WHERE username='$username' and password='$password'";
			$result = mysql_query($sql);
			$count = mysql_num_rows($result);
			
			
						
				if ($count == 1) {
					$_SESSION['username'] = $username;
					$_SESSION['password'] = $password;
				header('Location: add_banner.php');
					
				} else {
						$noinput = '<div class="white2">Sorry. You have entered an incorrect username or password,<br> please try again';
				}
				
		  } else {
			if (empty($username) || empty($password)) {  
				$bodylogErrors = '<div class="error">'; 
				foreach ($bodyErrors as $log_error) {
					$bodylogErrors .= "<li>$log_error</li>";
				}
			$bodylogErrors .= '</div>';
		   }
	}		
	
}

include('functions/wrapper1.php');
include('functions/dropdowns.php');
include('functions/random_images.php');

?>


This is the code on the second page
<?php
session_start();
if(!isset($_SESSION['username'])) {
header('Location: add_a_banner.php');
}


include('validation.php');
include('dbconnect.php');
?>

Any more help would be greatly appreceated.

Thanks for taking the time to do this.
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 September 2006 - 06:35 PM

very strange all worked then went dead aswell weired.

echo out your querys and see if they mach as it suppose to not there is also some pages got no links.

when i press your account i get a hello so i think the sessions work.

it's the querys i think have a look weired

Nice site theo.

thinking.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 02 September 2006 - 06:42 PM

Cheers mate.


How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#12 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 September 2006 - 06:52 PM

can i have a fake name and password please to see it i get in.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#13 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 02 September 2006 - 06:56 PM

If i echo the $username out after the:   $_SESSION['username'] = $username;
                         $_SESSION['password'] = $password;
It echos out the user name, Its also registers the session, Which is very strange?
But then the header dont work.

e,g
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
echo $username;
header('Location: add_banner.php');

the 'Your Accout' doesn't have any sessions on the page its goes to yet.

Here is a test username and password
test
test


How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#14 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 September 2006 - 06:59 PM

i logged in and i got the hello very weired.

mybe you need to use include dont knoe weired


this is for the users to login as the login page i suspect yes?

include("add_banner.php");
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#15 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 September 2006 - 07:03 PM

If i echo the $username out after the:  $_SESSION['username'] = $username;
                          $_SESSION['password'] = $password;
It echos out the user name, Its also registers the session, Which is very strange?
But then the header dont work.

e,g
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
echo $username;
header('Location: add_banner.php');

the 'Your Accout' doesn't have any sessions on the page its goes to yet.

Here is a test username and password
test
test

$username is not your session variable. That variable is the variable you setup ealier to to get the username form the _POST['username'] array. To echo the username session you'll want to use
echo $_SESSION['username'];


#16 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 02 September 2006 - 07:04 PM

the login box to the bottom left donn't have any session check on the next page yet.

The login box in the center does, so try in that box and you will see the address baar change, then change back.


How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#17 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 02 September 2006 - 07:06 PM

the login box to the bottom left donn't have any session check on the next page yet.

The login box in the center does, so try in that box and you will see the address baar change, then change back.

Ok wildteen88, I'll try it out.
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#18 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 02 September 2006 - 07:10 PM

Yeah, it echos out the user name.

If you try the test=username and test=password your'll see it echo out at the top left hand corner
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users