473,395 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Another php session problem

This is my code"
Expand|Select|Wrap|Line Numbers
  1. <?php if(!session_start()) { exit(); }else{ session_start(); $sessid = session_id(); }?>
  2. // some html code
  3.       <?
  4.       // here is part a
  5.       $_SESSION['x'] = "hello world!"; echo $_SESSION['x'];
  6.       if (isset($_GET['admin'])) {
  7.       include("include/admin.inc.php");
  8.       }else if ($_GET['a'] == "l") {
  9.       $query = "SELECT * FROM `login_attempt` WHERE ip = '$userip';";
  10.       $query = mysql_query($query);
  11.       if(mysql_num_rows($query) == 0) {
  12.       $query1 = 'INSERT INTO `login_attempt` (`ip` ,`attempt_left` ,`expire`) VALUES ("' . $userip . '", "5", DATE_ADD(NOW(), INTERVAL 1 HOUR));';
  13.       mysql_query($query1);
  14.       }
  15.       if(mysql_num_rows($query) != 0) {
  16.        while($info = mysql_fetch_array($query)) {
  17.        $log_left_times = $info['attempt_left'];
  18.        $log_exp = $info['expire'];
  19.        }
  20.       }
  21.       require('func/CalculateMonthSecond.func.php');
  22.       $log_exp = str_split($log_exp);
  23.       $year = $log_exp[0] . $log_exp[1] . $log_exp[2] . $log_exp[3];
  24.       $month = $log_exp[5] . $log_exp[6];
  25.       $day = $log_exp[8] . $log_exp[9];
  26.       $hour = $log_exp[11] . $log_exp[12];
  27.       $minute = $log_exp[14] . $log_exp[15];
  28.       $second = $log_exp[17] . $log_exp[18];
  29.       $y_s = 31536000*$year;
  30.       $m_s = CalculateMonthSecond($year, $month);
  31.       $d_s = $day*86400;
  32.       $h_s = $hour*3600;
  33.       $m_s2 = $minute*60;
  34.       $s_s = $second;
  35.       $expire_second = $y_s+$m_s+$d_s+$h_s+$m_s2+$s_s;
  36.       $year2 = date('Y');
  37.       $month2 = date('m');
  38.       $day2 = date('d');
  39.       $hour2 = date('H');
  40.       $minute2 = date('i');
  41.       $second2 = date('s');
  42.       $y_s2 = 31536000*$year2;
  43.       $m_s2 = CalculateMonthSecond($year2, $month2);
  44.       $d_s2 = $day2*86400;
  45.       $h_s2 = $hour2*3600;
  46.       $m_s3 = $minute2*60;
  47.       $s_s2 = $second2;
  48.       $now_second = $y_s2+$m_s2+$d_s2+$h_s2+$m_s3+$s_s2;
  49.       if($expire_second < $now_second) {
  50.       $query_updEXP = 'UPDATE `login_attempt` SET `attempt_left` = "5"' . ' WHERE `ip` = "' . $userip . '";';
  51.       mysql_query($query_updEXP);
  52.       }
  53.       $query = "SELECT * FROM `login_attempt` WHERE ip = '$userip';";
  54.       $query = mysql_query($query);
  55.       if(isset($_POST['account']) && isset($_POST['password'])) {
  56.       if ($expire_second < $now_second) {
  57.       $expired = 1;
  58.       }else{
  59.       $expired = 0;
  60.       }
  61.       $account = SQLInjectionFilter($_POST['account']);
  62.       $password = hash("sha256", $_POST['password']);
  63.       $query = "Select * FROM `user` WHERE username = $account AND password = '$password';";
  64.       $query = mysql_query($query);
  65.       if($log_left_times <= 0 && $expired == 0) {
  66.       $query_z = 'update `login_attempt` set `expire` = DATE_ADD(NOW(), INTERVAL 1 HOUR) WHERE `ip` = "' . $userip . '";';
  67.       mysql_query($query_z);
  68.       $s = 3;
  69.       }else if ($log_left_times >= 0 && expired == 1) {
  70.         if(mysql_num_rows($query) != 0) {
  71.            $_SESSION['logined'] == '1';
  72.         $_SESSION['logined_time'] == date("r");
  73.         $_SESSION['account'] == $_POST['account'];
  74.         echo $_SESSION['logined'];
  75.         // here is part b
  76.         $_SESSION['x'] = "hello world!"; echo $_SESSION['x'];
  77.         $s = 2;
  78.         }else{
  79.         $log_left_times = $log_left_times-1;
  80.         $query_updEXP_2 = 'UPDATE `login_attempt` SET `attempt_left` = "' . $log_left_times . '"' . ' WHERE `ip` = "' . $userip . '";';
  81.         $query_updEXP_3 = 'update `login_attempt` set `expire` = DATE_ADD(NOW(), INTERVAL 1 HOUR) WHERE `ip` = "' . $userip . '";';
  82.         mysql_query($query_updEXP_2);
  83.         mysql_query($query_updEXP_3);
  84.         $s = 1;
  85.         }
  86.       }else if ($log_left_times > 0) {
  87.         if(mysql_num_rows($query) != 0) {
  88.            $_SESSION['logined'] == '1';
  89.         $_SESSION['logined_time'] == date("r");
  90.         $_SESSION['account'] == $_POST['account'];
  91.         echo $_SESSION['logined'];
  92.         // here is part b
  93.         $_SESSION['x'] = "hello world!"; echo $_SESSION['x'];
  94.         $s = 2;
  95.         }else{
  96.         $log_left_times = $log_left_times-1;
  97.         $query_updEXP_2 = 'UPDATE `login_attempt` SET `attempt_left` = "' . $log_left_times . '"' . ' WHERE `ip` = "' . $userip . '";';
  98.         $query_updEXP_3 = 'update `login_attempt` set `expire` = DATE_ADD(NOW(), INTERVAL 1 HOUR) WHERE `ip` = "' . $userip . '";';
  99.         mysql_query($query_updEXP_2);
  100.         mysql_query($query_updEXP_3);
  101.         $s = 1;
  102.         }
  103.       }
  104.     }
  105.       require("include/login.inc.php");
  106.       }else if ($_GET['a'] == "r") {
  107.       include("include/register.inc.php");
  108.         }else if ($_GET['a'] == "c") {
  109.         include("include/contact.inc.php");
  110.         }else if ($_GET['a'] == "f") {
  111.        include("include/faq.inc.php");
  112.       }else if ($_GET['a'] == "t") {
  113.       include("include/tos.inc.php");
  114.       }else if ($_GET['a'] == "a") {
  115.       require ("include/account.inc.php");
  116.          }else if ($_GET['a'] == "b") {
  117.       include ("include/banner.inc.php");
  118.       }else    if (!isset($_GET['a']) OR $_GET['a'] == "" OR $_GET['a'] == "h") {  
  119.       include("include/index.inc.php");
  120.       }
  121.       ?>
  122. // some html code
  123.  
in part a, it can print out hello world!, but in part b, it didn't print out anything!

So how to fix this?

Thanks!
Jul 19 '10 #1

✓ answered by matthewlkc

my father say
may be your "else" is not match with"if"
check it angin

3 1442
dlite922
1,584 Expert 1GB
For basic stuff like this, you sometimes have to reduce your code to absolute minimum and hard code some data if needed to try to pin point the problem.

This is a useful skill that all programmers should have, thus you should not be robbed of opportunities to do this yourself.

1. Save this file and rename it as something else

2. Take out all the queries and logic

3. Leave the session code the way it "should" work and debug from there.


Good luck,


Dan
Jul 19 '10 #2
my father say
may be your "else" is not match with"if"
check it angin
Jul 19 '10 #3
Thanks, my problem sloved, also, i want choose both of you as the best ans. but i found it there is some if and else problem in my script, however thanks dan!
Jul 20 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Roman | last post by:
Hi, I've installed .net on my server and since then I'm loosing my sessions from my (old) asp. e.g.: Session("test") works on the same page, but if the page is changed the whole session is...
3
by: David W. Fenton | last post by:
A very old app of mine that's been in production use, and largely unchanged since about 1998 has started recently throwing error 3188 (can't update, locked by another session on this machine) when...
1
by: caldera | last post by:
Hello, We have a session problem. A dataset is put into a session and call this session value later. When we run this web page in http://localhost it works. But server has a specific name like...
4
by: Ryan Moore | last post by:
I'm using Forms Authentication for user logins in an ASP.NET app. Is there any way to log out another Session when a user logs in? Example: The site only allows 10 users to be logged in at...
1
by: Axel Dahmen | last post by:
Hi, today I've had a strange DTS error: In one of my transformations I'd been using several Copy Column transformations + one ActiveX transformation using a lookup function. This lookup function...
4
by: alan | last post by:
Hi, i have some problem in asp.net session problem in page_load -> i have Label1.text = Session("a") in DataGrid1_sortCommand -> i have Session("a") = e.sortExpression
1
by: Mark Reed | last post by:
Hi All, I'm having a problem with the following code. I've read quite a lot of old posts regarding the issue but none seem to affer a solution. The scenario is. I have a bound form which...
0
by: Access Programming only with macros, no code | last post by:
ERROR MESSAGE: Could not update; currently locked by another session on this machine. BACKGROUND I have the following objects: Table1 - HO (which has about 51,000+ records) Table2 -...
7
by: beary | last post by:
Sorry if this seems obvious to some, but On the "check" page I have session_start(); $_SESSION=$subjectshort; $_SESSION='horse'; header( "Location: admin.php" );
2
by: Kong Chun Ho | last post by:
Hi all, I have a php session problem when i echo a session_id, it return nothing! <?php if(!session_start()) { exit(); }else{ ob_start(); session_start(); echo session_id(); echo SID;...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.