How to reload a page in PHP before exit function? [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I got some code like this and the header is not working
if ($variable > 0) {
header('Location: mypage.php');
exit;
}
And I need exit function, is this a bad idea?

If your code produces any output text before header directive then header directive will be ignored.
Even if header is located before any output (HTML or PHP), be sure not to have any characters nor spaces between beginning of PHP file and <?php tag.
However, there is a chance that header directive will be accepted even if there is output present before it, if written text is still in the PHP output buffer and nothing has yet been sent to web server. But, to be safe, make header the first thing before any text output.

Related

cannot print "hello world" on the browser using php language [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm wondering why I cannot display the simple "hello world" using php language.
This is how my code looks like:
<?
echo "Hello world";
?>
and this is how the output come out in the browser, nothing display:
You need to make sure following things for executing php file.
Php tag should be properly open and close <?php ... ?>
You xampp server is properly running.
You are accessing file by putting correct path.

File display using PHP and header() not working [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm trying to show any file in the browser using PHP and headers, but it isn't working with a PNG image, it shows a strange black square like this:
The Strange Blank Square
Here is my code:
<?php
header('Content-Type: ' . mime_content_type($filepath));
readfile($filepath);
die();
?>
I already checked the $filepath variable, its the full path (E:\wwwPublic\myapp\application\controllers\..\..\documents\34807\image.PNG) I don't know what is going wrong in that code.
Do you have any idea(s) ?
I solved it, I found that Code Igniter has default headers, I needed to add ob_clean() to remove all of them and add my own, Thank you for your help

PHP does not copy the file properly [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
im copying a file from another domain. It does not give me any errors but the files does not get recognized and its different size from the original file. Its the same extension i checked. so im kinda clueless.
if (!copy('http://maholi.com/image/data/Products/Linen - Juvenile and Infant/1440.jpg', $_SERVER['DOCUMENT_ROOT'].'/resources/categories/tttt6.jpg')) {
echo "failed";
}
any ideas?
This works fine for me:
if (!copy('http://maholi.com/image/data/Products/Linen%20-%20Juvenile%20and%20Infant/1440.jpg', $_SERVER['DOCUMENT_ROOT'].'/tttt6.jpg')) {
echo "failed";
}
Edit: URL's are not allowed to contain spaces. See "Is a URL allowed to contain a space?". Your web browser will automatically encode illegal characters, making you believe they are allowed.

Code for set the url as usernameq [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I use a code to set the URL as:
http://domainname.com/user
The problem is that I use some masks in my .htaccess, so what we see in the URL is not always the real path of the file.
What I need is to get the URL, what is written in the URL, nothing more and nothing less—the full URL.
I need to get how it appears in the Navigation Bar in the web browser, and not the real path of the file on the server.
You need to simple check in PHP what's the value of $_SERVER['REQUEST_URI']
or substr($_SERVER['REQUEST_URI'],1) if you want to remove leading slash

Error message in the header of my site - how to fix? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have an error message appearing in the header section of my site and don't know what's the reason for that. It seems like a bug but I don't know the reason and how to fix that!
It appears that your site is trying to set something on the header (perhaps a cookie) after the response was sent. We need to see the code responsible. Most likely you need to move some of your code around in your file (perhaps the thing on line 8 should be before the thing on line 1?)
The reason is present in the error message itself; headers cannot be set after output has been sent to the browser. When PHP first outputs any actual content to a browser, it has to send the HTTP headers first. After the headers has been sent, any new headers can't be added to the response, as the HTTP protocol now is in the actual body of the response. The error message shows you which line started the output (line 1), and which line tried to set the header (line 8).
To avoid the issue you can use ob_start and output buffering, although I'd strongly suggest separating displaying HTML from the code setting the headers, by either using a template language such as Smarty or twig, or a more extensive framework with a complete MVC model.

Categories