URL repeats itself, leading to a 404 error - php

My page will redirect the user to another page which will handle all the updating information. I got the redirect in itself working, problem is, the URL isnt what i expect it to be, leading to a 404 error. Let me try to exemplify.
The user clicks a button, redirecting him to "test.com/main/update.php". But my file is in "test.com/test/RazorFinger/update_test.php". so it ends up being something like this:
<FORM name=form id="form" action="test.com/main/update.php?area=<?=$GetArea?>&etc..." method="POST" target='_blank'>
So my main URL is this:
http://test.com/teste/RazorFinger/update_test.php?area=TestArea&proj_id=1234&task_uid=1
And the redirected url is basically:
http://test.com/teste/RazorFinger/test.com/main/update.php?area=TestArea&etc..etc..etc..
The question might be a bit complicated because i'm using fake URLs as example, but basically, i can't get out of "test.com/test" and into "test.com/main", and that leads me to a 404 error. So what's wrong?

put http:// (or https:// if you use SSL) in font of the url.
<form action="http://test.com">
This will lead to the URL http://test.com
<form action="test.com">
This will lead to the URL http://test.com/test.com

you are passing the whole url in the action so this code will obviously give an error.
Replace action by action="test.com. u will get correct result

Related

PHP - Redirecting to previous page after logging in AND INCLUDING GET DATA

Okay so first off, sorry if this is a duplicate. I've searched for around 20 minutes all over stack overflow AND the internet, and I can't seem to find a solution to my problem.
What I'm trying to do:
I have a login form on every page, with a hidden input containing the current page the user is on - so when they login, it successfully redirects back to the page they were on.
E.g. User is on news.php and not logged in. They login, which takes them to login.php to verify data, then redirects back to news.php
This works great!
The problem: If there is any get data or anchor tags at the end of the URL, I can't seem to redirect back to that.
E.g. User is on news.php?id=4#comments and not logged in. They login, etc etc, but it redirects back to news.php and ignores the trailing data.
Anyone have any help here?
My code:
<input type="hidden" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" name="location" />
$previousPage = $_POST['location'];
header("refresh: 1; url=".$previousPage);
Obviously I think the issue is the $_SERVER['HTTP_REFERER'] part, but I'm not sure what to replace it with to make it include trailing data.
All help is appreciated!
Just use
print_r($_SERVER);
and select the one that fits your needs most!
Hint: Combine HTTP_HOST and REQUEST_URI.
The hash portion will actually never be send to the server: Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
Thanks to #Tobias,
This is what I ended up with:
<?php echo basename($_SERVER['REQUEST_URI']); ?><script>document.write(window.location.hash); </script>
Which on a page like example.com/news.php?id=2#comments will return:
news.php?id=2#comments

error 406 not acceptable when i use iframe

I am using a form action in Iframe page.(if1.php). I want to navigate to(mail.php) page which is a regular php page. (ie iframe page to another page). The code in iframe page(if1.php) for navigation is shown below..
<form target="myframe" action="mail.php" method="post">
<!-- code here -->
</form>
But i am getting the following error when i press a submit button in iframe page(if1.php). Why is this error happening? The browser that I'm using is chrome.
Not Acceptable An appropriate representation of the requested resource
/radical/mail.php could not be found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
First THANKS for all those who tried helping me in finding the solution ...
The issue was only a "server specific" and not "code specific"...The Server team was able to rectify the issue with some minor changes in server settings and every thing works fine now...
Again many Thanks
Regards,

Codeigniter url gets appended every click

I have a problem with CI whenever i click a button in a form which has an action of image/upload or a hyperlink with the same link it gets appended whenever i click it the second time. say for example my home is localhost/admin and i click a button or a link which has image/upload.. so the url will now beh localhost/admin/image/upload but when i click the same button the second time the url will now beh calhost/admin/image/image/upload wchich well then cause a 404 error which ofcourse is the error given that the page is not found by just seeing that url. it gets appended every time i click the button or the link.
Anyone of you knows this please do share!
UPDATES:
BTW just a headsup for all those people who didn't know or who encountered this problem.. USE anchor or any helper in CI becuase if you manually put links in href or actions on form tag without putting the base_url.. your URL will be messed up.. helpers do append base_url. :D
Check out the Codeigniter docs and the URL Helper. That should help out.
http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
I know for anchors you would just do:
echo anchor('image/upload', 'Upload');
This will append the url to the base url and you don't have to worry about changing anything or any 404 errors.
just put http:// at infront of your link.
or otherwise
change your config file:
$config['base_url'] = 'http://www.yourhost.com/home';
try to link the url as '/path-to-url'. notice '/' before url.
Link
currently you might be doing like below
Link
Also try changing
$config['base_url'] = 'http://localhost/home/';

HTTP POST issue without filename

I have a form that uses the POST method to send data. The POST destination is configured as "http://www.example.com/form". However, the actual POST file is "http://www.example.com/form/index.php".
Because the action does not include the file name (index.php), the POST variables are not making it to the page. (This said, GET requests seem to work fine.)
Short of changing the action and/or method, is there any fix for this? Can I implement a mod_rewrite rule to pass the POST values along to the page?
I could not reproduce this with
<form action="/test/" method="POST">
But I was able to reproduce it with
<form action="/test" method="POST">
In the second case my Apache send as Moved-Permanently redirect to /test/ and the POST variables are lost.
This redirect is done by mod_dir.
If you disable mod_dir links to a directory without a trailing slash a simply not working any more.
The only advice I can give you is to fix the form's action.

how to manage the use of both $_SERVER['PHP_SELF'] in action of form and htaccess for urlrewriting together for same page?

how to manage the use of both $_SERVER['PHP_SELF'] in action of form and htaccess for url-rewriting?
If I submit a form and in the action attribute of it i pass "$_SERVER['PHP_SELF']" and at the same time i am using url rewriting for the same page.. then these two things will contradict each other resulting in the display of action value of form in address bar.. so how can i manage this to get the url rewrited form of $_SERVER['PHP_SELF']?
here the rewrite rule is to change the name of url file likewise as if form is submitted to any file say direction.php then rewrite will change it to something 30/redirect.html
I am not sure what rewrite setup you have got so my guess is you have to specify the url in form action. You'd not be able to use $_SERVER['PHP_SELF'] as it will return the path of file which is actually being executed.
For example:
<form action="'.$_SERVER['PHP_SELF'].'">
to
<form action="'./url/as/per/rewrite'].'">
If this doesn't serve the purpose. You can have a look at $_SERVER['REQUEST_URI'] or
$_SERVER['REDIRECT_QUERY_STRING']
$_SERVER['REDIRECT_URL']
and update the form action value.
I hope it helps.

Categories