Magic Quotes and Strip Slashes: What am I doing wrong?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Magic Quotes and Strip Slashes: What am I doing wrong?

Post by eabigelow »

Hi--
Last edited by eabigelow on Wed Oct 21, 2009 4:55 pm, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by requinix »

Here is the code from the add.phtml file:

$filename ="msg.dat";
$file= fopen($filename,'a');
fputs($file, "$message1 - $pseudo1 - $pseudo2 - $pseudo3\n");
fclose($file);

?>
Is that all of the code?
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by eabigelow »

Hi, many thanks for replying!

Yes, this is all the code for the add.phtml file.
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by eabigelow »

Whoops! Except for the <?php at the beginning!

Sorry!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by requinix »

register_globals and magic_quotes... wonderful...

Code: Select all

<?php
 
function unmagicquotes($string) {
    return function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()
        ? stripslashes($string)
        : $string;
}
 
if (isset($_POST["message1"], $_POST["pseudo1"], $_POST["pseudo2"], $_POST["pseudo3"])) {
    $message1 = unmagicquotes($_POST["message1"]);
    $pseudo1 = unmagicquotes($_POST["pseudo1"]);
    $psuedo2 = unmagicquotes($_POST["pseudo2"]);
    $pseudo3 = unmagicquotes($_POST["pseudo3"]);
 
    $filename ="msg.dat";
    $file= fopen($filename,'a');
    fputs($file, "$message1 - $pseudo1 - $pseudo2 - $pseudo3\n");
    fclose($file);
}
 
?>
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by eabigelow »

Wow! I will try this right away. Many, many thanks (I am keeping my fingers crossed)!
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by eabigelow »

Well, no go on this one so far. I cut and pasted your code into the add.phtml page and uploaded that, but nothing is showing.

I checked to make sure, and here is what I have in my www folder:

php_flag magic_quotes_gpc on

So it appears magic quotes is on. Also, my sever is running PHP 5.XX

Should I have the .htaccess file in the same folder as the add.phtml file?
Last edited by eabigelow on Tue Oct 13, 2009 11:27 pm, edited 1 time in total.
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by eabigelow »

Actually, now the inputted text is not showing on the msg.dat page at all... CHMODing file now...
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by eabigelow »

No text is saving into the msg.dat file at all... CHMOD of add.phtml file at 777. Also tested with original file, and that works (at least for sending the text into the msg.dat file)...
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by requinix »

What's add.phtml now? There's a parse error in it.
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by eabigelow »

Hi--

Sorry for the delay in responding.

Here is the current code in the add.phtml file:

<?php

function unmagicquotes($string) {
return function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()
? stripslashes($string)
: $string;
}

if (isset($_POST["message1"], $_POST["pseudo1"], $_POST["pseudo2"], $_POST["pseudo3"])) {
$message1 = unmagicquotes($_POST["message1"]);
$pseudo1 = unmagicquotes($_POST["pseudo1"]);
$psuedo2 = unmagicquotes($_POST["pseudo2"]);
$pseudo3 = unmagicquotes($_POST["pseudo3"]);

$filename ="msg.dat";
$file= fopen($filename,'a');
fputs($file, "$message1 - $pseudo1 - $pseudo2 - $pseudo3\n");
fclose($file);
}

?>

Does this help?

Many thanks!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by requinix »

I still don't see it.

Change the <?php to be just ?php. This will mean the page won't work and will display as HTML instead, but it'll give a clearer picture as to what exactly is in the file.
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by eabigelow »

Hi--
hold on... working on this...
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by eabigelow »

Ok--

Some good news!

With your script (as follows) the slashes are stripped from the first two text items, but not the last two (pseudo2, pseudo3). Added: Just tried again--this time, it worked for the first two, and the last, but not the third (pseudo2).

Here's the current add.phtml code:

Code: Select all

<?php
 
 function unmagicquotes($string) {
     return function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()
         ? stripslashes($string)
         : $string;
}
 
if (isset($_POST["message1"], $_POST["pseudo1"], $_POST["pseudo2"], $_POST["pseudo3"])) {
     $message1 = unmagicquotes($_POST["message1"]);
     $pseudo1 = unmagicquotes($_POST["pseudo1"]);
     $psuedo2 = unmagicquotes($_POST["pseudo2"]);
     $pseudo3 = unmagicquotes($_POST["pseudo3"]);
  
     $filename ="msg.dat";
    $file= fopen($filename,'a');
     fputs($file, "$message1 - $pseudo1 - $pseudo2 - $pseudo3\n");
     fclose($file);
 }
  
 ?>
I thank you for this good first step! Is there any reason why we may be missing some of the text items?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Magic Quotes and Strip Slashes: What am I doing wrong?

Post by jackpf »

Why not just turn of magic quotes? :/
Post Reply