SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Provo, UT
    1 Post(s)
    0 Thread(s)

    Call to undefined function formatURL()

    Can someone help me understand why I would get this error sporadically? My users get emails from my site that contain new testimonials. Some are reporting that they can successfully click on the first link, which uses the following format:

    It prompts them to login, and then they are redirected to the testimonial. Then they try to click on the 2nd link that came in the email. Sometimes it successfully takes them straight to the new testimonial, without having to login, while other times they get an empty white page. Looking in the error_log it states, Call to undefined function formatURL(). So why would my call to this function work most times but sometimes not? Any help would be appreciated!

    $tID    = $_REQUEST['tID'];      // Testimonial ID
    $sID    = $_REQUEST['sID'];      // Search ID
    // Only process this if we have one of these variables
    if ($tID || $sID) {
        // When trying to view a regular testimonial
        if ($tID) {
            $_SESSION[tIDrouter] = $tID;
            $loginNeeded = "No";    
        // When trying to view a new testimonial match
        if ($sID) {
            $_SESSION[referSource] = "Search Match";
            if (strstr($_SESSION[requestedPage], "stop.php")) {
                $_SESSION[stopSearch] = $sID;
            } else {
                $_SESSION[sIDrouter] = $sID;
                $_SESSION[loginNeededDebug] = "Yes";
                $loginNeeded = "Yes";
        // Are they already logged in and trying to view multiple match alerts in a row?
        if ($_SESSION['uID']) {
            $_SESSION[loginNeededDebug] = "No";
            $loginNeeded = "No";
        // Code for converting the article title
        if (!$_SESSION[entryPoint]) {
            function formatURL( $title, $separator = '-' )
                $accents_regex = '~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i';
                $special_cases = array( '&' => 'and');
                $title = str_replace("'", "", "$title");   
                $title = mb_strtolower( trim( $title ), 'UTF-8' );
                $title = str_replace( array_keys($special_cases), array_values( $special_cases), $title );
                $title = preg_replace( '/[!?,.+]+/', '', $title );
                $title = preg_replace( $accents_regex, '$1', htmlentities( $title, ENT_QUOTES, 'UTF-8' ) );
                $title = preg_replace("/[^a-z0-9]/u", "$separator", $title);
                $title = preg_replace("/[$separator]+/u", "$separator", $title);
                return $title;
        // Create the URL that uses the new longer format
        if ($tID) {
            $findTitle = "SELECT title from testimonies where tID = '$tID'";
            $result = mysql_query ($findTitle) OR die(mysql_error());
            if ($row = mysql_fetch_array($result)) {
                $title = $row["title"];    
                $title = stripslashes($title);
                $reformattedTitle = formatURL($title);
                $destinationURL = "$tID/$reformattedTitle";
                $_SESSION['requestedPage'] = $destinationURL;        
                if ($loginNeeded == "No") {
                    Header( "HTTP/1.1 301 Moved Permanently" );
                        Header( "Location: $destinationURL" );
            } else {
                print ("<p>Sorry, this testimonial could not be located in the database</p>");
    } // End if ($tID || $sID)
    // Removed additional login code if $loginNeeded == "Yes"
    Last edited by Force Flow; Oct 23, 2012 at 18:56. Reason: added code tags
    Convert your dollars into silver coins.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    France, deep rural.
    17 Post(s)
    1 Thread(s)
    formatURL is not available to this entire script.

    I have not logically followed all your conditions, but by moving that function to "stand alone" at say the top of the script, you would make it available to all the code inside the various conditions, which would answer your question though may not fix your problem.
    PHP Code:
    $tID    $_REQUEST['tID'];      // Testimonial ID
    $sID    $_REQUEST['sID'];      // Search ID

    function formatURL(){

    // declare it here


    // now get on with your logic 


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts