Issue
I am trying to move my site offline for obvious reasons and I am having trouble getting the localhost
PHP function to work. My code is the following:
include "http://localhost:8888/mainbar.php?display=1";
I am able to include the file if I just have it's name, but I need to pass values over the url so this is not an option. I have looked into other means of getting this to work, but the whole point of using MAMP is to be able to work offline and then upload improvements.
Next, I am unable to set cookies. Here is the following cookie code I have:
$expire=time() + (14 * 24 * 60 * 60);
setcookie("user", "Conan", $expire, '/');
I also have tried to set cookies with Chrome but am unable to do so.I would be surprised if this cannot be done.
Solution
Includes should only be given file paths, not URLs.
The proper usage would look like the following: include "/path/to/file"
include "/var/www/html/yourappfolder/mainbar.php";
I see that you are trying to pass it a variable, ?display=1
. The solution wouldn't be to figure out how to load the file with a URL parameter, you really want to redesign how your fetching the information that corresponds to the display
variable.
What you want to do is improve the software design and create a separate function somewhere, something like: getMainBarData($display)
. In your mainbar.php file, you will call this function to get the results you currently have. In your file that you're using include, you can include the file holding the new function getMainBarData($display)
, and call it directly: getMainBarData(1)
.
So basically, you want to create a function that is both usable by mainbar.php
and this file using include. 1 function that can be used by 2 pages is your optimal solution here.
As far as the cookie issue.. Try without the path "/".. so:
setcookie('user', 'Conan', $expire);
Answered By - Atticus
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.