SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Strange problem with PHP

    Hi everyone, I'm having some trouble with a site I'm designing.
    These are the pages I'm working with:
    Index.php -> Control.php -> Main.php
    Index.php: has a form to enter user and pwd.
    Control.php: checks user, pwd and redirects the user to Main or Index depending on the correct values of these fields.
    Main.php: has the code of the program.

    Well, the thing is that if I open Index.php it calls Control.php, if there's any trouble in it (wrong pwd, wrong user, etc..) it calls an error function from error.php, but if everything's ok it doesn't let the user pass to Main.php unless you've previously made some mistake in entering the user or pwd.

    My control.php file looks like these:
    PHP (19 lines) ::
    PHP Code:
    <?php
    session_start
    (); 
    include 
    "errores.php";
    require (
    "db_config.inc.php");
       
    $sql "SELECT * FROM usuariosceros WHERE usuario = '".$_POST["user"]."'";
       
    $result mssql_query($sql$conex);  
       
    $filas mssql_num_rows($result);
       if (
    $filas <= 0)
          { 
    error(13$_POST["user"]); exit; }   
       
    $n1 mssql_result($result,01);  
       if (
    trim($n1) != trim($_POST["pwd"]))
          { 
    error (1"Usuario o Contraseņa"); exit; }         
       
    $permi mssql_result($result02);
       if (
    $permi == 0)
           { 
    error (14$_POST["user"]); exit; }    
       
    $user $_POST["user"];
       
    $_SESSION["valid"]= "YES"
       
    header ("Location: Main.php?userID=".trim($user));  
    ?>

    Any clues...Hope someone can help. I'm using IIS 5.0, PHP 5.0, MSSQL 2000. There's 0 possibility of changing IIS 5.0 cause there are other applications in other languages running OK there.

    Thank you.
    _____________

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, does your program ever comes to this line
    $user = $_POST["user"];
    $_SESSION["valid"]= "YES";
    and if yes (as you mentioned, everything goes fine), then what is the error you are getting, or what's happening.
    also debug this script, with error_reporting(E_ALL) at top of the script, in case, you have turned off the error reporting and it migh be supressing errors.
    ---------------------------
    Errors = Improved Programming.
    My Site

  3. #3
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You said you were having a strange problem, but you never really gave us much insight into what that problem was...

  4. #4
    SitePoint Member
    Join Date
    May 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The problem is...

    Well, it does acces the two lines mentioned by you, jaswinder. Adding the error reporting clausule didn't show anything strange.
    The problem I have is that eventhough a user enters a valid user and password he's redirected to Index.php, instead of Main.php.

    Why would these be?

  5. #5
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fernando2005
    Well, it does acces the two lines mentioned by you, jaswinder. Adding the error reporting clausule didn't show anything strange.
    The problem I have is that eventhough a user enters a valid user and password he's redirected to Index.php, instead of Main.php.

    Why would these be?
    Are you sure your script even gets executed (i.e. invalid form ACTION attribute)?

    Can you show us index.php?
    My name is Steve, and I'm a super-villian.

  6. #6
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    show us main.php
    ---------------------------
    Errors = Improved Programming.
    My Site

  7. #7
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaswinder_rana
    show us main.php
    I suppose, though it seems unlikely that he is inadvertently sending all requests back to index.php.
    My name is Steve, and I'm a super-villian.

  8. #8
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What i was thinking is, he is checking if the session is ok and user is registerd
    if not then he might be redirecting the user back to index.php

    he might be having probelms in there, like wrong variable name or not intilizing the session

    so, just better to take a look to be sure its not that
    ---------------------------
    Errors = Improved Programming.
    My Site

  9. #9
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    man this is weird, there's no mention of index.php in there. Look like a ghost in the machine problem

    Fernando, post code from all the files dude.

  10. #10
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason i mentioned main.php is the script is redirect to main.php (it can't go to index.php, no way) but it is redirected to index.php. so the something might(might not sure) be wrong in main.php which is redirecting the user
    ---------------------------
    Errors = Improved Programming.
    My Site

  11. #11
    SitePoint Member
    Join Date
    May 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Main.php

    Ok, guys. Still no clue here's my Main.php

    PHP Code:
    <? include ("seguridad.php");?> 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
    <html>
    <head>
    <title>Reporte de Ceros y Promedios</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <form action="atop.php" method="post" name="uno">
    <?
        $userID 
    $_GET["userID"];
        
    $permisos $_GET["permisos"];
    ?>
    <frameset rows="80,*" cols="*" frameborder="NO" border="0" framespacing="0">
      <frame src="Top.php?userID=<? echo $userID?>&permisos=<? echo $permisos?>" name="topFrame" scrolling="NO" noresize >
      <frameset cols="115,*" frameborder="NO" border="0" framespacing="0">
        <frame src="Menu.php?userID=<? echo $userID?>&permisos=<? echo $permisos?>" name="leftFrame" scrolling="NO" noresize>
        <frame src="CerosoProm.php?userID=<? echo $userID?>&permisos=<? echo $permisos?>"name="mainFrame">
      </frameset>
    </frameset>
    <noframes><body>
    </form>
    </body></noframes>
    </html>
    Seguridad.php
    It's just a small files that checks the session var valid.
    PHP Code:
    <? 
    session_start
    (); 
    if (
    $_SESSION["valid"] != "YES") { 
        
    header("Location: Index.php"); 
        exit(); 

    ?>
    Hope this helps. I don't think the problem is in Index.php, it's just a form with login and password fields. Thanks for your help.

  12. #12
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Taking a bit of a stab in the dark here, but you mentioned the problem only occurs essentially on the 'first' time the user accesses the script -- once they enter an invalid value, and then a correct value, they are let in.

    Sounds as though the header() isn't executing correctly, and I'm guessing that the first time Control.php is hit, session_start() sends a cookie to the client, preempting the data from header. (This doesn't make sense even to me, since the cookie *is* header data...)

    But you can try adding:

    PHP Code:
     ob_start(); 
    To the top of your control.php and seguridad.php scripts, just to see.
    My name is Steve, and I'm a super-villian.

  13. #13
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try changing your Seguridad.php to following and post the output

    PHP Code:
    <?
    session_start
    ();
    //Just to check what's in the session
    echo '<pre>';
    print_r($_SESSION);
    echo 
    '</pre>';
    exit;
    //UPto here
    if ($_SESSION["valid"] != "YES") {
        
    header("Location: Index.php");
        exit();
    }
    ?>
    ---------------------------
    Errors = Improved Programming.
    My Site


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •