Jump to content
rbatista

Header("Location: ") Problem

Recommended Posts

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
  • Like 1

Share this post


Link to post
Share on other sites

normally "Location: admissions.php?success" would have something like "location:admissions.php?success=blah"

Edited by DDs1

Share this post


Link to post
Share on other sites

this should be in the php section btw

Share this post


Link to post
Share on other sites

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);

Share this post


Link to post
Share on other sites

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

.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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;'>
<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';
}

Share this post


Link to post
Share on other sites

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();}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...