Jump to content

Recommended Posts

it seems like a lot of people are having this same problem but I haven't found one solved topic that worked for me so  I'm gonna ask again.

 

page 1:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

//host name
$host = "localhost";
//mysql login info
$username = "root";
$password = "";
//DB info
$db_name = "syllabus";
//DB table info
$tbl_name = "syll";

//Connecting to server and selecting the DB
mysql_connect("$host", "$username","$password") or die ("cannot connect to the database");
mysql_select_db("$db_name") or die ("cannot select the database");

//send username and password from form
$user = $_POST['user'];
$pass = $_POST['pass'];

//protection for mysql
$user = stripslashes($user);
$pass = stripslashes($pass);
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);

$sql = "SELECT * FROM $tbl_name WHERE user='$user' and pass='$pass'";
$result = mysql_query($sql);

//Count rows
$count = mysql_num_rows($result);

// if there is a match there must be only one row
if ($count == 1)
{
	//register the session and redirect to next page
	session_start();
	$_SESSION['user'] = $user;
	$_SESSION['pass'] = $pass;
	session_write_close();
	if (isset($_SESSION['user']))
		{
			if (isset($_SESSION['pass']))
				{
				header("location:http://localhost/FinalPart5Form2.html");
		}		}
					}
else
{		
	echo "Invalid username $user or password $pass";
}
?>;

 

I did var dumping before session_write_close and both were set properly

 

page2:

<? 
//pass session over
ini_set ("display_errors", "1");
error_reporting(E_ALL | E_STRICT);
session_start(); var_dump($_SESSION['client']);
?>	
<html>
<body>
<h2>Form 2</h2>
<h3> Welcome, <?PHP echo $_SESSION['user']?>!</h3>
<p> Please complete your profile below.</p>
<form action="form2process.php" method="POST" target="_blank" >
Course Title: <input type="text" name="title" size="50" />
<br />
<br />
Instructor name: <input type="text" name="instname" size="40" />
<br />
<br />
Office Hours:
<p style="text-indent:50px">Room No: <input type="text" name="hrsroomno" size="38" /></p>
<p style="text-indent:50px">Days: <input type="text" name="hrsdays" size="42" /></p>
<p style="text-indent:50px">Time: <input type="text" name="hrstime" size="42" /></p>
Phone: <input type="text" name="phn" size="48" />
<br />
<br />
Email: <input type="text" name="email" size="49" />
<br />
<br />
Website: <input type="text" name="url" size="47" />
<br />
<br />
Course Description: <br /><textarea rows="10" cols="58" name="crsdes"> </textarea>
<br />
<br />
Book Recommendec: <br /><textarea rows="10" cols="58" name="bookrec"> </textarea>
<br />
<br />
Grading Scale:
<p style="text-indent:50px">Assignments(%): <input type="text" name="gradeassign" size="32" /></p>
<p style="text-indent:50px">Quiz(%): <input type="text" name="gradequiz" size="40" /></p>
<p style="text-indent:50px">Exam(%): <input type="text" name="gradeexam" size="40" /></p>
<br />
Syllabus: <br /><textarea rows="25" cols="150" name="syll"> </textarea>
<br />
<input type="submit" name="SubmitPart4B" value="Create!" />
</form>
</body>

 

when I did the var dumping on this page it returned NULL

Link to comment
https://forums.phpfreaks.com/topic/206435-passing-session-to-other-pages/
Share on other sites

If you are getting no php errors and the session variables don't carry over using the code you posted, then either -

 

1) You have disabled cookies in your browser and the session id cookie is not being propagated between the two pages, or

 

2) You are either changing the path in the URL or the hostname/subdomain in the URL, between the two pages, and the session id cookie is not setup to match any path/hostname than the one where it was set or you are changing the whole domain in the URL, or

 

3) Your php configuration is not setup to use sessions or to pass the session id using a cookie and/or on the end of the URL.

 

Edit: 4) ini_set() has been disabled on your server and you won't be seeing any php detected errors from the posted code.

 

To troubleshoot -

#1 - have you changed your browser configuration to block cookies and is a session id cookie being set in your browser after you browse to the first page?

 

#2 - what are the URL's of the two pages and what does a phpinfo() statement show for the session.cookie_path and session.cookie_domain settings?

 

#3 - what does a phpinfo() statement show for all the session... settings?

 

i have not changed any setting anywhere in the browser. I checked and there is a localhost cookie. 

 

All pages are accessed through http://localhost/...

 

here is the session info:

session.cookie_path / /

session.cookie_domain no value no value

 

session

Session Support enabled

Registered save handlers files user sqlite

Registered serializer handlers php php_binary wddx

 

I don't know if this what you meant by all the info but...

Directive Local Value Master Value

session.auto_start Off Off

session.bug_compat_42 On On

session.bug_compat_warn On On

session.cache_expire 180 180

session.cache_limiter nocache nocache

session.cookie_domain no value no value

session.cookie_httponly Off Off

session.cookie_lifetime 0 0

session.cookie_path / /

session.cookie_secure Off Off

session.entropy_file no value no value

session.entropy_length 0 0

session.gc_divisor 100 100

session.gc_maxlifetime 1440 1440

session.gc_probability 1 1

session.hash_bits_per_character 5 5

session.hash_function 0 0

session.name PHPSESSID PHPSESSID

session.referer_check no value no value

session.save_handler files files

session.save_path \xampp\tmp \xampp\tmp

session.serialize_handler php php

session.use_cookies On On

session.use_only_cookies Off Off

session.use_trans_sid 0 0

I don't see any setting problems.

 

Sessions are not that hard, what does the following two pieces of code do when you browser first to page1.php, then to page2.php -

 

page1.php

<?php
ini_set("display_startup_errors", "1");
ini_set("display_errors", "1");
error_reporting(E_ALL);

session_start();
$_SESSION['user'] = 'some value';
echo session_id();
?>

page2.php

<?php
ini_set("display_startup_errors", "1");
ini_set("display_errors", "1");
error_reporting(E_ALL);

session_start();
var_dump($_SESSION['user']);
echo session_id();
?>

I put the code in php file that processes the login form and connects to the database and the output i got is as follows

"k1ctl76d1v3u568hp2m82480p3

Notice: A session had already been started - ignoring session_start() in C:\xampp\htdocs\FinalPart5ProcessForm1.php on line 43

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\FinalPart5ProcessForm1.php:8) in C:\xampp\htdocs\FinalPart5ProcessForm1.php on line 51"

 

 

page1.php

<?php
ini_set("display_startup_errors", "1");
ini_set("display_errors", "1");
error_reporting(E_ALL);

session_start();
$_SESSION['user'] = 'some value';
echo session_id();
?>

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.