SJF Posted July 4, 2009 Share Posted July 4, 2009 Hey guys! Brand new to the forums, so first of all I'd like to say thanks for taking time to read this! I'm broken this down as basic as possible for assistance. The Code that is in both links (include.php) below: <?php include("http://www.toyrecruiter.com/content/?p=3");?> The Error [pre]Warning: include(content/index.php?p=3) [function.include]: failed to open stream: No such file or directory in /home/content/g/r/e/greattoysearch/html/toyrecruiter/include.php on line 1 Warning: include() [function.include]: Failed opening 'content/index.php?p=3' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/content/g/r/e/greattoysearch/html/toyrecruiter/include.php on line 1[/pre] The Situation I'm using PHP includes to pull string data from a single Wordpress post so I can place it anywhere on the page. I've done it with multiple sites in the past with absolutely no problem. Working vs Non-Working Examples Working: http://www.sjf.me/include.php Non-Working: http://www.toyrecruiter.com/include.php Other Forum's Solutions Other people have had similar issues and here are some of the solutions they provided: Edit / Create PHP.ini to include allow_url_fopen = on as well as allow_url_include = on Did this. And I've saved it as both PHP.ini as well as PHP5.ini (since that's what they said to save it as if you have PHP5 installed). I -can- downgrade to PHP4 (GoDaddy allows me to do this) but I have not tried this. Call your Hosting Service Did this. They claim everything is fine on their end. I even asked why it works when I link to their server (toyrecruiter.com) via my other server (www.sjf.me - hosted through HostMonster) and still they say the PHP is working fine. Didn't help at all. Use cURL instead of php includes Did this. It does not work for me. I'm not sure why, but basically it shows up completely blank as if it wasn't bringing the data into the variables or something. Not to mention, there is no reason I should have to go this route if it is working perfectly fine on another server. Edit your .htaccess to point to a local PHP.ini file where you can change allow_url_fopen and allow_url_include I have not done this, but if anyone can point me in the right direction to do this, or feel it might solve the problem, please do! I'm at a complete loss. This website is for a client, and they have already paid for hosting from GoDaddy for a while so switching hosting services is not a choice (or at least not one I think they'll want to do). www.sjf.me is hosted with HostMonster.com with PHP 5 www.toyrecruiter.com is hosted with GoDaddy.com with PHP 5 Thanks again for taking the time to read this and hopefully someone has a solution! Happy 4th of July! Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/ Share on other sites More sharing options...
newbtophp Posted July 4, 2009 Share Posted July 4, 2009 <?php include("/content/?p=3");?> Try without the domain, or modify the path. Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-868967 Share on other sites More sharing options...
MadTechie Posted July 4, 2009 Share Posted July 4, 2009 Erm.. you shouldn't include things like that! (sign of a bad design) I guess you could do this <?php $_GET['p'] = 3; include("content/index.php"); ?> that doesn't fix the bad design problem! Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-868968 Share on other sites More sharing options...
SJF Posted July 4, 2009 Author Share Posted July 4, 2009 <?php include("/content/?p=3");?> Try without the domain, or modify the path. Sorry I forgot to put that I tried this. It doesn't seem to work either. Erm.. you shouldn't include things like that! (sign of a bad design) I guess you could do this <?php $_GET['p'] = 3; include("content/index.php"); ?> that doesn't fix the bad design problem! All due respect, but I honestly don't see it as a bad design. All I am doing is taking a single wordpress post and stripping it down to pure HTML code and then somehow taking that data and plugging it where you want to on a site (so that the client can later update the page whenever they want). The fact is that it has worked in the past (and as you can see, still works from sjf.me including it) so I'm not sure why it's not working otherwise. Also, what would you suggest as a solution otherwise, if the include is "bad design" in your opinion? Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-868969 Share on other sites More sharing options...
newbtophp Posted July 4, 2009 Share Posted July 4, 2009 Also, what would you suggest as a solution otherwise, if the include is "bad design" in your opinion? Urls like ?p=3 is non seo friendly. Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-868971 Share on other sites More sharing options...
SJF Posted July 4, 2009 Author Share Posted July 4, 2009 Also, what would you suggest as a solution otherwise, if the include is "bad design" in your opinion? Urls like ?p=3 is non seo friendly. Point taken. That's why I'm not using those URLs in the actual site. The actual site is www.toyrecruiter.com - check it out to see the error I'm referring to. You can see, for the top content I'm using a PHP include from the wordpress post (the ?p=3 you are referring to). I have other websites where this works 100% perfectly fine, so my question here isn't "is this good design" or "is this SEO friendly". My question is why doesn't it work on this GoDaddy server, when it works fine on my HostMonster server? Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-868972 Share on other sites More sharing options...
MadTechie Posted July 4, 2009 Share Posted July 4, 2009 I said its a sign of a bad design, the fact it works doesn't change that. the fact you need to pass a get value to an included file shows the bad design, if the file is on the same server (which I assume it is) then you should at least use sessions in the file (your including) a simple work around should be <?php readfile("http://www.toyrecruiter.com/content/?p=3"); ?> but without a greater understanding of what you have done and want your trying to achieve it very hard to say. EDIT: please don't take offence, I am just trying save you time when expand your current solution, as these things make life harder later on, fixing them sooner saves major headaches later! Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-868975 Share on other sites More sharing options...
SJF Posted July 4, 2009 Author Share Posted July 4, 2009 MadTechie - I appreciate it, I really do. However, both codes you provided are not working and are giving the same error. Here is what I'm trying to achieve in a nutshell, so that you have a greater understanding. In Wordpress, you can create posts. Each post is a link, just as I have included there (http://www.toyrecruiter.com/content/?p=3). If you go there and go ahead and view the source you'll see it's just HTML code. This is so that the client, in the future, can edit the content on that part of the website via editing the Wordpress post. So basically I am using Wordpress as a CMS, putting editable regions where I want them. Does this make sense? As I said before, it works fine on other pages. It validates fine. It works fine with SEO. I'm just not sure why it's not working with GoDaddy's service, versus my other service. Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-868979 Share on other sites More sharing options...
MadTechie Posted July 4, 2009 Share Posted July 4, 2009 Okay the reason its not working is simple, remote file access is turn off, So you can't pull in data from remote files, the way your have designed the system to work is to pull in data from word press post parse, this requires you to pull in the remote file.. the fact that go daddy has blocked this is the cause of the problem, Theirs a few solutions (I can think of), #1, create your own CMS (okay that's going to be a pain) #2, create a hack to fit your solution into WP, #3, create an adapter, basically your own class that connects to WP and display the correct info via sessions (whatever) #4, read directly from the WP database Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-868985 Share on other sites More sharing options...
SJF Posted July 4, 2009 Author Share Posted July 4, 2009 Ok. Would remote file access have anything to do with: [pre]allow_url_fopen = on allow_url_include = on[/pre] ? If so, is there a way to edit the .htaccess file to point to my local PHP.ini and use that instead of the main one (GoDaddy's) that it's probably using? Or is there another line of code I should put in my ini maybe? Here's my PHP ini file code: register_globals = off allow_url_fopen = on allow_url_include = on expose_php = off max_input_time = 60 variables_order = "EGPCS" extension_dir = ./ upload_tmp_dir = /tmp precision = 12 SMTP = relay-hosting.secureserver.net url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" [Zend] zend_extension=/usr/local/zo/ZendExtensionManager.so zend_extension=/usr/local/zo/4_3/ZendOptimizer.so Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-868994 Share on other sites More sharing options...
MadTechie Posted July 4, 2009 Share Posted July 4, 2009 allow_url_fopen = on is the main one, so changing that and restarting apache should get you up and running, as I personally don't use GoDaddy for hosting, I decided to look at what options they have Now if you have Hosting Configuration 2.0 your in luck Can I add a PHP initialization file to my hosting account? If you are running Hosting Configuration 2.0, you can create custom .ini files for both PHP 4 (php.ini) and PHP 5 (php5.ini) in the root directory of your site. By default, only php.ini is automatically created during new account setup. Initialization files can be used to manage form, server, and environmental variables, server-side cookies, temporary directories, error display, and error logging. you could create/edit that root php.ini file and that should be all.. Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-868998 Share on other sites More sharing options...
SJF Posted July 5, 2009 Author Share Posted July 5, 2009 Alright, this sounds like it might work. Thanks for looking into that. Now I just need to know how to do one of two things... 1) How to restart apache. or 2) how to edit the php.ini file directly on the page and hit some sort of "save" button so it automatically restarts apache. I'm looking for either one now. Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869004 Share on other sites More sharing options...
MadTechie Posted July 5, 2009 Share Posted July 5, 2009 Try connecting to the site via FTP, download and edit then upload the file.. Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869008 Share on other sites More sharing options...
SJF Posted July 5, 2009 Author Share Posted July 5, 2009 Did that, and have done that. It didn't have a PHP.ini file or a PHP5.ini file so I made both and uploaded it, and still nothing. So what I did was a little research and stumbled upon this page: http://help.godaddy.com/article/1409 It talks about how to edit the PHP.ini file via SSH - but it's for dedicated server, while this is a shared one. So I did that whole special request for access to SSH, and it is running setup now. I'm guessing Apache restarts every 24 hours so hopefully within 24 hours it will read my new php.ini file and just reapply it with the _fopen settings. Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869013 Share on other sites More sharing options...
MadTechie Posted July 5, 2009 Share Posted July 5, 2009 Looking back I am still not sure why my first suggestion didn't work.. I have tweaked it a little, and it should work, assuming its in the folder that contains the folder "content" that as WP inside. <?php $_GET['p'] = 3; include(dirname(__FILE__)."/content/index.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869015 Share on other sites More sharing options...
SJF Posted July 5, 2009 Author Share Posted July 5, 2009 I get the following error: [pre] Warning: require(./wp-blog-header.php) [function.require]: failed to open stream: No such file or directory in /home/content/g/r/e/greattoysearch/html/toyrecruiter/content/index.php on line 17 Fatal error: require() [function.require]: Failed opening required './wp-blog-header.php' (include_path='.:/usr/local/php5/lib/php') in /home/content/g/r/e/greattoysearch/html/toyrecruiter/content/index.php on line 17 [/pre] Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869019 Share on other sites More sharing options...
MadTechie Posted July 5, 2009 Share Posted July 5, 2009 Ahh so the problem is the following includes, changing the working directory may fix that <?php $_GET['p'] = 3; chdir('content'); //added include(dirname(__FILE__)."/content/index.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869021 Share on other sites More sharing options...
SJF Posted July 5, 2009 Author Share Posted July 5, 2009 It worked!!! You're a genius! Too bad you don't live in the US, I'd buy you a drink! Thanks SO much for your assistance. Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869034 Share on other sites More sharing options...
MadTechie Posted July 5, 2009 Share Posted July 5, 2009 Your welcome, we need a buy a drink button on this site lol Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869039 Share on other sites More sharing options...
SJF Posted July 5, 2009 Author Share Posted July 5, 2009 Ugh... ??? hold the phones. When I try adding that code for multiple posts on one page it gives me this error: [pre]Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /home/content/g/r/e/greattoysearch/html/toyrecruiter/index.php on line 160[/pre] See www.toyrecruiter.com for where the errors are appearing and what I'm trying to do... Think you can help me out one last time? Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869357 Share on other sites More sharing options...
SJF Posted July 5, 2009 Author Share Posted July 5, 2009 Here's something I attempted after doing a bit of research. What it is doing is trying to find the directory "content" within the folder "content" since it is already inside the directory "content". So, I found that if before you ever call chdir('directory') if you put $cwd = getcwd(); it will save the current directory, which then you can come back to it. So I did this code: $cwd = getcwd(); $_GET['p'] = 3; chdir('content'); include(dirname(__FILE__)."/content/index.php"); chdir ($cwd); So as you can see – it brings PHP back to the directory it started in, so the next include I simply have to put the same code (change the 'p' value), keep the chdir the same, include the same way, and at the end "reset" the chdir by using chdir ($cwd); I've done that, and now nothing shows up at all. Not even an error. So I echoed $_GET['p'] and it reads 3 the first time, and on the second include (when I change the value) it reads 8, how it should, etc. When I echo getcwd(); it echos fine (in the root, where it should) or in content if I echo after chdir ('content'). So now I'm baffled. Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869416 Share on other sites More sharing options...
MadTechie Posted July 5, 2009 Share Posted July 5, 2009 Your better bet is to do this $_GET['p'] = 3; $WPdir = dirname(__FILE__)."/content"; chdir($WPdir); include($WPdir."/index.php"); that way your using the absolute path EDIT: minor typo in code Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869433 Share on other sites More sharing options...
SJF Posted July 5, 2009 Author Share Posted July 5, 2009 Ok cool, I swapped out all of the code. But still nothing appears after the very first include. I'm wondering if it is because I'm including the same index.php file but with different variables for p in different places on the page... Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869438 Share on other sites More sharing options...
MadTechie Posted July 5, 2009 Share Posted July 5, 2009 So are you trying to pull more than one include ? Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869447 Share on other sites More sharing options...
SJF Posted July 5, 2009 Author Share Posted July 5, 2009 Yea, just as a quick debug mode, I've set up www.toyrecruiter.com/include.php with the following code inside: <?php $_GET['p'] = 3; $WPdir = dirname(__FILE__)."/content"; chdir($WPdir); include($WPdir."/index.php"); ?> <hr /> <?php $_GET['p'] = 8; $WPdir = dirname(__FILE__)."/content"; chdir($WPdir); include($WPdir."/index.php"); ?> Because each include is going to be in a different DIV on the page, take this example as simply debugging. The second include doesn't do anything. It just doesn't bring the post in at all. Edit: Doing more than one include seems to work if I just pull in a simple PHP file twice, so I'm guessing it has something to do with the way the variables are. It must not like me trying to bring in two pages at once. Quote Link to comment https://forums.phpfreaks.com/topic/164787-solved-php-include-not-working-server-side/#findComment-869448 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.