Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Location
    Cape Town
    Posts
    845
    Member #
    7422
    PHP Code:
    session_start();

    //variable that will make sure that the user does not send this page twice!
    if(isset($_SESSION['send'])){
        
    header('location:requestingmembership.php');        
    }else {
        
        
    $_SESSION['send'] = 1;

    This is the very first lines of code on my page. Th reason for it is so the user cannot refresh the page and resubmit the info. But it doesnt seem to be working as planned.

    It does kick you to "requestingmembership.php", but the rest of the page still loads. Instead of me receiving one email from the page, once you refresh the page, it kicks you to requestingmembership.php but it sends me an email aswell.

    Any suggestions?

  2.  

  3. #2
    Senior Member
    Join Date
    Aug 2003
    Posts
    444
    Member #
    2801
    Put an exit statement after the header call.
    eKstreme
    eKstreme.com - Free website tools!
    fontfox - free fonts Hand-picked quality fonts.

  4. #3
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    Header info is sent all at once, as soon as the first piece of content is delivered (hence why you get "HEADERS ALREADY SENT" error messages sometimes). So, if you have more code (like the email) it'll keep going until it hits some real HTML to output, at which time it'll send out location: headers that change where you're going eKstreme's solution will work though.
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site

  5. #4
    Senior Member
    Join Date
    Aug 2003
    Posts
    444
    Member #
    2801
    Just to elaborate, in a situation like this, you really need to send an email only if a condition is met. Therefore the code to send emails should fall into the else block of code.

    In essense, the page becomes a large if/else condition. The if statement does the forwarding, and the else does whatever needs to be done. There should be no code outside this decision structure.

    Adding an exit() statement works, but I don't like it on design principle reasons. I like clean code.

    But that's just me
    eKstreme
    eKstreme.com - Free website tools!
    fontfox - free fonts Hand-picked quality fonts.

  6. #5
    Senior Member jbagley's Avatar
    Join Date
    Sep 2004
    Location
    Cape Town
    Posts
    845
    Member #
    7422
    Hi guys, thanks for the help. I think the best solution to use is, encapsulate the entire code in an if/else block.

    As you guys say, the exit() command will work, but it isnt the best way of doing it.

    Thanks again!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:45 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com