Jump to content

Recommended Posts

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 by steveo314

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?

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.

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>';
?>

 

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 by steveo314

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 by steveo314

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>";
}

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 by steveo314

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?

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...

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 by steveo314
  • 2 weeks later...

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.

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.