Jump to content

rtadams89

Members
  • Posts

    40
  • Joined

  • Last visited

    Never

Posts posted by rtadams89

  1. Hello all. Let me start by saying I have searched for this, but have not found a satisfactory answer. Probably because I am unsure of exactly what to search for.

     

    I have a website with 10+ PHP pages. There are some functions that every page uses, some functions that a few of the pages use, and some functions that only get used on one page. Currently, all of these functions are in a file named "functions.php" which is 40KB in size. As the first line of all my content PHP pages, I have included

    <?require($_SERVER['DOCUMENT_ROOT'].'/includes/functions.php');?>

    to ensure these functions are available on each page.

     

    Is this appropriate? Would it be better to have separate function files which contain "groups" of related functions, and then only include those "groups" that are needed on the particular page? Does including one large function file on every page perform better than including several smaller files on some pages?

  2. I have no idea how to phrase this simply, so here is the long explanation. I wanted to track the number of people who view my ads posted on craigslist. Craigslist won't let you embed PHP, javascript, or any external files in the posts, except for images. SO here is what I did:

     

    I created a file named "hit.php" on my server. In my craigslsit post, i include:

    <img src="http://myserver.com/hit.php?id=1234">

     

    When called, hit.php records the hit in a database and then uses a header(location) to redirect to a transparent gif file. The "id" parameter in the URL is the id of the post. This has to be hard coded into each craigslist post I make.

     

    I would instead like to pull the ID from the post URL automatically. For example, in the post http://phoenix.craigslist.com/sys/1234.html the id would be "1234". Is there a way to do this when the hit.php script is being called from an "<img>" tag?

  3. You don't need the ?name=ryan in the include.

     

    I do. Without it, the include.php page won't have anything to process.

     

    does it really work fine? i haven't tried such feat.

    anyway, why would you do that for? i don't find any good reason for printing a name from another script while passing a parameter inside include() itself.

     

    It doesn't work fine, that's the problem.

    The code I posted is a simplified example of what I am trying to do. In reality, the include.php file actually takes an e-mail address as in put, converts it to hex code, and outputs it in the form of a JavaScript document.write command. This is all so that when a robot views the source code of a page, it won't be able to pick out the mailto links and spam them.

  4. I have a php file named "include.php" which contains the following code:

    <?php
    echo $_GET['name'];
    ?>

     

    If I go to http://myserver.com/include.php?name=ryan I get a page that contains the text "ryan".

     

    I also have another page named "main.php" which has the following code:

    <?php
    echo "The name is: ";
    include ("http://myserver.com/include.php?name=ryan");
    echo ".";
    ?>

     

    I would expect the output of this page to be "The name is ryan.". However, I get nothing.

     

    I'm pretty sure this is because I am using the include() function incorrectly. What function should I use?

  5. I added the following line to my .htaccess file:

    #Custom 404 for non existant .php files work around
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^[0-9a-zA-Z_/.-]+\.php$ http://www.asurfc.com/error.php?code=404

     

    Everything now works as expected. Any reason the plain "errordocument" declaration wasn't working for non existent php files?

  6. Here is the .htaccess I have placed in my root directory:

    CheckSpelling off
    AddType x-mapp-php5 .php
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !www.asurfc.com
    RewriteRule ^.*$     http://www.asurfc.com%{REQUEST_URI} [R]
    
    ErrorDocument 404 http://www.asurfc.com/404.php
    

     

    If a visitor goes to "http://asurfc.com/nowhere.html" or "http://asurfc.com/nowhere/nowhere.php", my custom 404 page gets displayed as expected. But, if a visitor goes to "http://asurfc.com/nowhere.php", my web host's default 404 page gets displayed. It seems my custom 404 page works every time except if the non-existent requested file is a php file in the root directory.

     

    Can someone explain why this is happening?

     

     

    PS: My web host is 1&1. You can see the problem I have for yourself by visiting the URLs I mentioned above.

  7. Thanks for the reply. Unfortunately the referring page can't run PHP. However, your response got me going in the right direction. In the referring page, i used this JavaScript code:

    var str1, str2;
    str1 = location.href;
    str2 = str1.replace ("&", "andandand");
    top.location.href = "http://asurfc.com/forum.php?iframe=" + str2;

     

    That just replaces "&" with "andandand". I used "andandand" to make sure I wouldn't have any problems if the URL already included a single "and".

     

    Then on my forum.php code, I returned the URL with this:

    <?php
    $iframe = str_replace("andandand" , "&" , $_GET['iframe']);
    if ($iframe == "")
    {
    $iframe = "./forum/";
    }
      
    ?>

     

    which just replaces the "andandand" with "&".

     

    Thanks for the help!

  8. I have a page (forum.php) and on this page I have the following code:

     

    <?php
    $iframe = $_GET['iframe'];
    echo $iframe;
      
    ?>

     

    So when I go to forum.php?iframe=http://google.com, the page displays "http://google.com" as expected. The issue is, if I go to forum.php?iframe=http://somesite.com?a=1&b=2, then the forum.php page only displays "http://somesite.com?a=1".

     

    I've also tried forum.php?iframe="http://somesite.com?a=1&b=2", but even with quotes, the $_GET['iframe'] variable gets truncated at the first "&" sign.

     

    How can I get around this?

×
×
  • 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.