Jump to content

Recommended Posts

I am so very frustrated with this issue that I'm so ready to tear my hair out.  :facewall: Or do as this little guy is. So here's my issue.

 

I'm using header location to redirect users from a submitted form to a page that will show them the groups they belong to. When you submit the form, the browser goes to show 'Webpage not found' and in the address bar, the URL looks like this:

 

http://www.site.com/sandbox/%3C?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//D

 

And it continues on the full character length of the address bar. I've been searching Google and Bing to no avail. Anyone have any suggestions on what to look for in this situation? I've never run into an issue like this in my seven or so years of coding. Thanks to anyone who tries!!

Link to comment
https://forums.phpfreaks.com/topic/169732-php-headers-issue-please-help/
Share on other sites

<?
if(!defined('INTERNAL_PAGE')) { define('INTERNAL_PAGE', TRUE); }

include 'includes/function.php';

if ($_SESSION['auth'] != 1) {
        $_SESSION['auth'] = NULL;
        $_SESSION['name'] = NULL;
        $_SESSION['userid'] = NULL;

        header ('Location: http://www.site.com/');
    }

    $thisTribeId = 0;
    $nowAMember = 0;
    

    if (sizeof($_POST) > 0) {
        //check to see if the name and password are valid.
        if ($_POST['password'] == '' || $_POST['groupname'] == '') {
            echo 'Group Name and Password fields cant be blank';
		exit;
        } else {
            //check to see if this user is already a member of this group
            //get group id
            if ($Group->getGroupByName($_POST['groupname']) == 'yes') {
                //this is a valid group
                //get group id
                $thisGroupId = $Group->paramId('get', '');

                if ($MyGroups->AlreadyAMember($thisGroupId, $_POST['groupname']) == 'yes') {
                    echo 'You are already a member of this group'; exit;
                } else {
                    //add userid to the mygroups table
                    $MyGroups->joinGroup($thisGroupId);
                    $nowAMember = 1;
                    
                    $to  = $login->getusersEmail($_SESSION['userid']);
				$subject = 'You joined a Group';
				$message = 'You joined the '.$_POST['groupname'].' group.';
				// To send HTML mail, the Content-type header must be set
				$headers  = 'MIME-Version: 1.0' . "\r\n";
				$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

				// Additional headers
				$headers .= "To: ".$_POST['email']."\r\n";
				$headers .= "From: Site.com <[email protected]>\r\n";

				mail($to, $subject, $message, $headers);
	            
				header ('Location: http://www.site.com/sandbox/ListGroups.php');
				exit();
                }
                
            } else {
                echo 'Wrong tribe credentials or the group don\'t exist.'; exit;
            }
        }
        exit;
    }

if ($nowAMember == 1) {
        echo 'You are now a member of the '.$_POST['groupname'].' tribe.';
    }
    
    // Start Page

if(isset($_GET['form']) && $_GET['form'] == 1) {
	include 'templates/header-popup.html';
	include 'templates/join-group.html';
	include 'templates/footer-popup.html';
} else {
	include 'templates/header.html';
	include 'templates/my-groups.html';		
	include 'templates/footer.html';
}
    
?>

 

Everything works but the header following submission of the form. Thanks!

What happens if you define the url then call that in the header redirect, i.e

 

// Start defining the URL.

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

// Check for a trailing slash.

if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {

$url = substr ($url, 0, -1); // Chop off the slash.

}

// Add the page.

$url .= '/index.php';

 

ob_end_clean(); // Delete the buffer.

header("Location: $url");

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.