Help with php scripts running in MAMP

Discussion in 'Web Design and Development' started by loislane74, Sep 27, 2008.

  1. loislane74 macrumors newbie

    Joined:
    Sep 27, 2008
    #1
    i have php scripts which is running just fine in WAMP but my client is using MAMP when i tried executing its not redirecting to the correct page i cant really figure out what is the problem here is my sample code:

    PHP:
    include "connection_dbase_settings.php";
            
                    
    $user_name $_POST[user];
                    
    $pass_word $_POST[pass];
                                
                    
    $quer "Select * from tbl_users where username='$user_name' and password='$pass_word'";
                    
    $result1 mysql_query($quer);
                    
    $row mysql_fetch_array($result1);
                    
    $user_id $row[userid];
                    
    $level $row[user_level];
                    
    $user_area $row[area];
                    
    $user_fullname $row[name];
                    
    $center $row[center_name];
                    
                    
    $num mysql_num_rows($result1);
                    
                        if((
    $num != 0) && ($level == 'Coordinator'))
                        {
                            
    session_start();
                            
    $_SESSION['id']=$row[userid];
                            
    $_SESSION['ucentername']=$center;
                            
    $_SESSION['uarea']=$user_area;
                            
    $_SESSION['ufullname']=$user_fullname;
                            
    header("Location: http://localhost/Feeding/menu_guest.php");
                        }
                        
                        elseif((
    $num != 0) && ($level == 'Administrator'))
                        {
                            
    session_start();
                            
    $_SESSION['id']=$row[userid];
                            
    $_SESSION['ucentername']=$center;
                            
    $_SESSION['uarea']=$user_area;
                            
    $_SESSION['ufullname']=$user_fullname;
                            
    header("Location: http://localhost/Feeding/menu_admin.php");
                        }
                        else
                        {
                            
    header("Location: http://localhost/Feeding/error_login.php");
                        }
    im using this URL: http://localhost::8888/login.php
    whenever im running the page after loggin in the page is blank and all I can see is just the text LOG IN
     
  2. Thom_Edwards macrumors regular

    Joined:
    Apr 11, 2003
    #2
    You say you are using localhost::8888 at the end of your post. I'm sure you meant to put localhost:8888 (with only one colon), but in the code you are using localhost without port 8888 included. I would start by adding :8888 after localhost in the code and see what happens.


    And this has nothing to do with the problem you mentioned, but I thought I would throw this in here to help out a bit. You probably will want to do a little research on SQL Injection, prepared queries using PEAR, PDO or other options, and the php function available for MySQL mysql_real_escape_string. The fact that you don't sanitize your $POST values before concatenating them in with your SQL statement opens you up for attacks.
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    On the redirects (which are the lines that start with header("Location ...")) you don't include the port number. So the first one should be:

    PHP:
    header("Location: http://localhost:8888/Feeding/menu_guest.php");
    Also be sure both are using port 8888. I was thinking MAMP used 8080 by default, but in any case make sure they're using the same port number. You didn't supply the code being used to connect to MySQL. Make sure you're using the correct MySQL port as well (if using it), which is different than the Apache port of 8888 you're using. I think on default MAMP has it as 8889.

    I also completely agree with Thom_Edwards's second paragraph about sanitizing the submitted information. Be sure to check out the links he provided, it can turn into a very serious problem for you.
     
  4. loislane74 thread starter macrumors newbie

    Joined:
    Sep 27, 2008
    #4
    well on the script that i deployed on the MAMP which is on the client i already fixed that problem im actually using this line:
    PHP:
    header("location: http://localhost:8888/Fedding/menu_admin.php");
    but still its not working, its not loading the page as what i've stated on the above statement...
    with regards to SQL injection i would do certainly apply it once the website goes LIVE...
    any idea still what could be the problem :(
     
  5. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #5
    You mentioned all you see is the text "LOG IN." What page is that on? The error login page? Nothing in the PHP jumps out as being wrong, but there's a bit we can't see here. On the if statements when you compare against $level, it's compared against a capitalized word. Is it stored in the DB as capital? Just a thought.
     
  6. loislane74 thread starter macrumors newbie

    Joined:
    Sep 27, 2008
    #6
    The weird thing is that the Log-In text that we can see is not even on the page where it is redirected but on my page im displaying a Log In text which is displayed here is it:

    PHP:
    function display_form()
        {
            global $errors;
    ?>
            <br>
          <p class="style1">Log - In<br>      
                 
            <!-- add your content below -->
            <div align="center">        
            <br><table width="354" border="0" align="center">
              <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                <tr>
                  <td width="95">Username</td>
                  <td width="249" colspan="6"><input type="text" name="user" value="<?php echo $_POST[user]; ?>">
                      <?php echo $errors['user']; ?></td>
                </tr>
                <tr>
                  <td>Password</td>
                  <td colspan="6"><input type="password" name="pass" value="<?php echo $_POST[pass]; ?>">
                      <?php echo $errors['pass']; ?></td>
                </tr>
                <tr>
                  <td> </td>
                  <td colspan="2"> </td>
                </tr>
                <tr>
                  <td colspan="3"><div align="center">
                      <input type="submit" name="submit" value="SUBMIT">
                      <input name="reset" type="reset" value="CLEAR">
                  </div></td>
                  </tr>
                <tr>
                  <td height="59" colspan="2"><p align="left"> </p>                  </td>
                </tr>
              </form>
              <?php
         
    }
         
    ?>
              </table>
          </div></td>
      </tr>
    </table>
     

Share This Page