SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Oct 2002
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why does my local PHP work different to online?

    Hey,

    Ok locally I am running PHP 4.2.3 to test my scripts.

    The server I am uploading to is running 4.3.10.

    Now I have an email script that needs to strip slashes added to the text box content. But as I add it into the database, I add slashes beforehand...

    Anyway here is the code:

    Code:
     // insert record into database
     $sql = "INSERT INTO tbl_mailing_sent SET 
     fld_id='',
     fld_subject='$subject',
     fld_text='$text',
     fld_date = CURDATE(), 
     fld_time = CURTIME(),
     fld_category='$category'";
     $result2 = mysql_query($sql) or die 
     //("Error in query: $sql. " .mysql_error())
     ("There has been an error with your request, please try again later.")
     ;
     
     //mail headers
     $headers  = "From: " .$mailingname. " <" .$mailingemail. ">\r\n";
     $headers .= "Reply-To: " .$mailingname. " <" .$mailingemail. ">\r\n";
     $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
     $headers .= "X-Priority: 3\r\n";
     $headers .= "X-MSMail-Priority: Normal\r\n";
     $headers .= "X-Mailer: " .$mailingname. "\r\n";
     
     // format text
     $mail_text = func_links($text);
     $text_formatted = nl2br($mail_text);
     $text_formatted = stripslashes($text_formatted);
     
     $mail_message = "<p>Hi ". $row['fld_name'] .",</p>
     				  <p>". $text_formatted ."</p>
     				  <p>". $html_signature ."</p>";
     				  
     @mail($row['fld_email'], $subject, $mail_message, $headers);
    This is the function code for func_links:

    Code:
     // convert links without <a> tags into links
     function func_links($text)
     {
     
     	// Match things beginning with http:// (or other protocols)
     	$NotAnchor = '(?<!"|href=|href\s=\s|href=\s|href\s=)';
     	$Protocol = '(http|ftp|https):\/\/';
     	$Domain = '[\w]+(.[\w]+)';
     	$Subdir = '([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?';
     	$Expr = '/' . $NotAnchor . $Protocol . $Domain . $Subdir . '/i';
     	
     	$Result = preg_replace( $Expr, "<a href=\"$0\" title=\"$0\" target=\"_blank\">$0</a>", $text );
     	
     	// Match things beginning with www.
     	$NotAnchor = '(?<!"|href=|href\s=\s|href=\s|href\s=)';
     	$NotHTTP = '(?<!:\/\/)';
     	$Domain = 'www(.[\w]+)';
     	$Subdir = '([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?';
     	$Expr = '/' . $NotAnchor . $NotHTTP . $Domain . $Subdir . '/i';
     	
     	return preg_replace( $Expr, "<a href=\"http://$0\" title=\"http://$0\" target=\"_blank\">$0</a>", $Result );
     
     }
    Now locally this works fine, I don't get any slashes in the way, but if I send online I get the slashes still - it makes no sense, the files are EXACTLY the same - I can only think it is due to the difference in PHP.

    Is what I am doing not viable in PHP 4.3.10 but is ok in 4.2.3???

    Any help would be great.

    Cheers,
    Chris

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    texas
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    look into get_magic_quotes_gpc(). my guess is that this function will return different results on your local system and on the server. depending on how your php.ini is set up, php might automatically addslashes to all incoming formdata. if get_magic_quotes_gpc() returns 1, then php is adding the slashes. if it returns 0, then it is not adding the slashes.

    you can also check to see if get_magic_quotes_gpc is enabled by calling phpinfo() on the server and local and comparing the output to see if magic_quotes_gpc is enabled on either/both of them.
    free online calendar: http://inversiondesigns.com
    includes multiple calendars/users/groups, task manager,
    email and sms reminders, permissions (sharing), etc.


Bookmarks

Posting Permissions

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