www.webdeveloper.com
Results 1 to 4 of 4

Thread: Refreshing a page adding GET vars.

  1. #1
    Join Date
    Jul 2011
    Posts
    54

    Refreshing a page adding GET vars.

    So I am creating an application that requires 3 variables to be passed to some page.php.

    I need $_GET['x'], $_GET['y'], and $_GET['z'] to be passed to the page.

    I have an if statement that I have created now to catch if any of these 3 vars have not been passed, however I am wondering if it's possible to reload the current page in PHP, appending default values for these variables to the URL.

    PHP Code:
    if(!isset($_GET['x']) || !isset($_GET['y'] || !isset($_GET['z']))
    {
          
    //load currentURL + "?x=1&y=2&z=3";

    For example, if someone requests page.php it will automatically change it to page.php?x=1&y=2&z=3.

    Thanks in advance! .

  2. #2
    Join Date
    Aug 2006
    Posts
    1,943
    Do you really need to reload a page with a default query string? Why not:
    Code:
    if (!isset ($_GET['x'])) $_GET['x'] = '1';
    
    // ...move on knowing that $_GET['x'] has something useful in it.
    Dave

  3. #3
    Join Date
    Jul 2011
    Posts
    54
    The reason I was wanting to reload the page with default GET values set is because the page will have two different stylesheets / layouts being used depending on what stage of the application the user is in.

    In theory;

    If the user goes to the page for the first time, they will select a series of default settings, and then next time the application is run by that user, all of those settings will be remembered.

    However, just for default testing purposes now I dont want to have to go to through the lengthy process of creating a "profile" everytime I want to test the second section of the application.

    Rather then using PHP I have come up with a temporary solution to just use javascript like this: location.href = window.location + (all arguments here).

  4. #4
    Join Date
    Aug 2006
    Posts
    1,943
    Ah, got it. From PHP you could do:
    PHP Code:
    header ("http://www.mydomain.com/?x=1&y=2&z=3"); 
    Dave

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles