7 Replies - 531 Views - Last Post: 02 May 2011 - 10:23 AM Rate Topic: -----

#1 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Session working on 1 page but not the other

Posted 02 May 2011 - 04:46 AM

Hello i am working on a register script which can be found here
http://www.pokemonto...rt/register.php

I am making a random number e.g
10 <-- random number
Type The Number You See


It prints off fine on the register page then when i take it to any other page e.g the progress.php to check its the same number it fails
I have been having problems with my hosting. That session start is always set so i do not need to set the session ever.


My pages

    <?php

srand ((double) microtime( )*1000000);
$random_number = rand(0,10);
 $_SESSION['random_number2'] = $random_number ;
?> 
  
</div>
<form method="post" action="progress.php">



<p align="center"> Name: </p>
<div align="center">
  <input type="text" size="30" maxlength="40" name="name"> 
  <br />
</div>
<p align="center">Password: </p>
<div align="center">
  <input type="password" size="30" maxlength="10" name="password">
  
</div>
<p align="center">Pick a starter pokemon:</p>
<p align="center">&nbsp;</p>
<div id="div4">
  <div align="center"><img src="pokemonsprites/ButterfreeNormalSprite.gif" width="64" height="64" /></div>
</div>
<p align="center">
  <input type="radio" name="size" value="Butterfree">
  Butterfree  </p>
<div id="layer">
  <div align="center"><img src="pokemonsprites/HaunterNormalSprite.gif" width="64" height="64" /></div>
</div>
<p align="center">
    <input type="radio" name="size" value="Haunter">
  Haunter</p>
<div id="div">
  <div align="center"><img src="pokemonsprites/MareepNormalSprite.gif" width="64" height="64" /></div>
</div>
<p align="center">
    <input type="radio" name="size" value="Mareep" />
  Mareep</p>
<div id="div2">
  <div align="center"><img src="pokemonsprites/PidgeyNormalSprite.gif" width="64" height="64" /></div>
</div>
<p align="center">
    <input type="radio" name="size" value="Pidgey" />
  Pidgey</p>
<div id="div3">
  <div align="center"><img src="pokemonsprites/WeezingNormalSprite.gif" width="64" height="64" /></div>
</div>
<p align="center">
    <input type="radio" name="size" value="Weezing" />
  Weezing</p>
<p align="center">

<?php
echo  $_SESSION['random_number2'] ;



?>
<p align="center">Type The Number You See 
<div align="center">
  <input type="number" size="30" maxlength="10" name="number" />
  &nbsp;
  </p>
</div>
<p align="center"><br />
  
  
  
  <input type="submit" value="Email Myself">
</p>
</form>


<?php

var_dump($_SESSION);
error_reporting(E_ALL);

?>




progress.php

<?php


$size = $_POST['size'];

echo $_POST['size'] ;

$_SESSION['therenumber'] = $_POST['number'] ;

echo $_SESSION['random_number2'];

?>



<?php
if  ($_SESSION['therenumber'] ==  $_SESSION['random_number2'])
 {
  echo "Lets Go Baby" ;
}
else {
print ("opps you got the number wrong");
}

 
?>

<?php

 
  var_dump($_SESSION);
  error_reporting(E_ALL);
 
 ?>




I am getting this error Parse error: syntax error, unexpected T_ECHO in /home/nick1200/public_html/toxicfreshstart/progress.php on line 18

That error means ive missed a ' on line 18 but line 18 is
echo $_SESSION['random_number2'];

I think its because it ent being set

P.s all the other posts session are being set just not that 1

This post has been edited by nick1200: 02 May 2011 - 10:25 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Session working on 1 page but not the other

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2895
  • View blog
  • Posts: 10,027
  • Joined: 08-August 08

Re: Session working on 1 page but not the other

Posted 02 May 2011 - 07:04 AM

I see no:
session_start();

Was This Post Helpful? 0
  • +
  • -

#3 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: Session working on 1 page but not the other

Posted 02 May 2011 - 07:10 AM

Apart from the no session_start() on each page. Line #8 in progress.php has no semicolon at the end of the line.
Was This Post Helpful? 0
  • +
  • -

#4 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: Session working on 1 page but not the other

Posted 02 May 2011 - 07:22 AM

View PostCTphpnwb, on 02 May 2011 - 08:04 AM, said:

I see no:
session_start();

like i have said with hostgator they start the session for you all ready
so no need to start the session and if i start the session it shows a error session is all ready set

View Postcodeprada, on 02 May 2011 - 08:10 AM, said:

Apart from the no session_start() on each page. Line #8 in progress.php has no semicolon at the end of the line.


That has fixed the error but it still not getting $_SESSION['random_number2']
if you try and enter the number it shows you it says its wrong because the progress page ent getting the echo $_SESSION['random_number2'] and donno why

This post has been edited by nick1200: 02 May 2011 - 07:26 AM

Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2895
  • View blog
  • Posts: 10,027
  • Joined: 08-August 08

Re: Session working on 1 page but not the other

Posted 02 May 2011 - 08:26 AM

Ok, so where do you set this?
$_SESSION['random_number2']
Was This Post Helpful? 0
  • +
  • -

#6 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: Session working on 1 page but not the other

Posted 02 May 2011 - 09:28 AM

View PostCTphpnwb, on 02 May 2011 - 09:26 AM, said:

Ok, so where do you set this?
$_SESSION['random_number2']


by here
 <?php

srand ((double) microtime( )*1000000);
$random_number = rand(0,10);
 $_SESSION['random_number2'] = $random_number ;
?> 





On the register page then i echo it out on the register page


<?php
echo  $_SESSION['random_number2'] ;
?>
<p align="center">Type The Number You See 




Which works fine but then when it goes over to process.php it goes
Was This Post Helpful? 0
  • +
  • -

#7 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: Session working on 1 page but not the other

Posted 02 May 2011 - 10:13 AM

I'm still skeptical about hostgator starting sessions automatically. Dump the session on both pages and compare the data.

var_dump($_SESSION);


Also for debugging purposes place this at the top of your page

error_reporting(E_ALL);

Was This Post Helpful? 0
  • +
  • -

#8 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: Session working on 1 page but not the other

Posted 02 May 2011 - 10:23 AM

View Postcodeprada, on 02 May 2011 - 11:13 AM, said:

I'm still skeptical about hostgator starting sessions automatically. Dump the session on both pages and compare the data.

var_dump($_SESSION);


Also for debugging purposes place this at the top of your page

error_reporting(E_ALL);


On register.php im getting

array(1) { ["random_number2"]=> int(10) } 


with no error's


Then on progress.php im getting

array(1) { ["therenumber"]=> string(2) "10" } 



with no error's but page dies

page can be found here http://www.pokemonto...rt/register.php

I have also updated the source code on here with the changes
The dump shows that random_number2 ent cumming over

This post has been edited by nick1200: 02 May 2011 - 10:29 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1