| | |
problem in setting session
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 205
Reputation:
Solved Threads: 11
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
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
•
•
Join Date: Dec 2007
Posts: 205
Reputation:
Solved Threads: 11
login1.php
option1.php
a long code :-)
php Syntax (Toggle Plain Text)
<?php session_start(); ob_start(); ?> <?php mysql_connect("IP addr","username","password") or die(mysql_error()); mysql_select_db("login") or die(mysql_error()); //if login form is submitted if(isset($_POST['submit'])) { //if form is submitted //check whether all the fields are filled or not if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill all the fields.'); } //verifies against database $_POST['username']=md5($_POST['username']); if(!get_magic_quotes_gpc()) { $_POST['username']=addslashes($_POST['username']); } $check=mysql_query("SELECT * FROM users WHERE username='".$_POST['username']."'") or die(mysql_error()); //gives error if user doesnot exist //{ $check2=mysql_num_rows($check); if($check2==0) { die('User does not exist'); } while($info=mysql_fetch_array($check)) { $_POST['pass']=stripslashes($_POST['pass']); $info['password']=stripslashes($info['password']); $_POST['pass']=md5($_POST['pass']); //gives error if password is wrong if($_POST['pass'] !=$info['password']) { die('incorrect password,please try again.'); } else //if login is ok then direct them to options page { $_SESSION['views'] = 1; header("Location:option1.php"); ob_flush(); ?> <!META HTTP-EQUIV="Refresh" CONTENT="0; URL=option1.php"> <?php } } } else { //if they are not logged in ?> <form action="<?PHP echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="50"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?>
option1.php
php Syntax (Toggle Plain Text)
<?php session_start(); ob_start(); if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else { //header("Location:message.php"); echo "session not set"."</br>"; print_r($_SESSION); } ?>
a long code :-)
Last edited by carobee; Feb 20th, 2008 at 3:16 am.
I don't see anything wrong with the code apart from this line.
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
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*
*PM asking for help will be ignored*
![]() |
Similar Threads
- IE6/IE7 unexpectedly drops the PHP Session ID cookie (PHPSESSID) (PHP)
- How to open a .exe file in the foreground (Perl)
- How to expire a session (PHP)
- parameter passing thru on click for different buttons (ASP)
- PHP MySQL problem (PHP)
- Problem in session using php5 (PHP)
- Losing session variable problem...help! (ASP)
- Setting parameters for non-use session logoff (Windows NT / 2000 / XP)
- Newbie Needs Help (Perl)
Other Threads in the PHP Forum
- Previous Thread: how to untar a tar.gz file in php script
- Next Thread: hi.. need help..
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web webdesign websphere white xml youtube






