Jump to content

Traxus

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Everything posted by Traxus

  1. You know when you spend 20 minutes writing a post and you figure out the answer 20 seconds after? I looked into $GLOBALS['var] on the included page. Worked. FML. <?php echo "<!-- 1234 1234 1234 1234 -->"; //test measure to see if/where file is including $section_keywords = "red, secondary"; $section_description = "this is the red section description"; $GLOBALS['xyz'] = "1234"; //test Var to see if there was a naming conflict with the above two.. ?>
  2. I'm having a problem with (what I'm almost certain is) variable scope, maybe you can help... So I've got a parent class that, among other things, gets the name of the filepath, explodes this filepath, checks for files with names that mirror that filepath (without the slashes of course), and includes them if they exist: class ParentClass { public $RootFolder; public $PageSections; function __construct() { global $root_folder; $this->RootFolder = $root_folder; //get all directory names... $cleanse = $this->RootFolder; $pagepath = str_replace($cleanse, '', dirname($_SERVER['PHP_SELF'])); $this->PageSections = explode('/', $pagepath); } function RequireIfExists ($sections, $root_folder, $file_name, $file_type) { foreach ($sections as $i){ if (isset($o)) { $i = $o."/".$i; } $file = $root_folder.$i."/".$file_name.$file_type; if (file_exists($_SERVER['DOCUMENT_ROOT'].$file)) { require ($_SERVER['DOCUMENT_ROOT'].$file); echo "<!--".$file." included -->"; //temporary measure to ensure that the file is at least being called. } $o = $i; } } // so, excuting the function // $this->RequireIfExists($this->PageSections, $this->RootFolder, "sectionvars", ".php"); // on some/sub/folder/index.php // will look for somesectionvars.php, somesubsecitonvars.php & somesubfoldersectionvars.php // and include whichever ones exist. } Then there is a child class that utilizes this function, and successfully requires the file. I know the file is coming through because the echo statement on the page shows up in the code, but I cannot get the variables to pass through? <?php class HtmlHead extends PageBlock{ public $PageKeywords; public $PageDescription; public $PageStyles; public $PageScripts; //------------------------ public $SectionKeywords; public $SectionDescription; //------------------------ public $SiteKeywords; public $SiteDescription; public $SiteStyles; public $SiteScripts; //------------------------ public $CatchAll; function __construct() { parent::__construct(); //$this->RequireIfExists($this->PageSections, $this->RootFolder, "sectionvars", ".php"); //I have tried calling the function here with no luck global $site_description, $site_keywords, $section_description, $section_keywords, $xyz; //also made sure to global the variables from the required page $this->SiteDescription = $site_description; $this->SiteKeywords = $site_keywords; $this->SectionDescription = $section_description; $this->SectionKeywords = $section_keywords; $this->PageDescription = $page_description; $this->PageKeywords = $page_keywords; } function Constructor() { $this->RequireIfExists($this->PageSections, $this->RootFolder, "sectionvars", ".php"); //Tried calling the function here as well, no luck global $xyz; //global'd the var i want echo "\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />"; echo "\n<!--Sec Keywords are".$xyz."-->"; //Tried to echo the var... //------------------------Rest of code... } } And here is the page that is being required... <?php echo "<!-- 1234 1234 1234 1234 -->"; //test measure to see if/where file is including $section_keywords = "red, secondary"; $section_description = "this is the red section description"; $xyz = "1234"; //test Var to see if there was a naming conflict with the above two.. ?> What am I overlooking this time?
  3. thanks for that, still new to classes/OOP had no idea about __construct()
  4. I'm confused as to why assigning these variables in the class causes the page not to load... var $RootFolder = '/shyid/'; var $PagePath = str_replace($this->RootFolder, '', dirname($_SERVER['PHP_SELF'])); var $PageSections = explode('/', $this->PagePath); but when i set them on the page, everything works correctly? $head->RootFolder = '/shyid/'; $head->PagePath = str_replace($head->RootFolder, '', dirname($_SERVER['PHP_SELF'])); $head->PageSections = explode('/', $head->PagePath); Insight? Thanks.
  5. As of yesterday, I have just started playing with classes, I'm a complete greenhorn regarding OOP. I'm in the midst of building myself a simple templating engine. I have a question regarding a common function (method?) named EchoIfSet that appears in two classes: function EchoIfSet ($open_tag, $file_src, $close_tag) { if (isset($file_src)){ echo "\n".$open_tag.$file_src.$close_tag; } } I know there is a more efficient way to use this in both classes: <?php class HtmlHead { var $Keywords; var $Description; var $PageStyles; var $PageScripts; //------------------------ var $SectionStyles; var $SectionScripts; //------------------------ var $SiteStyles; var $SiteScripts; //------------------------ var $CatchAll; function Constructor() { echo "\n<head>"; echo "\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />"; echo "\n<meta name='keywords' content='".$this->Keywords."' />"; echo "\n<meta name='description' content='".$this->Description."' />"; //------------------------ $this->EchoIfSet("<script src='", $this->SiteScripts, "' type='text/javascript'></script>"); $this->EchoIfSet("<script src='", $this->SectionScripts, "' type='text/javascript'></script>"); $this->EchoIfSet("<script src='", $this->PageScripts, "' type='text/javascript'></script>"); //------------------------ $this->EchoIfSet("<link rel='stylesheet' type='text/css' href='", $this->SiteStyles, "' />"); $this->EchoIfSet("<link rel='stylesheet' type='text/css' href='", $this->SectionStyles, "' />"); $this->EchoIfSet("<link rel='stylesheet' type='text/css' href='", $this->PageStyles, "' />"); $this->EchoIfSet(NULL, $this->CatchAll, NULL); echo "\n</head>"; } function EchoIfSet ($open_tag, $file_src, $close_tag) { if (isset($file_src)){ echo "\n".$open_tag.$file_src.$close_tag; } } } ?> <?php //this one will be called several times on the page class HtmlBlock { var $DivId; var $DivClass; var $DivContent; function Constructor() { //------------------------ echo "\n<div"; $this->EchoIfSet(" id='", $this->DivId, "'"); $this->EchoIfSet(" class='", $this->DivClass, "'"); echo ">"; //------------------------ $this->EchoIfSet(NULL, $this->DivContent, NULL); //------------------------ echo "\n</div>"; } function EchoIfSet ($open_tag, $file_src, $close_tag) { if (isset($file_src)){ echo "\n".$open_tag.$file_src.$close_tag; } } } ?> But I'm not sure where to look for documentation on this. I did some googling/rtfm regarding subclasses, but all of that documentation seems to be in regards to abstract classes, and if i understand correctly abstract classes should have no functions or variables actually defined in them, its basically a template for other classes... Can anyone point me towards a tutorial that deals with class hierarchies?
  6. Disregard that last post... You gave all the information I needed, thanks a lot!
  7. Thanks for your help. I was able to pass the variables from the local config.php file to the remote form_builder.php file via this method, constructing the input form correctly: $crossDomainVar = "value"; echo "<?php \$crossDomainVar='".$crossDomainVar."' ?>"; However, I'm kicking myself for not realizing that the remote results_builder.php relies on $_POST variables that come from the local site. Can you (or anyone?) point me to some examples or documentation on that? Thanks again.
  8. I had a feeling it was something like this, but couldn't wrap my head around it. Would fsockopen(); or any of the file reading functions avert this? If so, would it be hopelessly inefficient regarding bandwidth and processing power? That's intresting, I didn't know you could echo entire blocks of php code... in other words: $crossDomainVar = "value"; echo "<?php \$crossDomainVar='".$crossDomainVar."' ?>";
  9. I can't seem to use variables in a php script when they are in a php file included from another domain. I have allow_url_include on, and have successfully included php files from the other domain, spare this detail. Here's the situation, I've got a php script that will build a contact form based on feilds defined in an xml file and variables set in a config.php file. The config.php file has a variable that defines the path to the xml file, as well as the path to the form builder php file, and other things like the subject of the email that will be sent upon filling out the form, and the recipients email address. At the moment, I've got this setup running on about 15 different domains. Every time that I need to update the form builder, I have to make the changes and then re upload the file to each domain, which is becoming a pain in my behind. I decided to try and call this file from one of my personal domains, that way any new update would apply to each domain that called it. However, I wanted the unique form info (xml and config.php file) to remain on the clients domain, as that feels more sensible to me. When I include a page with the following code, from mypersonaldomain.com the everything works: $xml_path = "http://www.clientdomain01.com/form_feilds.xml"; function form_generator() { //lotsa code } form_generator(); But when I do this on clientdomain01.com, the second file won't read the variables from the first: require_once ('site/relative/path/to/config.php'); //this is the config page that points to the xml require_once ('http://www.mypersonaldomain.com/form_builder.php'); //this is the php page that reads the config.php and xml files (for reference, form_builder.php looks something like): function form_generator() { //lotsa code that reads config.php and form_feilds.xml } form_generator(); I've done some expirimenting, by including a variables.php page and then trying to echo those variables, and the echo wont display the vars from the other domain, so I'm sure this is the bottleneck. Variables are global where they need to be... Ive tried global $var1, $var2; as well as $GLOBAL['var1']... Googling hints that this needs to be done through $_POST and fsockopen(); but I haven't found any concrete examples... Is this a security feature, or just a php.ini setting? It seems that, if i could include a variables.php page from the same domain and utilize those vars, I could also do the same with a page on a different domain? I'm aware that there are third party solutions for hosted contact forms etc... But I would like to learn this cross domain for future application. Thanks for your time... [attachment deleted by admin]
×
×
  • 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.