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.
Related
I am working on a site and the builders have used a mix of php and html for links. For example:
<li>Variable Speed Drives</li>
<li>Corrosion Resistant Baseplates</li>
and
<li>MP Repair</li>
<li>MTA Repair</li>
The php is referenced in another file in this way:
<?php
$pdf_link = "../pdf/";
$external_pdf_link = "../../pdf/";
$video_link = "../video/";
$external_video_link = "../../video/";
?>
My concern is not knowing the function of the php, other than it being a placeholder, and given that the links work both ways, I don't want to break something because I am clueless to its purpose.
In doing my due diligence researching, I ran across this post, which is close, but still no cigar, Add php variable inside echo statement as href link address?. All of the research seems to be about how rather than why. This is the site, and they only used it for the "Downloads" links: http://magnatexpumps.com/
Thank you...
B
There is no right way. They are just different.
Let's forget the PHP for a while. If you have this link in a page:
<a href='about.html'/>About</a>
What will happen? The browser will change the URL of the document. If you are at the root of the site like: "www.example.com", will redirect to "www.example.com/about.html". If you are in a URL like "www.example.com/news/index.html" will redirect you to "www.example.com/new/about". That's why sometimes it is useful to have a variable before, to force a full path URL.
Another case of URL variable interpolation is when you have different systems running in the same url. In this case, you will have to append the system name in order to get to where you want. If you don't know where your application will run if it will run on the doc root, or in a subfolder, use a variable to indicate the base path.
I recently started getting this error on my site :
The requested URL /ilanlar.php was not found on this server.
although the link is correct and I have set the path and everything correctly, the link I try to access is as follows :
http://domain.com/%EF%BB%BFilanlar.php?il=34&ilce=34.35&mah17050&path=2
here the surprising thing is, I have the link defined as:
<a href='http://domain.com/ilanlar.php?il=34&ilce=34.35&mah17050&path=2'>CLICKY</a>
but the %EF%BB%BF part is being added automatically on its own, what am I missing here?
Change the file encoding to UTF8, delete the link and type it again.
Don't copy/paste it. Type it.
So I made a script so that I can just use includes to get my header, pages, and then footer. And if a file doesnt exist a 404. That all works. Now my issue is how I'm supposed to get the end of the url being the page. For example,
I want to make it so that when someone goes to example.com/home/test, it will automatically just include test.php for example.
Moral of the story. How to some how get the page name. And then use it to "mask" the end of the page so that I don't need to have every URL being something.com/home/?p=home
Heres my code so far.
<?php
include($_SERVER['DOCUMENT_ROOT'].'/home/lib/php/_dc.php');
include($_SERVER['DOCUMENT_ROOT'].'/home/lib/php/_home_fns.php');
$script = $_SERVER['SCRIPT_NAME']; //This returns /home/index.php for example =/
error_reporting(E_ALL);
include($_SERVER['DOCUMENT_ROOT'].'/home/default/header.php');
if($_GET["p"] == 'home' || !isset($_GET["p"])) {
include($_SERVER['DOCUMENT_ROOT'].'/home/pages/home.php');
} else if(file_exists($_SERVER['DOCUMENT_ROOT'].'/home/pages/'.$_GET["p"].'.php')) {
include($_SERVER['DOCUMENT_ROOT'].'/home/pages/'.$_GET["p"].'.php');
} else {
include($_SERVER['DOCUMENT_ROOT'].'/home/default/404.php');
}
include($_SERVER['DOCUMENT_ROOT'].'/home/default/footer.php');
?>
PHP by itself wouldn't be the best choice here unless you want your website littered with empty "redirect" PHP files. I would recommend looking into the Apache server's mod_rewrite module. Here are a couple of guides to get you started. Hope this helps!
The simplest way would be to have an index.php file inside the /home/whatever folder. Then use something like $_SERVER['PHP_SELF'] and extract the name if you want to automate it, or since you are already writing the file yourself, hardcode it into it.
That however looks plain wrong, you should probably look into mod-rewrite if you are up to creating a more complex/serious app.
I would also recommend cakePHP framework that has the whole path-to-controller thing worked out.
so I hope someone would help me.
My first page is leave_app.php. In this page I put a link to apply leave, using the normal code:
New Leave Application
However the link didn't display as I had wished for.
"The requested URL /ci/add.php was not found on this server." and the link in the browser leads to this "http://localhost/ci/add.php".
I don't know why the server didn't find the page. I already made add.php page, also add at the leave_app controller the function add().
In the config.php file I put $config['index_page'] = '';
I have asked around but no one can help. I have already surfed around, but still don't know how to solve.
The beauty of Codeigniter is to rewrite urls in a clean manner, so all things go through index.php and the corresponding controller is loaded
Try accessing it like so:
/ci/index.php/add
Make sure your controller is in application\controllers\add.php and named Class Add
i have some problem i try to get the uri in php.
I'm using:
$_SERVER['REQUEST_URI']
It works just fine if i do it in the index.php, but, i NEED to get the url in a include file, but, when i do it, it takes the FILE adress, i mean, it shows something like this
adress bar: www.webpage.com/index.php
$_SERVER['REQUEST_URI'] output: webpage/includefile.php
I am explaining myself here? Thanks!
How are you including the file? If it's being included via an HTTP reference then it's actually being served as a page and the functionality you are seeing is correct. If the include path is a local file, you shouldn't be seeing this behaviour
Found this whilst trying to solve the same issue.
My solution that worked is to use $_SERVER['HTTP_REFERER']
This worked well in that it also included the parameters (e.g. ?this=that&foo=bar)
Maybe somewhere in your code (or in another include file) the value is overwritten.