donglei7152 2018-08-24 18:42
浏览 103
已采纳

如何在php中检查控制台上的变量值?

I want to check variable value in console I have tried everything but I am not getting the value in console.

 // Here I want to check $cart_id value before if Statement
 echo "Cart Id Before If Statement:" . $cart_id;

The above line is not working because the page add_cart skip and I am not able to check the value like I usually do. So I need to check this value on cosole like

console.log($cart_id);

But when I check console the console is showing empty. But When I click on network then I open preserve log then my file add_cart.php is showing and I am able to see cookie as well as form data but I have no idea how to check $cart_id in console or in any way.

I also tried in my helper.php class

function debug_to_console( $data ) {
$output = $data;
if ( is_array( $output ) )
    $output = implode( ',', $output);

echo "<script>console.log( 'Debug Objects: " . $output . "' ); 
</script>";
} 

And call it before my if statement

debug_to_console($cart_id); 

But above also not working for me. I am not able to check the result of $cart_id before if statement. Nothing show on console.

if ($cart_id != '') {

}else{

$items_json = json_encode($item);
$cart_expire = date("Y-m-d H:i:s",strtotime("+30 days"));
$db->query("INSERT INTO cart (items,expire_date) VALUES ('{$items_json}','{$cart_expire}') ");
$cart_id = $db->insert_id;
setcookie(CART_COOKIE,$cart_id,CART_COOKIE_EXPIRE,'/',$domain,false);
}

Your valuable suggestion would be welcome.

  • 写回答

1条回答 默认 最新

  • douzheng9221 2018-08-24 19:53
    关注

    If its only to debug your application code, you can simply add a dump in your php code before if statement, like -

    var_dump($cart_id);die();
    
    if ($cart_id != '') {...}
    

    As, the call is ajax, you will have an http call generated in network tab. Opening that select Response. There you will be able to see the value of $cart_id. That can be found as shown in below image -

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用lstm来预测股票价格
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上