header(location) causes [500] internal server error?
The script continues to execute after your header() call. You need put exit;
immediately after it. This shouldn't cause a 500 error, though.
Edit: Evidently this worked - meaning your problem is probably in some related code further down the page?
PHP header() causes internal server error
You are using this :
header('Location', 'index.html');
It is not the way header
must be used : the second parameter should be a boolean.
ANd the first one should be the header name + value.
So, in your case, something like this :
header('Location: index.html');
Only one parameter ; and name + ':' + value :-)
There is an example in the documentation :
The second special case is the
"Location:" header.
Not only does it
send this header back to the browser,
but it also returns a REDIRECT (302)
status code to the browser unless some
3xx status code has already been set.
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
As a sidenote, if I remember correctly, you should use a FULL absolute URL when using the Location
header ; I know using relative URL works in (almost ?) all browsers, but it is not valid, when reading the HTTP RFC, if I recall correctly.
As a second sidenote (yes, the answer has already been accepted, but maybe it'll be useful anyway, for next time :-) ) : that "INternal Server Error" might indicate your PHP script encountered some kind of error.
In that case, you should check the error_log
's file...
...Or activate error_reporting
and display_errors
to facilitate things -- at least on your development machine.
How to send 500 Internal Server Error error from a PHP script
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
Server error 500 for header location
Remove the single quotes around the querystring parameter values
header("location: ../../views/tileesDesign/viewAlbum.php?album=".$_GET['album']."&com_id=".$_GET['com_id']."&d_id=".$_GET['d_id']);
Or to make it even easier to read and debug
header("location: ../../views/tileesDesign/viewAlbum.php?album={$_GET['album']}&com_id={$_GET['com_id']}&d_id={$_GET['d_id']}");
And using this sample code from the command line and faking up a $_GET array containing all the required occurances :-
<?php
//header("location: ../../views/tileesDesign/viewAlbum.php?album=".$_GET['album']."&com_id=".$_GET['com_id']."&d_id=".$_GET['d_id']);
$_GET = array('album' => 'aaa', 'com_id'=> 'bbbb', 'd_id'=>'ccc');
echo "location: ../../views/tileesDesign/viewAlbum.php?album=".$_GET['album']."&com_id=".$_GET['com_id']."&d_id=".$_GET['d_id'];
echo PHP_EOL;
echo "location: ../../views/tileesDesign/viewAlbum.php?album={$_GET['album']}&com_id={$_GET['com_id']}&d_id={$_GET['d_id']}";
Generates this putput from either of the above options:-
location: ../../views/tileesDesign/viewAlbum.php?album=aaa&com_id=bbbb&d_id=ccc
location: ../../views/tileesDesign/viewAlbum.php?album=aaa&com_id=bbbb&d_id=ccc
internal server error while navigating php pages
You have an error in your header()
function, you are using:
header("location : admin.php");
This will throw the error you're getting because of the extra space between location
and the colon. Change it to this (notice the space):
header("Location: admin.php");
.htaccess/.htpasswd 500 Internal Server Error
Most likely problem is this line:
AuthUserFile /.htpasswd
This line should provide full filesystem path to the password file e.g.
AuthUserFile /var/www/.htpasswd
To discover your filesystem path, you can create a PHP document containing
echo $_SERVER['DOCUMENT_ROOT'];
Related Topics
Multiple Auto Increment in MySQL
PHP String in Array Only Returns First Character
PHP Loop: Add a Div Around Every Three Items Syntax
Array Merge on Multidimensional Array
How to Install All Required PHP Extensions for Laravel
How to Install Laravel Without Using Composer
Jetbrains Webide: PHP Variable Type Hinting
How to Implement MVC from Scratch in PHP
How to Log into Joomla Through an External Script
Fatal Error: Call to Undefined Function Mcrypt_Encrypt()
How to Insert Multiple Rows Using Prepared Statements
Cosine Similarity VS Hamming Distance
In Laravel How to Add Values to a Request Array
Stemming Algorithm That Produces Real Words
How to Post Multiple <Input Type="Checkbox" /> as Array in PHP
How to Block Uploads of Nude Images
Minifying Final HTML Output Using Regular Expressions with Codeigniter