#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189

    Correct page after header("Location: xxx") but url didn't change)


    Unexpected results...

    abc.php: (shortened for brevity)

    PHP Code:
    $thank_you='index.html';
    header("Location: $thank_you");
    exit; 

    index.html:
    Code:
    Hello World

    After running it displays "Hello World" (lol) but the address in the url bar is still abc.php

    This is happening on multiple browsers.
    Thomas Tremain
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Please post actual code, obviously this example works, it's the standard manual example.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    PHP Code:
    $start_page='index.html';

    $from_address="coupon@xxxxxxx.com";
    $from_name="Coupon";      //  Used for auto response only.

    $to_template='template.html';
    $to_email='xxxxxxx@xxxxxxx.com';
    $to_subject="Feedback from XXXXXXXXXXXXXX";

    $ar_template='ar.txt';
    $ar_attachment='coupon.pdf';
    $ar_subject='Your Coupon';

    $thank_you='thankyou.html';

    /////////////////  You should not need to edit below this line /////////////////////



    $ar_to=filter_var($_POST['email'],FILTER_VALIDATE_EMAIL);

    if (!
    $ar_to) {
        
    header("Location: $start_page");
        exit;
    }

    //Okay, so first, let's send our data to the customer

    $post=clean_user($_POST,'HTMLIZE');        //sanitize input
    $body=file_get_contents($to_template);        //Load template
    $post['IP']=get_ip();                //Set current IP as a template option
    $post['datetime']=date('Y/m/d H:i:s',time());    //Set current timestamp as a template option


    // Let's mix in our form variables
    foreach ($post as $key=>$value) {
        
    $body=str_ireplace('[['.$key.']]',$value,$body);
    }

    mail_to($to_email,$to_subject,$body,$from_address,$ar_to);

    // Now an autoresponse to the user

    mail_attachment(
            
    $ar_attachment,
            
    $ar_to,
            
    $from_address,
            
    $from_name,
            
    $ar_subject,
            
    file_get_contents($ar_template)
        );

    // All done, let's show the thank you page now
    header("Location: $thank_you");
    exit;


    function 
    mail_to($to,$sub,$body,$from=NULL,$replyTo=NULL) {
        
    $from= (isset($from)) ? $from 'noreply@'.preg_replace("/^(.*?)\.(.*)$/","$2",$_SERVER['SERVER_NAME']);
        
    $replyTo = (isset($replyTo)) ? $replyTo $from;
        
    $headers "From: $from\r\n" .
                
    "Reply-To: $replyTo\r\n" .
                
    "Content-Type: text/html\r\n";
        
    mail($to,$sub,$body,$headers);
    }

    function 
    mail_attachment($file$mailto$from_mail$from_name$subject$message) {
        
    $file_size filesize($file);
        
    $handle fopen($file"r");
        
    $content fread($handle$file_size);
        
    fclose($handle);
        
    $content chunk_split(base64_encode($content));
        
    $uid md5(uniqid(time()));
        
    $name basename($file);
        
    $header "From: ".$from_name." <".$from_mail.">\r\n";
        
    $header .= "Reply-To: $from_mail\r\n";
        
    $header .= "MIME-Version: 1.0\r\n";
        
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
        
    $header .= "This is a multi-part message in MIME format.\r\n";
        
    $header .= "--".$uid."\r\n";
        
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
        
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
        
    $header .= $message."\r\n\r\n";
        
    $header .= "--".$uid."\r\n";
        
    $header .= "Content-Type: application/octet-stream; name=\"".$file."\"\r\n"// use different content types here
        
    $header .= "Content-Transfer-Encoding: base64\r\n";
        
    $header .= "Content-Disposition: attachment; filename=\"".$file."\"\r\n\r\n";
        
    $header .= $content."\r\n\r\n";
        
    $header .= "--".$uid."--";
        
    mail($mailto$subject""$header);
    }


    function 
    clean_user($mixed,$htmlentities=NULL) {
        if (
    is_array($mixed)) {
            foreach (
    $mixed as $key=>$value){
                
    $mixed[$key]=clean_user($value);
            }
            return 
    $mixed;
        }
        if (
    is_string($mixed) ) {
            if (
    get_magic_quotes_gpc()) {
                
    $mixed=stripslashes($mixed);
            }
            if (isset(
    $htmlentities)) {
                
    $mixed=htmlentities($mixed,ENT_QUOTES,'ISO-8859-1',0);
            }
        }

        return 
    $mixed;
    }


    function 
    get_ip(){
       if (isset(
    $_SERVER['HTTP_CLIENT_IP'])){
          return 
    IP_type($_SERVER['HTTP_CLIENT_IP']);
        }
       foreach (
    explode(",", isset($_SERVER['HTTP_X_FORWARDED_FOR'])) as $IP){
          if (
    filter_var(trim($IP),FILTER_VALIDATE_IP)) {
                return 
    IP_type(trim($IP));
            }
        }
       if (isset(
    $_SERVER['HTTP_X_FORWARDED'])) {
          return 
    IP_type($_SERVER['HTTP_X_FORWARDED']);
        }else if (isset(
    $_SERVER['HTTP_FORWARDED_FOR'])) {
          return 
    IP_type($_SERVER['HTTP_FORWARDED_FOR']);
        }else if (isset(
    $_SERVER['HTTP_FORWARDED'])){
          return 
    IP_type($_SERVER['HTTP_FORWARDED']);
        }else if (isset(
    $_SERVER['HTTP_X_FORWARDED'])){
          return 
    IP_type($_SERVER['HTTP_X_FORWARDED']);
        }else{
          return 
    IP_type($_SERVER['REMOTE_ADDR']);
       }
    }

    function 
    IP_type($IP) {
        return 
    long2ip(ip2long($IP));

    Thomas Tremain
  8. #5
  9. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    Then I'm going to have to disagree with you about not being redirected. I can't speak to why the address bar isn't getting updated but you are certainly being sent to the thank you page.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    I don't believe I ever said the page wasn't getting redirected...




    Okay, I have narrowed it down to some jQuery on the calling form.

    If I remove
    Code:
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
    from the form page the problem goes away...

    At least the PHP portion IS working.
    Thomas Tremain
  12. #7
  13. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    Originally Posted by ttremain
    I don't believe I ever said the page wasn't getting redirected...
    You said you were still on the abc.php page.

    jQuery? Calling form? Is there something important you haven't mentioned?
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    Originally Posted by requinix
    You said you were still on the abc.php page.

    jQuery? Calling form? Is there something important you haven't mentioned?
    The jquery is on the page with the <form> that POSTs to abc.php. Originally I didn't think it was important. I'm still not sure how it could affect things two pages later, but it must somehow. (by two pages later I mean after loading abc.php, then thankyou.html )
    Thomas Tremain
  16. #9
  17. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    You are almost certainly submitting the form using AJAX.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    We are now off topic for PHP, so I was not going to pursue the question here, but here is the customer's index.html.

    If you have no idea, I would not be offended if a moderator moved this thread to the javascript forum.

    Code:
    <!DOCTYPE html> 
    <html>
    <head>
    	<meta charset="utf-8">
    	<meta name="viewport" content="width=device-width, initial-scale=1">
        <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> 
    	<title>YYYYYYYYY  Feeback | Powered by XXXXXXXXXX</title> 
    	<link rel="stylesheet" href="css/style.css" />
    	<script type="text/javascript" src="js/jquery.js"></script>
    	<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
        <script type="text/javascript" src="js/jquery.validate.js"></script>
        <script>
    $(document).ready(function() {
       $("#cform").validate({
         submitHandler: function(form) {
          $('[type="submit"]').button('disable', true).attr("value",
    "Submitting...");
           form.submit();
        }
      })
    });
    	</script>
      
     
    </head>	
    <body> 
    <!-- Start of first page: #one -->
    <div id="dim"></div>
    <div data-role="page" id="one">
    
    	<div data-role="header" data-position="fixed">
    		<div class="header"><span>Restaurant XYZ</span></div>
      </div><!-- /header -->
    
    	<div data-role="content" class="pagecontent" >
    	  <p><br>
          <img src="images/logo@2x.png" width="296" height="79"><br>
          <br>
          </p>
    		
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dui dolor, auctor non feugiat ac, fringilla quis sem. Cras ultricies massa et elit tempor viverra. Vivamus mattis, velit sed blandit dapibus, velit quam posuere dolor, non accumsan elit diam non turpis. Aliquam rhoncus purus nec elit ullamcorper tincidunt.</p>
        <p><a href="#two" data-role="button" data-transition="fade">Share Your Thoughts!</a></p>	
    </div><!-- /content -->
    	
    <div data-role="footer" data-theme="d">
    		<div class="footer"><span><img src="images/poweredby.png" width="277" height="28"></span>
      </div></div><!-- /footer -->
    </div><!-- /page one -->
    
    <!-- Start of first page: #two -->
    <div data-role="page" id="two">
    
    	<div data-role="header" data-position="fixed">
    		<div class="header"><span>Feedback</span></div>
      </div><!-- /header -->
    
    	<div data-role="content" class="pagecontent" >
        <p>Please fill out the form below</p>
    	  <form method="POST" enctype="multipart/form-data" action="formprocess.php" id="cform" class="validate">
    
    		  <input type="radio" name="Rate_Our_Service" id="Poor" value="Poor Service"/>
         	<label for="Poor">Poor Service</label>
    
         	<input type="radio" name="Rate_Our_Service" id="Okay" value="Okay Service"/>
         	<label for="Okay">Okay Service</label>
            
            <input type="radio" name="Rate_Our_Service" id="Good" value="Good Service"/>
         	<label for="Good">Good Service</label>
            
            <input type="radio" name="Rate_Our_Service" id="Excellent" value="Excellent Service" checked="checked"/>
         	<label for="Excellent">Excellent Service</label>
            <br />
            <label for="Server">Your server's name (if you know it).</label>
            <input type="text" name="Server" id="Server">
            <br />
           <label for="Suggestions">Suggestions on how our business and service can be improved.</label>
           <textarea name="Suggestions" id="Suggestions" cols="45" rows="5"></textarea>
      <br />
    			<label for="email">Your email address (so we can send you your coupon)!</label>
    			<input type="email" name="email" id="email" required="required">
    		
    			<!--  <input class="required inpt" type="text" name="subject" value="" /> --><br />
    			<button type="submit" data-textonly="false" data-textvisible="true" data-msgtext="Sending..." data-transition="slide" name="submit" value="submit-value">Submit</button>
      </form>
    </div><!-- /content -->
    	
    	<div data-role="footer" data-theme="d">
    		<div class="footer"><span><img src="images/poweredby.png" width="277" height="28"></span></div>
      </div><!-- /footer -->
    </div><!-- /page one -->
    
    
    </body>
    </html>
    Thomas Tremain
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    Solution:

    Add
    data-ajax="false"

    to the HTML form element. Example:
    Code:
    <form method="POST" enctype="multipart/form-data" action="formprocess.php" id="cform" class="validate" data-ajax="false">
    Thomas Tremain

IMN logo majestic logo threadwatch logo seochat tools logo