943,733 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1641
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 20th, 2008
0

problem in setting session

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 12
Posting Whiz in Training
carobee is offline Offline
209 posts
since Dec 2007
Feb 20th, 2008
0

Re: problem in setting session

can u give us the code that u have so that we can see where u are getting it wrong
Reputation Points: 11
Solved Threads: 2
Light Poster
tirivamwe is offline Offline
36 posts
since Oct 2005
Feb 20th, 2008
0

Re: problem in setting session

are you putting session_start() at the top of all the pages that require the session?
Reputation Points: 19
Solved Threads: 11
Junior Poster
richie513 is offline Offline
158 posts
since Feb 2008
Feb 20th, 2008
0

Re: problem in setting session

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 !
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Feb 20th, 2008
0

Re: problem in setting session

Click to Expand / Collapse  Quote originally posted by richie513 ...
are you putting session_start() at the top of all the pages that require the session?
You beat me by few seconds
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Feb 20th, 2008
0

Re: problem in setting session

Click to Expand / Collapse  Quote originally posted by nav33n ...
You beat me by few seconds
lol sorry about that
Reputation Points: 19
Solved Threads: 11
Junior Poster
richie513 is offline Offline
158 posts
since Feb 2008
Feb 20th, 2008
0

Re: problem in setting session

i have done session_start() in my pages
Reputation Points: 10
Solved Threads: 12
Posting Whiz in Training
carobee is offline Offline
209 posts
since Dec 2007
Feb 20th, 2008
1

Re: problem in setting session

Then code please !
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Feb 20th, 2008
0

Re: problem in setting session

login1.php
php Syntax (Toggle Plain Text)
  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
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 12
Posting Whiz in Training
carobee is offline Offline
209 posts
since Dec 2007
Feb 20th, 2008
0

Re: problem in setting session

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.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to untar a tar.gz file in php script
Next Thread in PHP Forum Timeline: hi.. need help..





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC