rbatista 1 Posted July 3, 2013 Report Share Posted July 3, 2013 Hi, I'm new programming with PHP and I am having this problem : Here are the codes : <?php if (isset($_GET['success']) && empty($_GET['success'])) { echo "<br>"; echo "<h4>You have been registered successfully.</h4>"; } else { if (empty($_POST) === false && empty($errors) === true) { // $register_data = array ( 'username' => $_POST['username'], 'password' => $_POST['password'], 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'email' => $_POST['email'] ); register_user($register_data); header("Location: admissions.php?success"); exit(); } else if (empty($errors) === false) { // Print error echo output_errors($errors); } ?> // End of the codes... Everything is working fine at my PC as localhost, but I put it's not working fine with my hosting. I mean, the header("Location: admissions.php?success"); works fine at my localhost, like reloading the page with SUCCESS, but with the hosting, then the admissions.php?success is not executed, is showing me a blank page. If I type the admissions.php?success at the browser, then it shows me the page... How can I fix that problem ? Thanks 1 Quote Link to post Share on other sites
divinedesigns1 91 Posted July 3, 2013 Report Share Posted July 3, 2013 (edited) normally "Location: admissions.php?success" would have something like "location:admissions.php?success=blah" Edited July 3, 2013 by DDs1 Quote Link to post Share on other sites
divinedesigns1 91 Posted July 3, 2013 Report Share Posted July 3, 2013 this should be in the php section btw Quote Link to post Share on other sites
justsomeguy 1,135 Posted July 3, 2013 Report Share Posted July 3, 2013 You're saying that it works if you type in the URL manually, but not if you send a location header? What is the code on the page you're redirecting to? I would look at that page for the problem, add some debugging code to it to see what's going on. Make sure you're showing all errors while you're debugging it, add this to the top of the page: ini_set('display_errors', 1); error_reporting(E_ALL); Quote Link to post Share on other sites
rbatista 1 Posted July 5, 2013 Author Report Share Posted July 5, 2013 Thanks all for your comments... What I mean is, that with that codes everything is working fine on the same script..... that script is name : admissions.php and if everything works fine then it calls itself. That's working perfect, but in my side.... I mean, working fine using my PC, but when I uploaded to my hosting, then the only thing that fails is that part : header("Location: admissions.php?success"); that part is not reloading the page again, or in other words, no calling again the script admissions.php with ?success . Quote Link to post Share on other sites
divinedesigns1 91 Posted July 5, 2013 Report Share Posted July 5, 2013 Thanks all for your comments... What I mean is, that with that codes everything is working fine on the same script..... that script is name : admissions.php and if everything works fine then it calls itself. That's working perfect, but in my side.... I mean, working fine using my PC, but when I uploaded to my hosting, then the only thing that fails is that part : header("Location: admissions.php?success"); that part is not reloading the page again, or in other words, no calling again the script admissions.php with ?success . do what justsomeguy said, localhost and your domain host process stuff differently at times so making your error display is best to fix it on ur domain host Quote Link to post Share on other sites
rbatista 1 Posted July 5, 2013 Author Report Share Posted July 5, 2013 ok... I will, thanks, I will let you know... Quote Link to post Share on other sites
rbatista 1 Posted July 7, 2013 Author Report Share Posted July 7, 2013 This is the error showing : Warning: Cannot modify header information - headers already sent by (output started at /home/aprendaa/public_html/includes/head.php:30) in /home/aprendaa/public_html/login.php on line48 THIS IS HEAD.PHP <!DOCTYPE html> <html lang="en"> <head> <title>Aprenda Ahora</title> <meta charset="utf-8"> <link rel="stylesheet" href="css/reset.css" type="text/css" media="all"> <link rel="stylesheet" href="css/layout.css" type="text/css" media="all"> <link rel="stylesheet" href="css/style.css" type="text/css" media="all"> <link rel="StyleSheet" href="css/burgundy.css" type="text/css"> <script type="text/javascript" src="js/jquery-1.5.2.js" ></script> <script type="text/javascript" src="js/cufon-yui.js"></script> <script type="text/javascript" src="js/cufon-replace.js"></script> <script type="text/javascript" src="js/Molengo_400.font.js"></script> <script type="text/javascript" src="js/Expletus_Sans_400.font.js"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script> <!--[if lt IE 9]> <script type="text/javascript" src="js/html5.js"></script> <style type="text/css"> .bg, .box2 {behavior:url(js/PIE.htc)} </style> <![endif]--> <!--[if lt IE 7]> <div style=' clear: both; text-align:center; position: relative;'> <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx?ocid=ie6_countdown_bannercode"> <img src="http://www.theie6countdown.com/images/upgrade.jpg" border="0" alt="" /></a> </div> <![endif]--> </head> <== THIS IS LINE 30 ON HEAD.PHP ======================================================================================================== THIS IS LOGIN.PHP <?php include 'desplegaerror.php'; // Luego Quitar include 'core/init.php'; logged_in_redirect(); include 'includes/head.php'; ?> <body id="page2"> <?php include ("bodyy1.htm") ?> <div class="body2"> <div class="main"> <!-- content --> <section id="content"> <div class="box1"> <div class="wrapper"> <article class="col1"> <div class="pad_left1"> <?php if (empty($_POST) === false) { $username = $_POST['username']; $password = $_POST['password']; if (empty($username) === true || empty($password) == true) { $errors[] = "Usted necesita entrar un Username y un Password"; } else if (user_exists($username) === false) { $errors[] = "No podemos encontrar su Username. Estás registrado ?"; } else if (user_active($username) === false) { $errors[] = "Usted no ha activado su cuenta !"; } else { if (strlen($password) > 32) { $errors[] = "Password muy largo !!!"; } $login = login($username, $password); if ($login === false) { $errors[] = 'Esa combinación de Username/Password es Incorrecta'; } else { // set the user session // redirect user to home $_SESSION['user_id'] = $login; header('Location: index.php'); <== THIS IS LINE 48 ON LOGING.PHP exit(); } } } else { $errors[] = 'No se recibió ningun dato'; } Quote Link to post Share on other sites
Ingolme 1,027 Posted July 7, 2013 Report Share Posted July 7, 2013 You cannot call the header() function after any HTML has been printed. This part of the code should be at the very beginning of the page: $login = login($username, $password);if ($login === false) {$errors[] = 'Esa combinación de Username/Password es Incorrecta';} else { // set the user session// redirect user to home$_SESSION['user_id'] = $login;header('Location: index.php');exit();} Quote Link to post Share on other sites
rbatista 1 Posted July 7, 2013 Author Report Share Posted July 7, 2013 Hey !!! I fixed everything adding this at the begining of the script ob_start(); Thanks everyone for your support... Quote Link to post Share on other sites
birbal 168 Posted July 8, 2013 Report Share Posted July 8, 2013 You may like to read this http://w3schools.invisionzone.com/index.php?showtopic=44106&p=245750 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.