Jump to content

[SOLVED] Advice on Sessions


oceans

Recommended Posts

Hi,

If u running ur own local pc then just download and install WAMP or XAMPP.

It has no need to make changes in php.ini and some other files.

If u r on ur remote server then verify either the host has gave u the permission to edit or not.

If no then ask ur host to do for u.

Thats all.

Hope this will help u.

 

Link to comment
Share on other sites

OK,

 

I uninstalled php,mySql, turned off iis,

then installed wamps.

 

I put this before html Page 1

 

<?php

session_start();

$_SESSION['views']=0;

?>

 

I put this in the middle of <?PHP bla bla bla  ?> Page 1

 

$_SESSION['views']=10;

header("location: Page2.php");

 

I put this before html Page 2

 

<?php

session_start();

?>

 

I put this in the middle of <?PHP bla bla bla  ?> Page 2

 

echo "Pageviews=". $_SESSION['views'];

 

response on the screen is

 

Pageviews=

 

But no error message.

 

 

Link to comment
Share on other sites

Thanks mmarif4u,

 

(Page 1)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php

session_start();

$_SESSION['email']=0;

?>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<?PHP

//Transfer Data from Screen to Memory

$NumberOfTxtBoxes=1;

$NumberOfTxtBoxesToBeFilled=1;

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

{

for ($i=1; $i<=$NumberOfTxtBoxes; $i++)

{

$InputFromScreen[$i]=strtoupper($_POST["Txt".$i]);

}

}

else

{

for ($i=1; $i<=$NumberOfTxtBoxes; $i++)

{

$InputFromScreen[$i]="";

}

}

?>

<form id="form1" name="form1" method="post" action="0301SignUp.php">

  <table width="499" border="0" cellpadding="5" cellspacing="0">

    <tr>

      <td width="131"><span class="WorkPageFieldHead">Email Address</span></td>

      <td width="348"><span class="WorkPageField">

        <input name="Txt1" type="text" class="WorkPageField" id="Txt1" value="<?PHP echo $InputFromScreen[1]; ?>" size="30" maxlength="30" />

      </span></td>

    </tr>

    <tr>

      <td> </td>

      <td>

<?PHP

//Checking for Unfilled Fields

$TxtBoxesNotFullyFilled=0;

for ($i=1; $i<=$NumberOfTxtBoxesToBeFilled; $i++)

{

if ($InputFromScreen[$i]=="")

{

$TxtBoxesNotFullyFilled=1;

break;

}

}

if ($TxtBoxesNotFullyFilled==1)

{

echo "All Fields Should be Filled!";

}

else

{

$_SESSION['email']=Txt1;

header("location: 0302SignUp.php");

}

?>

</td>

    </tr>

    <tr>

      <td> </td>

      <td><input type="Submit" name="Submit" value="Submit" /></td>

    </tr>

  </table>

</form>

</body>

</html>

 

(Page2)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php

session_start();

?>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<?PHP

//Temp Statement to be removed later

echo "Email Address= ". $_SESSION['email'];

 

//Transfer Data from Screen to Memory

$NumberOfTxtBoxes=2;

$NumberOfTxtBoxesToBeFilled=2;

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

{

for ($i=1; $i<=$NumberOfTxtBoxes; $i++)

{

$InputFromScreen[$i]=strtoupper($_POST["Txt".$i]);

}

}

else

{

for ($i=1; $i<=$NumberOfTxtBoxes; $i++)

{

$InputFromScreen[$i]="";

}

}

?>

<form id="form1" name="form1" method="post" action="0302SignUp.php">

  <table width="499" border="0" cellpadding="5" cellspacing="0">

    <tr>

      <td width="131"><span class="WorkPageFieldHead">Email Address</span></td>

      <td width="348"><span class="WorkPageField">

        <input name="Txt1" type="text" class="WorkPageField" id="Txt1" value="<?PHP echo $InputFromScreen[1]; ?>" size="30" maxlength="30" />

      </span></td>

    </tr>

    <tr>

      <td>Verification Key</td>

      <td><span class="WorkPageField">

        <input name="Txt2" type="text" class="WorkPageField" id="Txt2" value="<?PHP echo $InputFromScreen[2]; ?>" size="30" maxlength="30" />

      </span></td>

    </tr>

    <tr>

      <td><p> </p></td>

      <td><?PHP

//Checking for Unfilled Fields

$TxtBoxesNotFullyFilled=0;

for ($i=1; $i<=$NumberOfTxtBoxesToBeFilled; $i++)

{

if ($InputFromScreen[$i]=="")

{

$TxtBoxesNotFullyFilled=1;

break;

}

}

if ($TxtBoxesNotFullyFilled==1)

{

echo "All Fields Should be Filled!";

}

else

{

/*$con = mysql_connect("localhost","peter","abc123");

if ($con)

{

 

}

else

{

die('Could not connect: ' . mysql_error());

}

*/

//$_SESSION['views']=1;

header("location: 0303SignUp.php");

}

?></td>

    </tr>

    <tr>

      <td> </td>

      <td><input type="Submit" name="Submit" value="Submit" /></td>

    </tr>

  </table>

</form>

</body>

</html>

 

(i) Error I see when (page 1) loads:

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\MyPHP\Member\0301SignUp.php:2) in C:\wamp\www\MyPHP\Member\0301SignUp.php on line 3

 

(ii) Error I see when I Input values into the feild:

 

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\MyPHP\Member\0301SignUp.php:2) in C:\wamp\www\MyPHP\Member\0301SignUp.php on line 60

 

Error (ii) did not appear when I used IIS, may be I twitched something in my code lately, thus this error, but the code seems ok.

 

Thanks for your offer to help.

 

Link to comment
Share on other sites

Try this:

<?php
ob_start();
session_start();
$_SESSION['email']=0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
The rest of code

 

Also do it for 2nd page, and then let me know what happened.

Link to comment
Share on other sites

U r welcome.

 

Actualley in php u have to put the sessions before the html is parsed.

So it means that at the top of the page before html or other php code.

Other if u put ob_start();

Then u can use session_start(); in every page.

Now i will recomend u to make a separate php page as(session.php) and

put all ur session variable there and include it on every page u want to put the

session.

But remember u have to include that file at very top of the page like:

<?php
require_once('session.php');
?>

 

Glad to solved out ur problem.

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.