wmguk Posted March 30, 2008 Share Posted March 30, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/ Share on other sites More sharing options...
wmguk Posted March 30, 2008 Author Share Posted March 30, 2008 any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504750 Share on other sites More sharing options...
trq Posted March 30, 2008 Share Posted March 30, 2008 Can we see scripts/connection.php ? Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504751 Share on other sites More sharing options...
wmguk Posted March 30, 2008 Author Share Posted March 30, 2008 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()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504754 Share on other sites More sharing options...
wmguk Posted March 30, 2008 Author Share Posted March 30, 2008 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504755 Share on other sites More sharing options...
wildteen88 Posted March 30, 2008 Share Posted March 30, 2008 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']; Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504757 Share on other sites More sharing options...
wmguk Posted March 30, 2008 Author Share Posted March 30, 2008 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.... Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504762 Share on other sites More sharing options...
wildteen88 Posted March 30, 2008 Share Posted March 30, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504765 Share on other sites More sharing options...
trq Posted March 30, 2008 Share Posted March 30, 2008 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'])) { Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504766 Share on other sites More sharing options...
wmguk Posted March 30, 2008 Author Share Posted March 30, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504773 Share on other sites More sharing options...
wmguk Posted March 30, 2008 Author Share Posted March 30, 2008 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']; Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504778 Share on other sites More sharing options...
trq Posted March 30, 2008 Share Posted March 30, 2008 No, it should be.... if (!isset($_SESSION['myusername'])) { header("location:index.php"); exit; } $user = $_SESSION['myusername']; Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504782 Share on other sites More sharing options...
wmguk Posted March 30, 2008 Author Share Posted March 30, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504886 Share on other sites More sharing options...
wmguk Posted March 30, 2008 Author Share Posted March 30, 2008 also, just trying to work out proper file permissions, I'm trying to get it to not list the files and folders within a directory what should my root be and then normal folders etc? Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504916 Share on other sites More sharing options...
wildteen88 Posted March 30, 2008 Share Posted March 30, 2008 To stop users seeing directory indexes just add a blank index.html or index.php file. Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504926 Share on other sites More sharing options...
wmguk Posted March 30, 2008 Author Share Posted March 30, 2008 ah ok hehe simple really didnt know if i could set it to like 755 or something and it would do it Quote Link to comment https://forums.phpfreaks.com/topic/98626-sessions-issues/#findComment-504944 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.