-1

SOLVED, I missed to add a folder path. Recently restructured my server and thereby caused a problem for me.

Having troubles with the header() in PHP, when im trying to redirect to HTML-page in parent directory. I have tried to find some answers in the forum but without success.

I have tried using both ../above.html and the full adress http://www.test.com/above.html without success. Also something to mention is that I send the redirrURL with a hidden input, but I have checked that I get the correct adress.

This is how my code looks right now, but I keep getting 404:

$redirrURL = $_POST['pageType'];
header( "Location: $redirrURL" );

this is where I call the PHP file that uses the header();

<form method="post" action="rateBarFunction.php">
            <td>
                <input type="hidden" name="pageType" value="<? echo $redirrURL ?>" />
                <select name="grade">
                    <option value="" style="display:none;"></option>
                    <option value="5">5</option>
                    <option value="4">4</option>
                    <option value="3">3</option>
                    <option value="2">2</option>
                    <option value="1">1</option>
                </select>
                <input type="submit" name="submit"/>
            </td>
        </form>
<?php 
    echo "</tr>";
}
echo "</table>";
?>

Is it not working because I echo HTML-code after I use header()?

Burro
  • 33
  • 8
  • Do you get a PHP error? What is the error then? – Jocelyn Apr 04 '13 at 17:02
  • Is the user directed to the correct URL? – PeeHaa Apr 04 '13 at 17:11
  • I don't get any PHP error, only thing I get is 404 - not found.. I use the same filename on my HTML-document as the one I am trying to redirect to. – Burro Apr 04 '13 at 17:12
  • When you get the 404, what is the address you get the 404 for? How does it differ from the Location: header address you have been given? Also instead of header() you can just output some HTML with the link for debugging purposes. That way you can check the output and then click the link and test if the link works. – hakre Apr 04 '13 at 17:23

2 Answers2

0
            <input type="hidden" name="pageType" value="<? echo $redirrURL ?>" />
                                 ^^^^^^^^^^^^^^^

So you need to use

$_POST['pageType'];
Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Sorry, must have written wrong. it is pageType on both places, so thats not it... – Burro Apr 04 '13 at 17:10
  • Then were does $redirrURL get set in the PHP code? Does the url actually show up in the html before you submit the form? – Marc B Apr 04 '13 at 17:11
  • It shows before I submit, and the URL matches the filename. The HTML-file is in the parent directory and I use ../fileToReach.html. I am so confused right now, the thing is that it worked before created a structure with folders on the server. Now it is structured as "Public folder" (root) --> Folder for PHP files, and the HTML-file i am trying to reach is in the "Public folder". – Burro Apr 04 '13 at 17:19
  • Thanks for the answer, my own restructuring with folders on the server caused the problem... Is there a way to remove this question? – Burro Apr 04 '13 at 17:35
  • you can delete it if you'd like – Marc B Apr 04 '13 at 17:37
0

No, you are not getting this error because of the header()/echoing. That should be fine.

But what is it that you want to do? In the form you have the action 'ratebarFunction.php'. That is the action that is going to be executed, unless you replace the action via JavaScript during the onSubmit - event. If you get a 404 on this form, then is there no valid URL 'ratebarFunction.php'.

You can test a 404 easily. Just go to the sourcecode of your page and open the URL in the field value by clicking on it. When it comes up, then will it work. If not, then is the syntax not proper. Easiest way to resolve is to create the correct URL in any browser and put that in the field value.

'../x.php' is a method for files. It works differently with URLs and in PHP can you resolve it much easier using $_SERVER['DOCUMENT_ROOT']. I would advise you to always use absolute URLs, because they don't fail when you decide to put your php-files in another directory. The superglobal $_SERVER etc. will help you out.

Loek Bergman
  • 2,192
  • 20
  • 18
  • Thanks for the answer, my own restructuring with folders on the server caused the problem... Is there a way to remove this question? – Burro Apr 04 '13 at 17:36
  • I think you (and I) need more reputation points to have the right to remove a question. Furthermore is this not an issue. We all make those kind of mistakes. In a lot of questions is the human error the cause. With this question and answer (if you accept it) can other people be helped. – Loek Bergman Apr 04 '13 at 17:40
  • 1
    Aah yes, the good old human factor. I guess this question can stay, as it might help someone.. – Burro Apr 04 '13 at 17:47