Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

i have some code that works totally fine at my localhost server but as soon as i upload it to the web it doesn't work..

Hi! I'm making a website in php and i'm doing a php recover password function. I first made it in my local editor and when i had a good app i then uploaded it to my website. And guess what? It doesn't work online, it just doesn't show anything at all. Doesn't send a email and it doesn't show a message that it sent a email either. The weird thing you need to notice here is that i have a lot of functions on the website like registration, that sends an email when you type in your information and it works! Well this one just doesn't and i really don't know why.

Functions.php code // I'm only showing the code i'm having problems with.

<?php

function recover_password() {

if ($_SERVER['REQUEST_METHOD'] == "POST" ) {

    // $errors = [];

    if ( isset($_SESSION['token']) && $_POST['token'] == $_SESSION['token'] ) {

        $email  = clean($_POST['user_email']);
        $email  = escape($email);

        $token  = clean($_SESSION['token']);
        $token  = escape($token);

        if (!email_exists($email) ) {

            $errors[] = "Sorry, email you provided is not registered in our system.";

        } else if ( email_exists($email) ) {

            //-- Check if account is active or not -- //

            $_sql    = "SELECT user_id, active FROM users WHERE user_email='$email'";
            $_result = query($_sql);

            confirm($_result);
            row_count($_result);

            $_row    = fetch_array($_result);
            $active  = $_row['active'];


            if( $active == 0 ) {

                $message = info_message("Account status inactive, Please activate your account first.");
                set_message($message);                  
                redirect('index.php');

            } else if( $active == 1 ) {             

                // -- security code -- //

                $validation_code = md5($email + microtime()); 

                // -- setting a time limited cookie( 3 minutes) -- //

                setcookie('temp_access_code', $validation_code, time());

                $validation_code = md5($email, microtime());

                setcookie('temp_access_code', $validation_code, time()+60);

                $sql     = "UPDATE users SET validation_code='$validation_code' WHERE user_email ='$email'";
                $result  =  query($sql);                    
                confirm($result);

                $mail = new PHPMailer();
                $mail->IsSMTP();
                $mail->Mailer = "smtp.gmail.com";
                $mail->Host = "ssl://smtp.gmail.com"; 
                $mail->Port = "465";
                $mail->SMTPAuth = true;
                $mail->SMTPSecure = 'ssl';
                $mail->Username = "mikster340";
                $mail->Password = "Ifsomeofyounoticedihadmyrealpasswordinthereitschangednow123";

                $mail->From     = "noreply@zestymemes.com";
                $mail->FromName = "admin@zestymemes.com";
                $mail->AddAddress("mikster3420@gmail.com");
                $mail->AddReplyTo($email);

                $mail->Subject  = "Hi! Reset your password at zestymemes.com";
                $mail->Body     = "You requested a password reset from your email {$email}, press on the link below to reset your password and insert this validation code {$validation_code}!
                http://www.dellongcompany.com/login/code.php?email=$email&code=$validation_code";
                $mail->WordWrap = 50;  

                if(!$mail->Send()) {
                    echo 'Message was not sent.';
                    echo 'Mailer error: ' . $mail->ErrorInfo;
                    exit;
            } else {
                    echo 'Message has been sent.';
            }   

            if (!empty($errors) ) {

                    foreach ( $errors as $error ) {

                        echo validation_error_message($error);
                    }
                }

            } else { 
                validation_error_message("Sorry, your session expired");
                redirect('index.php'); 
            }   // -- if the token is not the same  redirect the user  to home page --// 
                    // End Token checks
    }

    }
 }

}

?>

No i'm on a MacBook :)

I'm using Xampp

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Huh weird. I'll leave this to the pros then. But generally speaking, when something works locally but not up on the server it's because we've misnamed a file or directory and it's not really pointing anywhere. This is especially true for Windows users whose files aren't case sensitive. That's why I asked :smiley:

Something even more weird is that i implemented them via FileZilla so i know 100% that it's correct

2 Answers

If you want too see the thing in action you can go to my website www.dellongcompany.com/login/login.php remember that you need to insert a valid email if you want to register because you will eventually have to press on a activation link in a email you're getting.

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

What comes to mind is when you upload the code are you loading all the files & are you loading all the folders in the exact same locations? Does the server support css? Some web hosts only include html for their basic price.

Well yeah as i said i uploaded every single file and all the files etc. is the same, and i have never heard of web hosts only include HTML as css is pre installed on all computers i've seen just as HTML. And this is php i'm talking about not the design :) Even in inspect page it doesn't show anything

and i do know for sure that php is working as i'm already using it