How do i set a redirect?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wizardry
    New Member
    • Jan 2009
    • 201

    How do i set a redirect?

    Hello -

    I need to set the path in php for where i want the page to be loaded after these commands are processed.


    I've tried redirect but it works only if its locally. maybe i'm doing it wrong.

    here my current redirect
    Code:
    header("Location: http://$server/$domain/$username/$username.php") ;
    thanks, in advance for your help!
    Last edited by Markus; Feb 9 '09, 10:49 PM. Reason: Fixed code tags: it's [code] not [php]
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    I think you should make a string with the information. Not 100% sure, because I have never tried it your way, but something like:
    Code:
    $location = "Location: http://" . $server . "/" . $domain . "/" . $username . "/" . $username . ".php";
    header($location);
    And this is being parsed before there has been any user output isn't it? PHP header() function only works if it is before any output. Just checking ;)

    Comment

    • wizardry
      New Member
      • Jan 2009
      • 201

      #3
      thanks that what i'm working on now.

      no i've been using ob_start
      code...........
      ob_flush

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        What do you mean it only works locally? Is that on a local server or the link is pointing local?

        The code you provided should work. Do a var_dump() to see what your variables hold.

        Comment

        • wizardry
          New Member
          • Jan 2009
          • 201

          #5
          That was on a local server.

          the server that i'm working on is remote, vm.

          Code:
          <?php 
          ob_start();
          $first =$_POST['first']; 
          $last = $_POST['last']; 
          $username = $_POST['userreg']; 
          $pass = $_POST['passreg']; 
          $email = $_POST['email']; 
          $t1 = "/opt/lampp/htdocs/domain/" ;
          
          //make directory for the user by his username 
          mkdir("$t1"$username, 0777); 
          echo " Created $username directory";
          
          $conn = mysql_connect("localhost","xxxx","xxxx"); 
          mysql_select_db("forum", $conn); 
          
          $sql = "insert into users ( `user_name`, `password`, `firstname`, `lastname`, `email` ) values ('$username','$pass','$first','$last','$email')"; 
          $result = mysql_query($sql, $conn) or die (mysql_error()); 
          echo "inserted into database users profile info";
          
          touch('$t1$username/$username.php'); 
          echo "create users web page";
          
          $fp = fopen('$t1$username/$username.php', 'w'); 
          $php = "<html><body> 
          welcome:$username <br /> 
          what a great photo 
          <img src='$file' width=200 height=200 /> 
           your page url is  'http://localhost/domain/$username/$username.php' </html></body>"  ; 
          fwrite($fp,$php); 
          echo "wrote to users page";
          
          //redirecting him to his new page : 
          $url = 'http://localhost/domain/$username/$username.php';
          echo"going to new page";
          header('Location: '.$url) ;
          
          var_dump();
          ob_flush();
          
          ?>
          Last edited by Markus; Feb 10 '09, 12:17 AM. Reason: Fixed [code] tags.

          Comment

          • wizardry
            New Member
            • Jan 2009
            • 201

            #6
            when i ran vardump it said their was an error on line 11 which is mkdir command

            Comment

            • wizardry
              New Member
              • Jan 2009
              • 201

              #7
              why is the mkdir not making the dir in the supplied path its making it in the dir where the script is ran from?

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Because you have a syntax error.

                Code:
                mkdir("$t1"$username, 0777);
                Should be

                Code:
                mkdir($t1 . $username, 0777);
                Also, type [code] not [php] for your code.

                Comment

                • wizardry
                  New Member
                  • Jan 2009
                  • 201

                  #9
                  ok

                  will try and post results

                  Comment

                  • wizardry
                    New Member
                    • Jan 2009
                    • 201

                    #10
                    its still creating in the dir where the script is

                    Comment

                    • wizardry
                      New Member
                      • Jan 2009
                      • 201

                      #11
                      ok i've got it to work, thanks for your help

                      Comment

                      • wizardry
                        New Member
                        • Jan 2009
                        • 201

                        #12
                        ok another question same topic!

                        q1. how to have the form on submit wait until this is being built then go to the page that was just made?

                        thanks for your help in advance

                        Comment

                        • TheServant
                          Recognized Expert Top Contributor
                          • Feb 2008
                          • 1168

                          #13
                          If it is in the same script then it should read from top to bottom and do that anyway? If the form submits to a php file and the file has no output to the browser prior to completion of the page, you can use header(location :new_file.php); Is that what you mean?

                          Comment

                          • wizardry
                            New Member
                            • Jan 2009
                            • 201

                            #14
                            i have that issue solved with the file parsing.

                            I would like to on submit of my php post_form to wait until that form is created and send a message or icon letting the user know its processing. and then once its completed its processing reload the redirect page into the current page. instead of opening a new window or tab.

                            Comment

                            • TheServant
                              Recognized Expert Top Contributor
                              • Feb 2008
                              • 1168

                              #15
                              How long is the page taking to make?

                              Comment

                              Working...