cyberRobot Posted September 28, 2017 Share Posted September 28, 2017 Notice: Undefined index: username in /home/site/script2.php on line 14 How about the first script? Did you add the error code there? Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552059 Share on other sites More sharing options...
steveo314 Posted September 28, 2017 Author Share Posted September 28, 2017 How about the first script? Did you add the error code there? <?php session_start(); error_reporting(E_ALL); ini_set('display_errors', 1); first thing on both scripts Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552060 Share on other sites More sharing options...
cyberRobot Posted September 28, 2017 Share Posted September 28, 2017 So...you didn't get any errors with the first script? Note that you'll need to comment out / delay the header() redirect. Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552065 Share on other sites More sharing options...
steveo314 Posted September 28, 2017 Author Share Posted September 28, 2017 (edited) So...you didn't get any errors with the first script? Note that you'll need to comment out / delay the header() redirect. I don't get anything when i comment the 'header();' just a white screen Edited September 28, 2017 by steveo314 Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552066 Share on other sites More sharing options...
cyberRobot Posted September 28, 2017 Share Posted September 28, 2017 Are the first and second scripts on the same website? If so, try simplifying the process. Build a script that does nothing but create a session variable. Then create a second script that only attempts to display the variable. Of course, you'll still need to call session_start(). Do the scripts work if you visit the first and then the second? Are you using sessions successfully elsewhere on the same website? Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552068 Share on other sites More sharing options...
cyberRobot Posted September 28, 2017 Share Posted September 28, 2017 Do you manage the server where these scripts are posted or does someone else? If someone else, did you check with your host to see if something changed with PHP sessions? Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552069 Share on other sites More sharing options...
steveo314 Posted September 28, 2017 Author Share Posted September 28, 2017 Are the first and second scripts on the same website? If so, try simplifying the process. Build a script that does nothing but create a session variable. Then create a second script that only attempts to display the variable. Of course, you'll still need to call session_start(). Do the scripts work if you visit the first and then the second? Are you using sessions successfully elsewhere on the same website? I am trying to work on simplifying the whole thing. The process is spread out over too many scripts. Do you manage the server where these scripts are posted or does someone else? If someone else, did you check with your host to see if something changed with PHP sessions? We use a host. They handle the os admin. Whatever files and scripts are on it other than that I manage. They don't do earth shaking updates without notification. This came up when I was still on PHP5.6 and they put me at PHP7 yesterday. I have checked with them several times on what they have changed since this came up. Nothing until yesterday. Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552070 Share on other sites More sharing options...
cyberRobot Posted September 28, 2017 Share Posted September 28, 2017 I am trying to work on simplifying the whole thing. The process is spread out over too many scripts. Just to clarify, the simplified scripts would only be for testing. Basically, you can ignore everything else. We just want to know if session variables are actually working. For example, here would be script1.php: <?php session_start(); $_SESSION['test'] = 'hello'; ?> <a href="script2.php">Go to next script</a> Here is script2.php: <?php session_start(); print '<pre>' . print_r($_SESSION, true) . '</pre>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552072 Share on other sites More sharing options...
steveo314 Posted September 28, 2017 Author Share Posted September 28, 2017 (edited) Just to clarify, the simplified scripts would only be for testing. Basically, you can ignore everything else. We just want to know if session variables are actually working. For example, here would be script1.php: <?php session_start(); $_SESSION['test'] = 'hello'; ?> <a href="script2.php">Go to next script</a> Here is script2.php: <?php session_start(); print '<pre>' . print_r($_SESSION, true) . '</pre>'; ?> script1.php gives: Go to next script script2.php gives: Array ( ) Notice: Undefined index: username in /home/website/script1.php on line 14 Notice: Undefined index: test in /home/website/script2.php on line 15 line 14 is: $username = $_SESSION['username']; line 15 is: $test = $_SESSION['test']; cyberRobot, this is lines 1-13 of script2.php when I ran it with your debug lines: <?php session_start(); error_reporting(E_ALL); ini_set('display_errors', 1); if(session_status() != PHP_SESSION_ACTIVE) { echo "Session not active, script2.php"; sleep(1); } echo '<pre>' . print_r($_SESSION, true) . '</pre>'; //if($_SESSION['username'] == "") { //echo "Username is blank"; //sleep(1); //} Edited September 28, 2017 by steveo314 Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552075 Share on other sites More sharing options...
ginerjm Posted September 28, 2017 Share Posted September 28, 2017 Why not show us the first 15 lines of script1 Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552076 Share on other sites More sharing options...
steveo314 Posted September 28, 2017 Author Share Posted September 28, 2017 (edited) Why not show us the first 15 lines of script1 <?php session_start(); error_reporting(E_ALL); ini_set('display_errors', 1); if(session_status() != PHP_SESSION_ACTIVE) { echo "Session not active, script1.php"; sleep(1); } $iconnect = mysqli_connect("localhost","user","pass","db"); if(isset($_POST['submit'])) { //$username = htmlentities($_REQUEST['username']); //$password = htmlentities($_REQUEST['password']); $username = $_POST['username']; $password = $_POST['password']; $_SESSION['test'] = 'hello'; $_SESSION['username'] = $username; $_SESSION['password'] = $password; $password = md5($password); $valid = checkinput($username,$password); if($valid == true) { $valid = checkuser($username,$password,$iconnect); if($valid == true) { if($username != "") { header( 'refresh: 0; url=https://website/script2.php' ); exit; Edited September 28, 2017 by steveo314 Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552077 Share on other sites More sharing options...
steveo314 Posted September 28, 2017 Author Share Posted September 28, 2017 function checkinput($username,$password) { if($username == "" or $password == "") { return false; } else { return true; } } function checkuser($username,$password,$iconnect) { $checkquery = "SELECT username, password FROM users WHERE username='$username' AND password='$password'"; if($result = mysqli_query($iconnect,$checkquery)) { return true; } else { return false; } } function failed($reasons) { echo "<p>There are some problems with your login credentials:</p><p><b>$reasons</b></p>"; } Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552078 Share on other sites More sharing options...
ginerjm Posted September 28, 2017 Share Posted September 28, 2017 From what I can see of your code, you have no $_POST array since I don't see any form code nor any form begin displayed from script1. Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552079 Share on other sites More sharing options...
steveo314 Posted September 28, 2017 Author Share Posted September 28, 2017 (edited) From what I can see of your code, you have no $_POST array since I don't see any form code nor any form begin displayed from script1. script1.php is the action of the html form which is in reply #19. Do I need to have more in the lines I shared of script1.php in reply #36? Edited September 28, 2017 by steveo314 Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552080 Share on other sites More sharing options...
mac_gyver Posted September 28, 2017 Share Posted September 28, 2017 the error_reporting and display_errors settings need to go before the session_start(), so that any errors with the session start will be reported and displayed. are you on a cheap/free web host that might have disabled the error_reporting() and ini_set() statements so that the error_reporting and display_errors settings aren't doing anything? Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552081 Share on other sites More sharing options...
steveo314 Posted September 28, 2017 Author Share Posted September 28, 2017 the error_reporting and display_errors settings need to go before the session_start(), so that any errors with the session start will be reported and displayed. are you on a cheap/free web host that might have disabled the error_reporting() and ini_set() statements so that the error_reporting and display_errors settings aren't doing anything? I moved those two lines up on each script. No additional errors besides whats in reply #34. I don't know how Westhost fares... Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552082 Share on other sites More sharing options...
steveo314 Posted September 29, 2017 Author Share Posted September 29, 2017 (edited) When I do this on script2.php $_SESSION isn't empty <?php //error_reporting(E_ALL); //ini_set('display_errors', 1); session_start(); echo session_id(); echo '<pre>'.print_r($_SESSION,true).'</pre>'; But when I change it to this it is empty <?php //error_reporting(E_ALL); //ini_set('display_errors', 1); session_start(); echo '<pre>'.print_r($_SESSION,true).'</pre>'; The session ids match between script1.php and script2.php no matter what also. Edited September 29, 2017 by steveo314 Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552146 Share on other sites More sharing options...
steveo314 Posted October 13, 2017 Author Share Posted October 13, 2017 Do you manage the server where these scripts are posted or does someone else? If someone else, did you check with your host to see if something changed with PHP sessions? I didn't think thats what it was but.... There is a php.ini on a root dir that I cannot get to on my server. My hosting company has access to it. Something was changed on it. session dir was commented out on my php.ini, which overrides theirs. A month and a half of thinking I had a bad piece of code and it was because something was commented out in my php.ini. Quote Link to comment https://forums.phpfreaks.com/topic/305075-session_start/page/2/#findComment-1552680 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.