problem in setting session

Thread Solved

Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

problem in setting session

 
0
  #1
Feb 20th, 2008
hi there,
i have started session in my first page(login page). on fulfilling the validations the user is taken to the next page. in the second page, first i check whether session is set or not, and if it is not set the flash an error message to the user that he/she shlould login first. while validating in my login page if all the validations are successful i set a session variable and this variable i check in the next page. now my problem is that even after succesful login my next page is showing that session is not set. please help me fast.thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 36
Reputation: tirivamwe is an unknown quantity at this point 
Solved Threads: 2
tirivamwe's Avatar
tirivamwe tirivamwe is offline Offline
Light Poster

Re: problem in setting session

 
0
  #2
Feb 20th, 2008
can u give us the code that u have so that we can see where u are getting it wrong
If you find this useful you can add to my reputation
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 158
Reputation: richie513 is an unknown quantity at this point 
Solved Threads: 11
richie513's Avatar
richie513 richie513 is offline Offline
Junior Poster

Re: problem in setting session

 
0
  #3
Feb 20th, 2008
are you putting session_start() at the top of all the pages that require the session?
Technology is just a tool. In terms of getting the kids working together and motivating them, the teacher is the most important.
richie513
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: problem in setting session

 
0
  #4
Feb 20th, 2008
Are you starting the session in page2 ? If your answer is yes, then you need to show us your code. If your answer is no, then start the session !
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: problem in setting session

 
0
  #5
Feb 20th, 2008
Originally Posted by richie513 View Post
are you putting session_start() at the top of all the pages that require the session?
You beat me by few seconds
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 158
Reputation: richie513 is an unknown quantity at this point 
Solved Threads: 11
richie513's Avatar
richie513 richie513 is offline Offline
Junior Poster

Re: problem in setting session

 
0
  #6
Feb 20th, 2008
Originally Posted by nav33n View Post
You beat me by few seconds
lol sorry about that
Technology is just a tool. In terms of getting the kids working together and motivating them, the teacher is the most important.
richie513
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: problem in setting session

 
0
  #7
Feb 20th, 2008
i have done session_start() in my pages
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: problem in setting session

 
1
  #8
Feb 20th, 2008
Then code please !
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: problem in setting session

 
0
  #9
Feb 20th, 2008
login1.php
  1. <?php
  2. session_start();
  3. ob_start();
  4. ?>
  5. <?php
  6. mysql_connect("IP addr","username","password") or die(mysql_error());
  7.  
  8.  
  9.  
  10. mysql_select_db("login") or die(mysql_error());
  11.  
  12. //if login form is submitted
  13.  
  14. if(isset($_POST['submit'])) { //if form is submitted
  15.  
  16. //check whether all the fields are filled or not
  17.  
  18. if(!$_POST['username'] | !$_POST['pass']) {
  19. die('You did not fill all the fields.');
  20. }
  21.  
  22. //verifies against database
  23. $_POST['username']=md5($_POST['username']);
  24. if(!get_magic_quotes_gpc()) {
  25. $_POST['username']=addslashes($_POST['username']);
  26. }
  27.  
  28.  
  29.  
  30. $check=mysql_query("SELECT * FROM users WHERE username='".$_POST['username']."'") or die(mysql_error());
  31. //gives error if user doesnot exist
  32. //{
  33.  
  34. $check2=mysql_num_rows($check);
  35.  
  36. if($check2==0) {
  37. die('User does not exist');
  38. }
  39. while($info=mysql_fetch_array($check))
  40. {
  41.  
  42.  
  43. $_POST['pass']=stripslashes($_POST['pass']);
  44.  
  45.  
  46. $info['password']=stripslashes($info['password']);
  47. $_POST['pass']=md5($_POST['pass']);
  48.  
  49.  
  50. //gives error if password is wrong
  51.  
  52. if($_POST['pass'] !=$info['password']) {
  53. die('incorrect password,please try again.');
  54. }
  55. else
  56. //if login is ok then direct them to options page
  57. {
  58. $_SESSION['views'] = 1;
  59. header("Location:option1.php");
  60. ob_flush();
  61.  
  62. ?>
  63. <!META HTTP-EQUIV="Refresh" CONTENT="0; URL=option1.php">
  64. <?php
  65. }
  66. }
  67. }
  68. else
  69. {
  70. //if they are not logged in
  71.  
  72. ?>
  73.  
  74. <form action="<?PHP echo $_SERVER['PHP_SELF']?>" method="post">
  75. <table border="0">
  76. <tr><td>Username:</td><td>
  77. <input type="text" name="username" maxlength="50">
  78. </td></tr>
  79. <tr><td>Password:</td><td>
  80. <input type="password" name="pass" maxlength="50">
  81. </td></tr>
  82. <tr><td colspan="2" align="right">
  83. <input type="submit" name="submit" value="Login">
  84. </td></tr>
  85. </table>
  86. </form>
  87. <?php
  88. }
  89. ?>

option1.php
  1. <?php
  2. session_start();
  3. ob_start();
  4. if(isset($_SESSION['views']))
  5. $_SESSION['views']=$_SESSION['views']+1;
  6. else
  7. {
  8. //header("Location:message.php");
  9. echo "session not set"."</br>";
  10. print_r($_SESSION);
  11. }
  12. ?>

a long code :-)
Last edited by carobee; Feb 20th, 2008 at 3:16 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: problem in setting session

 
0
  #10
Feb 20th, 2008
I don't see anything wrong with the code apart from this line. if(!$_POST['username'] | !$_POST['pass']) { It should have been
if(!$_POST['username'] || !$_POST['pass']) { . Thats just a syntax error. The code isn't long ! lol.. it has just 80+ lines. Anyway, Check if its entering the else { $_SESSION['views'] part. If its entering the else part, remove the meta tag and try again..

Edit: And btw, <!META HTTP-EQUIV="Refresh" CONTENT="0; URL=option1.php"> is wrong. What is "!" doing there ?

Edit 2: And, you are not printing $_SESSION['views'] in page 2
Last edited by nav33n; Feb 20th, 2008 at 3:43 am.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC