I've developed an application, using LAMP, and everything works fine, after migrating over to IIS, some pages don't work correctly.
I have a service_edit.php, which carries over URL parameters from the previous page, e.g.:
service_edit.php?id=5&serv=22
After updating the record, the following variable should redirect the browser to:
$updateGoTo = "freelancer_details.php?id=" . $row_rsFreeLancer['freeid'] . "";
But the browser produces a HTTP 500 error with service_edit.php?id=5&serv=22 in the address bar.
If I use:
$updateGoTo = "freelancer_list.php;
Everything works fine.
Does anyone know what I'm doing wrong, or if there is a setting in IIS to get this to work?
EDIT
OK, getting a bit closer to the problem now...
I've found that on my LAMP server, after the record has been updated, the page goes back to the freelancer_details.php page, with the correct details displayed, however, the parameters from the previous page are carried over too.
The URL, instead of displaying:
freelancer_details.php?id=5
displays:
freelancer_details.php?id=&id=5&serv=22
How do I remove the URL parameters from the previous page, so the URL displays correctly, and therefore work on the IIS server?
I can't say specifically what the problem is from what you have here (it's hard to understand what you're saying without seeing the rest of the script), but I can almost guarantee that IIS isn't the problem. Most likely there is some confusion with the page you are trying to forward to - either it's not there, or not being forwarded properly.
Try doing this:
$updateGoTo = "freelancer_details.php?id=" . $row_rsFreeLancer['freeid'] . "";
echo("<a href='".$updateGoTo."'>Click Me</a>");
and try clicking. That will tell you if there is truly a page at that URL, or if it's off.
Also, how are you forwarding to the next page? Are you using header() or something else?
Edit
Hi,
What this means ?id=&id=5 is that instead of having $_GET['id'] available as 5, it will be an array with two values, one of which will be blank, and the other will be 5.
You need to figure out why the id is being added twice and fix that. Without code, I can't tell you much else.
If it is a DEV box, go in the IIS and/or IE and remove the "Friendly http error" that way, you should get a more verbose error message.
Related
I have an image that is supposed to redirect to another page when it's clicked. It also "sends" two variables to the page, s and n.
echo "<a href='../?change-preference&s=up&n=".$element."'>
<img src='..media/images/sort-up.png'>
</a>";
On the change-preference page I get the two variables like so:
$s=$_REQUEST['s'];
$n=$_REQUEST['n'];
My problem is that I get a "Page Not Found" error.
Also, if I try to directly access the page it works, but only if I type this:
www.example.com/preference/change-preference
and not if I try it with :
www.example.com/preference/change-preference&s=up&n=999
Any help would be appreciated!
You should use:
www.example.com/preference/change-preference?s=up&n=999
The ? is being used in the incorrect place when you are building your link.
You need to build your link as follows:
$element = 900;
echo "<a href='../change-preference?s=up&n=" . $element ."'><img src='..media/images/sort-up.png'></a>";
This will give you:
www.example.com/preference/change-preference?s=up&n=900
And in the following link from your question the ? is missing, which will not work:
www.example.com/preference/change-preference&s=up&n=999
First you are using ? in the incorrect place as Daniel_ZA pointed out or you have typed incorrectly on your question the url that actually works. For this answer I will assume that it is the first case.
Second, do you have a php file named "change-preferences" without the .php extension? It is being parsed via php. I think probably not. So you should have a folder named change-preferences then and a file named index.php inside it right?
Well, that's the reason change-preference?s=up&n=900 redirects to change-preference\?s=up&n=900. Because you are accessing the index file for that address and not directly a file. It should work fine however.
If it still return a 404 (Page not Found) error then it's probably something that you haven't include in your question that isn't well configured or is having a bad behavior. Please try a simpler setup (create a new folder with only the minimal necessary to execute the url) or provide more information on your question.
Well.. I didn't mention that I am working with Wordpress because I thought this was 100% PHP question. It appears that "s" is a reserved term in Wordpress causing a 404 error. Changing the "s" fixed the problem. I am living this answer here in case that some one else working on Wordpress finds him/her self in the same position. Al of the reserved terms.
I've been trying to get the URL (including GET parameters) of a site that is displaying my image. This is because I want to extract one parameter of the URL.
A friend told me that she knew someone that could achieve this, but I don't know if he was doing it with an image. Also I don't think I can do it with a link because when going to external sites it will appear a warning page saying that you're being redirected outside, so if I put a link to my page and someone clicks, I will get the referrer URL of redirection warning page. I can't assure if my friend was telling the truth about this, but it's very likely that it was true.
All I could get with the image was the IP and other things of the HTTP header, but the referrer part is empty and I thought that the referrer contained the full URL I'm talking about.
This is what I have tried.
First the img tag in the other site in BBCode:
[img]http://______.com/get_image.php?i=myimage[/img]
And in my site this script in PHP, although any language that does the work would be good for me:
<?php
// Get name of image to be displayed (non-sanitized here for simplicity)
$filename = $_GET["i"];
// Here I want to get the site where image is being viewed
if (!empty($_SERVER['HTTP_REFERER'])) {
$visitor_url = $_SERVER['HTTP_REFERER'];
} else {
$visitor_url = "none";
}
// And write the referrer to a file just to test if it works
$fp = fopen('referer.txt', 'w');
fwrite($fp, $visitor_url);
fclose($fp);
// Eventually display the image
header('Content-Type: image/png');
readfile($filename . '.png');
?>
So my questions are:
Is it possible to get full URL of a site that is displaying my image?
If not, is there any other method to get the full URL?
Thank you in advance.
Note: I don't have any permision in the other site where I'm posting the image, I'm just an user there. Please tell me if I'm missing something or I have to ask this in another way, I'm new to StackOverflow.
Try REMOTE_HOST instead of HTTP_REFERER:
// Here I want to get the site where image is being viewed
if (!empty($_SERVER['REMOTE_HOST'])) {
$visitor_url = $_SERVER['REMOTE_HOST'];
} else {
$visitor_url = "none";
}
The web server where you are serving the image will need to be configured properly. If using Apache, this is with HostNameLookups On.
See http://php.net/manual/en/reserved.variables.server.php
Normally browsers are sending full referer with all URL components including query parameters - $_GET params. If they don't then there is no other way to achieve that URL while passing throught an image content.
Sometimes sending referer may be blocked, for eg. in some batch URL processing using some crawler like program/script or on some proxies.
In PHP receiving referer is done by $_SERVER['HTTP_REFERER'] because it's normally just http header from request and it's the only $_SERVER array key with referer info.
You added the .htaccess tag so I think you're using the Apache web server. If you'd like to prevent the issue entirely, you can disable hotlinking entirely by going one layer lower. Instead of managing in PHP, you can configure the web server to not serve content to domains other than the one you are hosting.
Check out the guide for more details.
I fixed this problem by switching my site (where image is hosted) to HTTPS. The code in my question was doing its job correctly.
It looks that HTTP_REFERER was blank because of it coming from an HTTPS site and my site being HTTP it would always send it blank. I was aware that it could be a problem, but didn't make much sense for me because HTTP_REFERER was also blank when coming from another HTTP site (which I think it's not normal) so I thought the error was in another place.
Usually HTTP_REFERER is sent when it comes from and goes to:
from HTTP to HTTP
from HTTPS to HTTPS
from HTTP to HTTPS
But it's not sent when it comes from and goes to:
from HTTPS to HTTP
And in my case, I don't know why, it wasn't being sent from HTTP to HTTP which was confusing me.
I've got to make friendly URLS work (settings + .htaccess). So, rather than getting /member.html I want to get /member.
When I try to use my PHP forms (that have worked elsewhere) they don't work here.
The form method is POST
I've tried various URLS like /, /index.php, /?id=1 and the long URL.
I've tried all sorts of POST checks like:
if($_SERVER["REQUEST_METHOD"] == "POST"){
echo "2 server request<br/>";
}
if (isset($_POST['submitButton'])){
echo "3 post submitButton is set<br/>";
}
if ($_POST['submitButton']){
echo "4 post submitButton<br/>";
}
... none of these return. So the page doesn't recognize the POST header.
This leads me to suspect that the friendly URLs is the culprit. Either that or some security setting that prevents POST traffic.
This one for you can using if and else if statement. Otherwise use the all if statements you must create a else statement.
If user request to outer query request, PHP go to the else statement.
So you need a new layout.
I seem to have fixed the problem.
I installed FormIt add on.
I don't think i'm using the FormIt functionality as such but by simply adding [[FormIt]] to the page - it is operating as expected now.
It seems that POST doesn't work unless you add the addon
I have a website that is finished and uploaded, at first it works fine but after a while it stops working.
By stops working I mean whatever page I go to just shows a blank page, empty source.
In Chrome though, I get HTTP Error 500 (Internal Server Error)
To fix this all I need to do is change debug to 2, refresh and then change it back to 0.
I do not know what triggers this to happen, I have tried clearing the cache folders.
There are no log entries in /app/tmp/logs/error from the last week.
Any ideas would be great. Thanks.
In the end it was APC cache conflicts between multiple Cakes on the same server.
All I had to do was change $prefix in config.php and it worked.
Cakephp can show also blank page, if you have some component included in your controller and it contains error, and if for some reason debug does not work(though debug level in core.php is 2 or 3 ) in your component , it just shows blank page.
this post is getting old, but today I upload a new website to a server and get the blank page so I share my experience. I have no access to server logs so I was stuck. I was very confused because that server has running another sites with cakephp so I think the problem was mod_rewrite. After several ours of testing the problem was that the server's php version was too old to run cake 2.8.3. so I use an older version of cake and everything works fine. Hope this help someone.
Happened to me when I had a constant defined, did not notice this and defined another one with the same name.
const VISIBLE = 1;
const DELETED = 0;
const VISIBLE = 1;
A few years later I will add a comment here:
This would mean there was a syntax error, make sure u display these.
It might be due to white space in end of file
Please check your all files if white space is there after ‘?>’ tag it redirects it to blank page
or you can remove ‘?>’(closing php tag) to remove this problem.
In my case i had
public function appError($error) {}
on AppController which was supposed to redirect to a 404 page and i commented the redirect. this led to me having blank page.
In my case the problem was not the cache.
Enabling CakePHP debug should be useful. Change the value to
Configure::write('debug', 0);
to
Configure::write('debug', 1);
in app/cake/core.php
to show the real errors.
I had the exact same problem, it was the folder app/tmp/cache/models that didn't exist. After creating it, no more problem.
Typical scenario:
DB items are displaied in page http://...?item_id=467
User one day deletes
the item
Google or a user
attempts to access http://...?item_id=467
PHP diggs into DB and sees items does not exist anymore, so now PHP must tell
Google/user that item is not existing via a 404 header and page.
According to this answer I undertstood there is no way to redirect to 404 Apache page via PHP unless sending in code the 404 header + reading and sending down to client all the contents of your default 404 page.
The probelm: I already have an Apache parsed custom 404.shtml page, so obvioulsy I would like to simply use that page.
But if i read an shtml page via PHP it won't be parsed by Apache anymore.
So what do you suggest me to do?
Is there maybe some trick I could use palying with htaccess too?
Thanks,
Hmm. Two ideas come to mind:
Redirect to the 404 page using header("Location:...") - this is not standards-compliant behaviour though. I would use that only as a last straw
Fetch and output the Apache-parsed SHTML file using file_get_contents("http://mydomain.com/404.shtml"); - also not really optimal because a request is made to the web server but, I think, acceptable in most cases.
I doubt there is anything you can do in .htaccess because the PHP script runs after any rewrite rules have already been parsed.
IF you are using apache mod_php, use virtual('/404.shtml'); to display the parsed shtml page to your user.
I was trying to do this exact same thing yesterday.
Does Pekka's file_get_contents/include result in a 404 status header being sent? Perhaps you need to do this before including the custom error page?
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
You can test using this Firefox extension.
I was looking exactly for something like you needed, so you have a page:
http://example.com/page?item_id=456
and if later you want that if item is missing you are redirected to:
http://example.com/page_not_found?item_id=456
In reality I found it is much more maintainable solution to just use the original page as 404 page.
<?php
$item = findItem( $_GET['item_id']);
if($item === false){
//show 404 page sending correct header and then include 404 message
header( $_ENV['SERVER_PROTOCOL'].' 404 Not Found', true );
// you can still use $_GET['item_id'] to customize error message
// "maybe you were looking for XXX item"
include('somepath/missingpage.php');
return;
}
//continue as usual with normal page
?>
So if item is no longer in the DB, the 404 page is showed but you can provide custom items in replace or error messages.