www.webdeveloper.com
Results 1 to 8 of 8

Thread: header("location: member_profile.php?id=$id"); not working

  1. #1
    Join Date
    Mar 2014
    Posts
    5

    header("location: member_profile.php?id=$id"); not working

    <?php
    if ($_POST['email']) {
    //Connect to the database through our include
    include_once "connect_to_mysql.php";
    $email = stripslashes($_POST['email']);
    $email = strip_tags($email);
    $email = mysql_real_escape_string($email);
    $password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
    $password = md5($password);
    // Make query and then register all database data that -
    // cannot be changed by member into SESSION variables.
    // Data that you want member to be able to change -
    // should never be set into a SESSION variable.
    $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$password' AND emailactivated='1'");
    $login_check = mysql_num_rows($sql);
    if($login_check > 0){
    while($row = mysql_fetch_array($sql)){
    // Get member ID into a session variable
    $id = $row["id"];
    session_register('id');
    $_SESSION['id'] = $id;
    // Get member username into a session variable
    $username = $row["username"];
    session_register('username');
    $_SESSION['username'] = $username;
    // Update last_log_date field for this member now
    mysql_query("UPDATE members SET lastlogin=now() WHERE id='$id'");
    // Print success message here if all went well then exit the script
    header("location: member_profile.php?id=$id");
    exit();
    } // close while
    } else {
    // Print login failure message to the user and link them back to your login page
    print '<br /><br /><font color="#FF0000">No match in our records, try again </font><br />
    <br /><a href="login.php">Click here</a> to go back to the login page.';
    exit();
    }
    }// close if post
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Login to your profile</title>
    <script type="text/javascript">
    <!-- Form Validation -->
    function validate_form ( ) {
    valid = true;
    if ( document.logform.email.value == "" ) {
    alert ( "Please enter your User Name" );
    valid = false;
    }
    if ( document.logform.pass.value == "" ) {
    alert ( "Please enter your password" );
    valid = false;
    }
    return valid;
    }
    <!-- Form Validation -->
    </script>
    </head>
    <body>
    <div align="center">
    <h3><br />
    <br />
    Log in to your account here<br />
    <br />
    </h3>
    </div>
    <table align="center" cellpadding="5">
    <form action="login.php" method="post" enctype="multipart/form-data" name="logform" id="logform" onsubmit="return validate_form ( );">
    <tr>
    <td class="style7"><div align="right">Email Address:</div></td>
    <td><input name="email" type="text" id="email" size="30" maxlength="64" /></td>
    </tr>
    <tr>
    <td class="style7"><div align="right">Password:</div></td>
    <td><input name="password" type="password" id="password" size="30" maxlength="24" /></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input name="Submit" type="submit" value="Login" /></td>
    </tr>
    </form>
    </table>
    </body>
    </html>

  2. #2
    Join Date
    Mar 2014
    Posts
    5
    after i submit the login page i get a blank page, kindly help me out?

  3. #3
    Join Date
    Feb 2014
    Location
    Canada
    Posts
    155
    Try checking the error logs or running these 2 lines at the top of the page:

    PHP Code:
        error_reporting(E_ALL E_NOTICE);
        
    ini_set('display_errors'1); 
    Generally, I use JavaScript as an alternative to PHP's header when trying to re-direct users to a different page. It doesn't look as pretty but works. Chances are, the error you'll see will say something along the lines of trying to send header after already sent.

  4. #4
    Join Date
    Mar 2014
    Posts
    5
    after following your instructions i get the below errors,

    Deprecated: Function ereg_replace() is deprecated in /home/vol10_8/myfreepage.tk/mfpt_14268580/htdocs/login.php on line 14

    Fatal error: Call to undefined function session_register() in /home/vol10_8/myfreepage.tk/mfpt_14268580/htdocs/login.php on line 26

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Well, fatal errors are ... fatal, so it's time to join the PHP 5 world and stop using session_register().

    Your scripts should just be using session_start() on each page that needs read and/or write access to the session data, and access all such data via the $_SESSION super-global array.

    Also, while it's currently not a fatal error, it would be a good idea to migrate all use of ereg_*() functions to their corresponding preg_*() functions.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Mar 2014
    Posts
    5
    o.k thankyou, i look forward to join php 5.

  7. #7
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    547
    The blank page is probably because you have errors but you don't have error checking turned on in order to see them. Also as nogdog says, don't use session_register. I suggest you do some reading in the manual. Here's an example of some knowledge there:

    // Use of session_register() is deprecated
    $barney = "A big purple dinosaur.";
    session_register("barney");

    // Use of $_SESSION is preferred, as of PHP 4.1.0
    $_SESSION["zim"] = "An invader from another planet.";

    Other suggestions:
    Use the code tags for this forum to post your code in.

    Write neater looking code - try indenting some lines like:
    PHP Code:
    if (condition
    {
           
    statement1;
           
    statement2;
           
    statement3;

    Don't you agree that this is much more readable?

    Another thing: Why are you using stripslashes on an input field? Who put the slashes there?

  8. #8
    Join Date
    Feb 2014
    Location
    Canada
    Posts
    155
    The error output is telling you exactly what the problems are. First, ereg_replace() is depreciated, so you shouldn't be using it to start with. Second, you don't need session_register(), it's outdated, just use $_SESSION['something'] and have session_start() at each page (if you have php files included in other php files that start a session, there will be a notice saying it's been started but is being ignored). Take a look at the php.net manual and it's very handy to have open in another window as you're coding.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles