Jump to content

Newbie question (or maybe not)


Go to solution Solved by ricmetal,

Recommended Posts

hi guys

so im trying to access a variable from an included php file, included using a full address, with http://www...

but its not working.

 

i read up on php manual but i dont get the answers

im

using php 5.3

path is correct

allow url is on

included file is inclosed with php tags...

 

could i get some help?

 

here is the simple code i am using

 

 
// included.php
<?php
$a = "data";
?>
 
// main.php
<?php
include "http://www.somedomain.com/included.php";
echo $a; // outputs nothing
?>
 

 

what gives?

gracias

Link to comment
https://forums.phpfreaks.com/topic/287118-newbie-question-or-maybe-not/
Share on other sites

Make sure this is set allow_url_include in you php.ini file.

 

Reference: http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-include

 

yep, allow_url_include is off.

also didnt see that bit of info on php manual site.

anyway, i dont wanna need to mess with ini settings for this one. ill have to go around using the full address.

thanks!

i am trying to work with htaccess!

trying to figure out how it works still - i thought i would need to use the full address but im more confused now that before lol

i thought the 404 custom error page would keep the original url the user typed in (the failed url, hence the 4040 error) so the 404 error page would need to target elements scattered across the folder tree. thus the need for the include with full url.

 

btw, regarding htaccess, does anybody know if it is at all possible to automatically make the folder in which the htaccess is, the root folder? i read alot of people using hardcoded url to set their base folders but i would like to have this automated if possible.

Edited by ricmetal

I think you are getting confused with how PHP and HTML works.

 

PHP uses file paths when requiring files from the file system. Whereas HTML uses http requests (a url) to request for files from the server.

 

PHP has nothing do with the .htaccess (unless you are using the php_flag or php_value directives to alter PHP's config). The .htaccess  file is only invoked when responding to a http request.

  • Solution

i understand. my issue was that in thinking that the 404.php page would show up, in place of a nonexistent, typed-in url (by a user), and seeing that the 404.php file needs to include elements found across the folder tree, that i would need to target them using the full path. while this is correct, it is incorrect to think the nonexistent url would stay the same while the 404.php would be shown. i don't know why i was thinking that that is how it worked, but you see my logic in needing to use the full path, and why i brought htaccess into the picture.

 

if a file is not found, show the custom 404.php error page. from the 404.php page, include another file to use elements found in different areas of the tree. and to target them from different locations where the 404.php would be shown, i'd need the full url.

 

hehe

 

so, it turns out that the htaccess redirect when a page is not found actually redirects the url to the custom 404.php page instead of 'moving' the 404 file to the current location the user is.

 

HENCE, liking to automatically set the root of the website to where the htaccess file is. Seeing htaccess is complicated as chinese algebra and a little bit of Dead Space moon talk, i decided to hardcode the website's root folder in the htaccess file and remember that the custom 404.php error page does not move places in the tree folder, hence, not needing to use ful url's to include other folders from the server tree, as well.

 

and that is a wrap. this is what you get when you start building something in which you are a tad bit buried into too much of what you don't know, backed up with alot of what you'd like :)

that and taking long breaks while doing so!

cheers!

Edited by ricmetal

If you are passing ErrorDocument an absolute url to 404.php, then the user will be redirected to that page

ErrorDocument 404 http://sitename.com/path/to/404.php # causes redirect

If you don't want the redirect to happen then drop the http://sitename.com part from the path.

ErrorDocument 404 /path/to/404.php # does not cause redirect

The file paths used in your HTML you must then use an absolute url for serving files, whereas with PHP the file paths will be relative to where 404.php is located on the file system.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.