Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reseting $_GET values

    Is there a way to reset the $_GET values so that when a user hits "refresh", or "back" in their browser the code is not executed again?

    Example:
    PHP Code:
    $oData = new objData();
    if(
    $_GET['dir']!=="") {
        
    $dir $_SESSION['dir']; //Get stored directory path
            
        
    if($_GET['dirAction'] == "add") {    //Add the directory to the current dir string
            
    $dir .= "/" $_GET['dir'];
                    
        } elseif (
    $_GET['dirAction'] == "delete") { //Delete the directory from the current dir string
            
    $arrDir explode("/",$_GET['dir']); 
            
    $arrPath array_slice($arrDir,0,count($arrDir)-1);
            if(
    count($arrPath)>0$dir implode('/'$arrPath);
        }
        
        
    $_SESSION['dir'] = $dir;
    }
    $oData->setDir($dir); 
    A typical url string would read:
    PHP Code:
    directory.php?dir=folderFoo&dirAction=add 
    The only problem is that when the user hits refresh the code above looks to set the directory as root/folderFoo/folderFoo (instead of just root/folderFoo) and produces an error because that folder does not exist.

    Thanks for any help!

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm. I think you eiher need to redirect (--> header('Locarion etc') ) but this has all sort of other issues like users jumping back etc. I find that the most secure way is to set a flag in a sessionvariable.
    Like
    PHP Code:
    session_start();   // at the top of your page
    if (isset($_SESSION['processed']) and ($_SESSION['processed']=='yes')){
       
    //print a message or redirect
    } else {
       ... 
    // other code and processing
       
    $_SESSION['processed']='yes';

    Before you proces your request, you then check the sessionvariable.
    On some strategical pages (homepag etc, you unset these sessionvariables)
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •