Jump to content

Session help please. early post Still unsolved!


spires

Recommended Posts

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?

[code]
<?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');

?>
[/code]

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

Also, if i echo out the username inbetween session_register and the header
e.g
[code]
session_register('username');
session_register('password');
                         echo $username;
header('Location: add_banner.php');
[/code]
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
Link to comment
Share on other sites

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

Instead of
[code]session_register('username');
session_register('password');[/code]
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:
[code=php:0]session_start();
if(!isset($_SESSION['username'])) {
header('Location: add_a_banner.php');
}[/code]
Link to comment
Share on other sites

Thanks for looking
Here you go

login page
[code]
<?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');

?>
[/code]


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


include('validation.php');
include('dbconnect.php');
?>
[/code]
Link to comment
Share on other sites

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.theeventorganiser.com/add_a_banner.php

here the code for the page the whole php
[code]
<?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');

?>
[/code]


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


include('validation.php');
include('dbconnect.php');
?>
[/code]

Any more help would be greatly appreceated.

Thanks for taking the time to do this.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

[quote author=spires link=topic=106605.msg426703#msg426703 date=1157223368]
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
[/quote]
$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 [code=php:0]echo $_SESSION['username'];[/code]
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.