Simple PHP Code Not Working?

Discussion in 'PHP' started by WXM Matty, Apr 16, 2008.

  1. #1
    I have some php code. In the code I put links im using it so that when I update the links on my website it does it on all pages.

    The code works fine untill I place it in a folder other than the root directory.

    The error I get is:

    Warning: main(affiliates.php) [function.main]: failed to open stream: No such file or directory in /home/pecli/public_html/gaming/PS3.php on line 216
    
    Warning: main(affiliates.php) [function.main]: failed to open stream: No such file or directory in /home/pecli/public_html/gaming/PS3.php on line 216
    
    Warning: main(affiliates.php) [function.main]: failed to open stream: No such file or directory in /home/pecli/public_html/gaming/PS3.php on line 216
    
    Warning: main() [function.include]: Failed opening 'affiliates.php' for inclusion (include_path='.:/usr/php4/lib/php:/usr/local/php4/lib/php') in /home/pecli/public_html/gaming/PS3.php on line 216
    Code (markup):

    The PHP code is:

    <div id="cont">
    
    		
    		<ul>
    		<li>
    		<a href="#" onClick="MyWindow=window.open('http://www.xninelivesx.com/wowgold.htm','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=230,height=108'); return false;">WOW Gold</a> - <i>5% Off</i></li>
    		</ul>
    		<p><i>&nbsp;&nbsp; Online Flash Games</i></p>
    		<ul>
    		<li><a href="http://games.itarea.org">Jocuri flash</a></li>
    		<li><a href="http://www.ejocuri.us">Jocuri barbie</a></li>
    		<li><a href="http://www.24play.org">Jocuri gratuite</a></li>
    		<li><a href="http://www.e-jocuri.us">Jocuri online</a>
    		</li>
    		</ul>
    
    	</div>
    Code (markup):
    The code to link the php file:

    <?php include("affiliates.php");?>
    Code (markup):

    How can I fix this problem? I tryed putting the full path to the php file and it still didnt work.
     
    WXM Matty, Apr 16, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    go to affiliates.php on line 216, make sure that the ps3.php file exist..
     
    bartolay13, Apr 16, 2008 IP
  3. WXM Matty

    WXM Matty Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    There is no line 216

    The affiliates.php code is:

    <div id="cont">
    
    		
    		<ul>
    		<li>
    		<a href="#" onClick="MyWindow=window.open('http://www.xninelivesx.com/wowgold.htm','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=230,height=108'); return false;">WOW Gold</a> - <i>5% Off</i></li>
    		</ul>
    		<p><i>&nbsp;&nbsp; Online Flash Games</i></p>
    		<ul>
    		<li><a href="http://games.itarea.org">Jocuri flash</a></li>
    		<li><a href="http://www.ejocuri.us">Jocuri barbie</a></li>
    		<li><a href="http://www.24play.org">Jocuri gratuite</a></li>
    		<li><a href="http://www.e-jocuri.us">Jocuri online</a>
    		</li>
    		</ul>
    
    	</div>
    Code (markup):
    Although the page im using it on is not specified. I also want it an all of my webpages in different folders.
     
    WXM Matty, Apr 16, 2008 IP
  4. nicangeli

    nicangeli Peon

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    <?php include("/folder/affiliates.php");?>
    
    Code (markup):
    Does that help, im am no expert and i'm not sure I understand your problem properly.
     
    nicangeli, Apr 16, 2008 IP
  5. KnuTz

    KnuTz Well-Known Member

    Messages:
    169
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #5
    try
     <?php
    include('folder/affiliates.php');
    ?> 
    PHP:
     
    KnuTz, Apr 16, 2008 IP
  6. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #6
    make sure your affiliates.php are in the right directory, including subfolders.
     
    bartolay13, Apr 16, 2008 IP
  7. Ikki

    Ikki Peon

    Messages:
    474
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Php is telling you that that file can't be found. I believe that there's something wrong with your path... or maybe the file doesn't exist. You should check that.
     
    Ikki, Apr 16, 2008 IP
  8. andymayo

    andymayo Guest

    Messages:
    652
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #8
    yea matty, check that:p ill take a look at it later too.
     
    andymayo, Apr 16, 2008 IP
  9. dprundle

    dprundle Peon

    Messages:
    399
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Your afiliates.php doesn't exist in the location you specified.
     
    dprundle, Apr 16, 2008 IP
  10. WXM Matty

    WXM Matty Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    This is still not working, the affiliates.php is in the root directory. And I want the code to be linked inside a php file named PS3.php

    The PS3.php is in a different folder called 'gaming' not the root directory
     
    WXM Matty, Apr 17, 2008 IP
  11. adwads.com

    adwads.com Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    hmm try with whole url

    http://yoursite.com/affiliates.php

    <?php
    include('folder/affiliates.php');
    ?>
    PHP:
     
    adwads.com, Apr 17, 2008 IP
  12. WXM Matty

    WXM Matty Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I already tried that but thanks.

    Is there any reason it works with all files in the main directory but doesnt work with any file in a different folder? Is it because im linking to a different folder and you cant do that?
     
    WXM Matty, Apr 17, 2008 IP
  13. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #13
    Show us: PS3.php -- and tell us the absolute path to the index.php..
     
    exodus, Apr 20, 2008 IP
  14. Xtrm2Matt

    Xtrm2Matt Active Member

    Messages:
    129
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #14
    Put this in PS3.php:

    <?php echo dirname(__FILE__); ?>
    PHP:
    Then in affiliates.php:

    <?php include( "whatever_the_above_says/PS3.php" ); ?>
    PHP:
    Hard-coded include path indeed, but it's the easiest if you can't get things like this working.
     
    Xtrm2Matt, Apr 20, 2008 IP
  15. Trusted Writer

    Trusted Writer Banned

    Messages:
    1,370
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    160
    #15
    I would try this other

    
    <?php 
    include "http://".$_SERVER['HTTP_HOST']."/folder/affiliates.php;"
    ?>
    
    Code (markup):
    $_SERVER['HTTP_HOST']; will always return your full URL address [​IMG]
     
    Trusted Writer, Apr 20, 2008 IP
  16. Cyrus_vtn

    Cyrus_vtn Peon

    Messages:
    102
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #16
    well ya i mean if it's

    - affiliates.php
    --ps3.php

    you'd need to change it to <?php include ("../affiliates.php");?> when you call the file from ps3.php.
     
    Cyrus_vtn, Apr 20, 2008 IP
  17. andymayo

    andymayo Guest

    Messages:
    652
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #17
    [​IMG]

    this is a screen shot of the php code if that helps any one to solve this.
     
    andymayo, Apr 21, 2008 IP
  18. andymayo

    andymayo Guest

    Messages:
    652
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #18
    any one solve this?
     
    andymayo, Jul 17, 2008 IP