简体   繁体   中英

php auto add \ to href

I have this problem with my webpage when I hit the "edit" button, all href adds "\\" to the links.

It would keep adding on as the button is hit.

I tested it on xampp-localhost but everything is normal - it only happens when it is hosted.

I am new to php; I tried to Google it, but don't know where to look at, the code below is my edit button's action:

if ($img_path!=NULL){
        //delete old image  
        $sql="SELECT image FROM entry WHERE url =?";
        $stm = $db->prepare($sql);
        $stm->execute(array($_POST['url']));
        $e = $stm->fetch();
        if($e['image']!="/simple_blog/img/no_img.jpg"){
            unlink($_SERVER['DOCUMENT_ROOT'].$e['image']);
        }

        //update new contain
        $sql = "UPDATE entry SET entry=?, title=?, image=?, url=? WHERE url = ?";
        $stmt = $db->prepare($sql);
        $stmt->execute(array($_POST['wall'],$_POST['title'],$img_path,$url,$_POST['url']));
    } elseif ($img_path==NULL){
        $sql = "UPDATE entry SET entry=?, title=?,url=? WHERE url = ?";
        $stmt = $db->prepare($sql);
        $stmt->execute(array($_POST['wall'],$_POST['title'],$url,$_POST['url']));
    }
    $stmt->closeCursor();
    header('Location: /simple_blog/blog/'.$_POST['url']);

Sorry if I have not explained well about the problem, here is the page you can have a look at, I put the problem in first entry.

Link To Blog

user: testUser

pass: 12345

Thank you very much for any help!

Thank you PleaseStand for the suggestion link :D it's Magic quotes

Just need to add the following code and everything would work fine:

<?php
if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process)) {
foreach ($val as $k => $v) {
    unset($process[$key][$k]);
    if (is_array($v)) {
        $process[$key][stripslashes($k)] = $v;
        $process[] = &$process[$key][stripslashes($k)];
    } else {
        $process[$key][stripslashes($k)] = stripslashes($v);
    }
}
}
unset($process);
}?>

sql query is sensitive to question Mark for that put / before it.

for solve this problem you can use This code for read from DB

function dbdecode($string){
    $string=str_replace('\\',"\\",$string);
    $string=str_replace("\'","'",$string);
    $string=str_replace("\`","`",$string);
    $string=str_replace('\"','"',$string);
    $string=str_replace('\*','*',$string);
    return $string;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM