Jump to content

sessions issues :(


wmguk

Recommended Posts

hey

 

I currently have this script:

 

<?php
//Engage sesions.
session_start();
// Here we include the mysql connection script.
include("scripts/connection.php");

// Connect to server and select databse. 
if (!$con) 
{ 
die('Could not connect: ' . mysql_error()); 
} 
else {
if (!mysql_select_db($db, $con)){
echo 'Could not connect to database.';
exit; }
}


if(isset($_POST['Submit'])){

$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

/* Select data from database. */
$sql="SELECT * FROM our_info WHERE username='$myusername' and password='$mypassword'"; 
$result=mysql_query($sql); 
$count=mysql_num_rows($result);

/* If only one occurrence is there. */
if($count==1){
/* Set the myusername sesion to 1 */
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword; 
/* Make an sesion called authenticated to tell main.php that the user is logged in. */
$_SESSION['authenticated'] == 'true';
header("location:main.php");
exit;
} 
else 
{ 
header("location:failed.php");
exit;
} 
}
else {

//SHOW THIS

}

 

Which should assign myusername and mypassword to the session header?

 

but on the top of the page after login i get this:

 

Notice: Use of undefined constant myusername - assumed 'myusername' in /var/www/vhosts/mmm.co.uk/httpsdocs/display.php on line 6

 

:( any ideas?

Link to comment
Share on other sites

of course

 

<?php
$host = "localhost"; //Host name
$dbUser = "XXXX"; //MySQL Username
$dbPass = "XXXX"; //MySQL Password
$db = "XXXX" ; //Database name 
$db2 = "XXXX" ; //Upload storage location
$tbl_name="XXXX"; // Table name 


//FTP ACCESS SETTINGS - createadmin/uploadim.php

$ftpuser = "XXXX";
$ftppass = "XXXX";
$ftplocation = "ftp.XXXX.co.uk/httpdocs/clients";
$ftpacc = "ftp://$ftpuser:$ftppass@$ftplocation/$login" ;
$incdir = "http://www.XXXX.co.uk/clients/create.php" ;

$con = mysql_connect($host,$dbUser,$dbPass);
$conn = mysql_connect($host,$dbUser,$dbPass) or die(mysql_error());
mysql_select_db($db, $conn) or die(mysql_error());

?>

Link to comment
Share on other sites

oh, and this is the script on the top of every page

 

<?php
session_start(); 
$t = date("h:i:s", time()); 
$_SESSION['admin_login_time'] = $t; 
$user = $_SESSION['myusername']; 
if(!session_is_registered(myusername)){ 
header("location:index.php"); 
} 
?>

Link to comment
Share on other sites

Why are you connecting the mysql server twice:

$con = mysql_connect($host,$dbUser,$dbPass);
$conn = mysql_connect($host,$dbUser,$dbPass) or die(mysql_error());

 

Chnage it to:

$con = mysql_connect($host,$dbUser,$dbPass) or die(mysql_error());

 

Alos no need for this code either:

// Connect to server and select databse. 
if (!$con) 
{ 
die('Could not connect: ' . mysql_error()); 
} 
else {
if (!mysql_select_db($db, $con)){
echo 'Could not connect to database.';
exit; }
}

 

You have connected/selected database in scripts/connection.php

 

Also that error/notice you are retrieving is coming from  different script, display.php

 

Edit

 

Didn't see your second post. These lines:

$user = $_SESSION['myusername']; 
if(!session_is_registered(myusername)){ 
header("location:index.php"); 
} 

should be:

if(!isset($_SESSION['myusername']))
{
    header("location:index.php");
    exit;
} 

$user = $_SESSION['myusername'];

Link to comment
Share on other sites

im thinking now this website has 50+ scripts and 30 other php pages with connections on ill remove the connection script from connection.php

 

either that or go through EVERY page on the site and remove the connection from there.. :(

 

eek, ive looked at that connection.php page so often just didnt even register it....

 

 

Link to comment
Share on other sites

im thinking now this website has 50+ scripts and 30 other php pages with connections on ill remove the connection script from connection.php

 

either that or go through EVERY page on the site and remove the connection from there.. :(

 

eek, ive looked at that connection.php page so often just didnt even register it....

 

I suggest you keep the connection details within the connection.php and any other variables required by your app too. That way if you need to change the connection info for the database you'll just need to edit one script rather than a whole load of scripts.

Link to comment
Share on other sites

You've attempted to give session_is_registered a non existent constant.

 

Should be....

 

if(!session_is_registered('myusername')){

 

By the way, session_is_registered has long been depricated. All you really need use is...

 

if (isset($_SESSION['myusername'])) {

Link to comment
Share on other sites

ok, so set connection.php

 

$host = "localhost"; //Host name
$dbUser = "XXXX"; //MySQL Username
$dbPass = "XXXX"; //MySQL Password
$db = "XXXX" ; //Database name 
$db2 = "XXXX" ; //Upload storage location
$tbl_name="XXXX"; // Table name 


//FTP ACCESS SETTINGS - createadmin/uploadim.php

$ftpuser = "XXXX";
$ftppass = "XXXX";
$ftplocation = "ftp.XXXX.co.uk/httpdocs/clients";
$ftpacc = "ftp://$ftpuser:$ftppass@$ftplocation/$login" ;
$incdir = "http://www.XXXX.co.uk/clients/create.php" ;
$conn = mysql_connect($host,$dbUser,$dbPass) or die(mysql_error());
mysql_select_db($db, $conn) or die(mysql_error());

 

I'm getting this error now, which is this:

$ftpacc = "ftp://$ftpuser:$ftppass@$ftplocation/$login" ;

but $login isnt always required, that ftp script is only required on the ftp access system. so then $login isnt assigned unless its in the ftp system...

Notice: Undefined variable: login in /var/www/vhosts/xxxxxx.co.uk/httpsdocs/scripts/connection.php on line 15

Link to comment
Share on other sites

 

if(!isset($_SESSION['myusername']))
{
    header("location:index.php");
    exit;
} 

$user = $_SESSION['myusername'];

 

so it should be

 

if (isset($_SESSION['myusername'])) {
    header("location:index.php");
    exit;
} 
$user = $_SESSION['myusername'];

Link to comment
Share on other sites

ok, sorry :) thats cool, thank you :)

 

now, i can remove this from every page right?

 

include "scripts/connection.php"; 
if (!$con) 
{ 
  die( 'Could not connect: ' . mysql_error() ); 
   }
mysql_select_db($db, $con); 

 

and just make it

include "scripts/connection.php"; 

 

also how can i set $login = " "

 

$login= (empty($_POST[login])) ? " " : $_POST[login] ;

 

then only issue is that login isnt assigned via post or anything, this is on the include page, so login is assigned before the include...

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.