To say it simply, I am trying send a requested file to my user using a php request.
I did try to redirect my user directly to the file using
header("Location: http://myurl");
But, I am using Unity and apparently, this redirection doesn't act the same as if I go directly to the right url.
I get this error : necessary data rewind wasn't possible
Do you know another way I could send my files from the server to the client ? maybe with an "echo" ?
Thank you
header('Location: http://www.example.com/');
Or using javascript
<?php echo '<script>window.location="yoururl";</script>;' ?>
Finally, I did it with a simple
readfile("$ResourceId");
Thanks for your help, it makes me found it :)
Related
I have a php script that checks if the user typed the right password for the right username.
If its right I want to open another php page and pass some values with the get method. How do I do this? Im pretty new to php.
You can redirect to that page if this is your case:
if(condition){
header("Location: yourfile.php?parameter1=value1¶meter2=value2");
exit();
}
Note: header should be called before any output, its recommended to call it at top of the page before printing anything.
Or use cURL to send the GET request.
Don't use GET to send password!
Instead try to use cURL lib and send it via POST.
I had redirected my page like:
redirect(base_url().'user/login/?redirect=site/cart_steps/steps');
and it works fine in localhost and when i uploaded it to server it didnt redirect. I checked all the codes and above this all code executes. But when it comes to redirect the page doesnt redirects. I also tried
redirect(base_url().'user/login?redirect=site/cart_steps/steps');
redirect(base_url().'user/login');
header('Location:'.base_url().'user/login?redirect=site/cart_steps/steps');
header('Location:'.base_url().'user/login');
but the page didn't redirect? and also i checked out this The header function is not working on online server?
but it cant help me too.... can any one explain what is the problem here....
You can use the refresh method like this:
<?php
redirect($this->input->server('HTTP_REFERER'), 'refresh'); // refresh the page
?>
Another common mistake could be echoing out / printing something before the redirection.
I would check your CodeIgniter error logs to verify that particular file isn't throwing any error messages that could tell you what needs fixing.
If you haven't already, you'll probably also want to make sure that the URL helper is loaded.
ex:
$this->load->helper('url');
Another solution
<meta http-equiv="refresh" url=http://example.com/">
Try to use like this,
First define your base URL as :
$base_url = "Your base url";
then apply this $base_url variable to your redirect link.
Hope this will help.
I need to redirect visiters from:
/plug/survey/survey.php?22
to
/publications.php?1.articles.view.547
I have a limited understanding of .htaccess and php and wonder if anyone has any tips/ideas for me?
Any help would be very much appreciated!
Thank you
Add to the top of survey.php:
<?php
if ($_SERVER['QUERY_STRING'] == "22") {
header("Location: http://example.com/publications.php?1.articles.view.547");
exit;
}
You can write this code in htaccess file
RewriteEngine on
Redirect /plug/survey/survey.php?22 /publications.php?1.articles.view.547
Also read this
http://corz.org/serv/tricks/htaccess2.php
if it is just the one file, you can use header('Location: '.$url); at the top of the php - see http://php.net/manual/en/function.header.php
Your question really lacks vital information:
Where does that "1.articles" come from - is it a fixed string ?
where dies that "547" come from, I guess it is from a database lookup somehow ?
If so, there is no easy way to do that using plain rewrite rules.
Most likely the best solution is to write a small php script you redirect to. Inside that script you evaluate the request parameters (php variables $_SERVER and so on), make you database lookup and use the information gathered to send a redirect header to the browser (using phps 'header()' method).
I think your solution is
header("location:/publications.php?1.articles.view.547");
You can use .httaccess, but if you want the user should go on that page you cant use it because it will redirect you before reading any code on that page, but header() will first read the code and if any code is something not good then redirect like this,
if($varisgood){
// not redirect
}
else{
//redirect
}
Hey, does anyone know how i cant get a href link too run a PHP script? Like the href dosent change page just runs a PHP script above? Any pointers would be great :))
Use Ajax to make the request to the PHP page in the background.
If you link to a script which, after executing some code, tells the browser to redirect back to your main page, you will achieve that.
example:
<?php
//some code...
header("Location: $_SERVER['HTTP_REFERER']");
?>
It's one way to do it. It doesn't work on every server.
Alternatively, you can hardcode your url, like:
header("Location: path/to/the/page/you/want/to/go/back/to");
...
I am relatively new to PHP, so my apologies if the answer is trivial. Lol
I wrote a simple Contact Us email form (actually a WordPress page-template file). All the code is in one file.
After the user submits the form and the email is sent, the file generates a Thank You message.
If the user reloads the Thank You page, they are prompted to "Resend the Form Data," which is why I am asking this question.
My question: How do I avoid the prompt to resend the form data and still keep all of my code (including the Thank You data) in one file?
EDIT: I've seen folks use headers( Location: ), but I don't think that will work for if I want to keep all my code in one file.
You could redirect to a different query.
header("Location: ?page=thankyou");
Then, you don't even need to check if the POST data was sent. Just display the thank you page if page is equal to thank you.
This worked for me, it can be put anywhere in html file not just beginning like header() function:
<?php
if (!empty($_POST)){
?>
<script type="text/javascript">
window.location = window.location.href;
</script>
<?php } ?>
I placed it into prevent_resend.php and then included it after the postdata processing was done.
// ... save data from $_POST to DB
include('prevent_resend.php');
// ... do some other stuff
You can use javascript to post the form and show the thank you message. This way the browser never leaves the page.
Even with a header('Location: xxx'); you can still redirect it to the same page, and either set a url parameter or a session variable to distinguish what should be shown.
Although I question your requirement to have all the code in one file (why couldn't you separate it, and use require_once to include shared library code?), the header('Location:') technique is still completely valid. Simply do:
header('Location: http://www.example.com/path/to/my-one-file-of-code.php?thankyou=1');
Then, in your file, you can have:
if (isset($_GET['thankyou']) && $_GET['thankyou']) {
// Do whatever it is you do to thank the visitor.
}
This worked for me:
header("Location: #");