1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Simple PHP Problem. URL Reading.

Discussion in 'HTML, Graphics & Programming' started by SpicyDuck, 14 Jan 2006.

  1. SpicyDuck

    Soldato

    Joined: 10 Dec 2003

    Posts: 6,349

    I'm trying to get PHP to read the current URL to check for a word, in order to carry out a task.

    Here is what I have so far, but it doesn't work.

    Code:
    <?php
    
    	if ($_GET['form']) {
    		
    		include "includes/javascript.php";
    		
    		}
    
    ?>
    
    I want PHP to look in the url for the word "form" and, if it exists, include that file. Otherwise, don't.

    I'm doing this so that the JavaScript is loaded only when it's needed and not on every page.

    Any help?

    Thanks,

    Phil.
     
  2. Inquisitor

    Capodecina

    Joined: 12 Apr 2004

    Posts: 11,788

    Location: Birmingham

    Just use substr_count():
    Code:
    <?php
    
    	if (substr_count($_SERVER['REQUEST_URI'], 'form') > 0) {
    		include "includes/javascript.php";
    	}
    
    ?>
    
    :)
     
  3. Chaapa'ai

    Hitman

    Joined: 28 May 2004

    Posts: 525

    Location: The US of A

    PHP, what a silly language. I put it "up" there with cold fusion. Not harping on you mate just the language. I prefer java or csharp.

    Inquistor: That is a killer banner in your sig. Very nice.
     
  4. Inquisitor

    Capodecina

    Joined: 12 Apr 2004

    Posts: 11,788

    Location: Birmingham

    Uh, was that really necessary in this thread?

    Which one? It's on a rota :p
     
  5. Beansprout

    Man of Honour

    Joined: 31 Jan 2004

    Posts: 16,316

    Location: Plymouth

    Wtf? Go away ;)