开发者

php include not working

开发者 https://www.devze.com 2023-02-15 06:32 出处:网络
I’ve got a PHP file with a switch case to include different files depending on a variable $view. This was working perfectly when I was running this on WAMP server on my local machine.

I’ve got a PHP file with a switch case to include different files depending on a variable $view.

This was working perfectly when I was running this on WAMP server on my local machine. But now I have uploaded to a web server and the include functions have just stopped working. Nothing is getting included.

switch($view)
    {
    case 'AddToCart':
        echo 'adding to cart';
        if($_POST['qty']>0)
        {
            if(!isset($_SESSION['cart'][$_POST['id']]))
            {
                $_SESSION['cart'][$_POST['id']]=$_POST['qty'];
            }
            else
            {
                $_SESSION['cart'][$_POST['id']]+= $_POST['qty'];
            }   
        }
        header('Location:index.php');
        break;

    case 'UpdateCart':
        echo 'updating cart...';
        if(isset($_SESSION['cart'][$_POST['id']]))
        {
            if($_POST['updateqty']>0)
                $_SESSION['cart'][$_POST['id']]=$_POST['updateqty'];
            else
                unset($_SESSION['cart'][$_POST['id']]);
        }   
        header('Location:index.php?view=ViewCart');
        break;

    case 'ViewCart':
        echo 'This is the fu开发者_JS百科ll feature cart.';
        include('models\cart.php');
        include('models\fullcart.php');
        break;

    case 'Checkout':
        echo 'reached checkout';
        include('models\finalcart.php');

        break;

    case 'ClearCart':
        echo 'Clear cart reached';
        $_SESSION['cart']=array();
        $_SESSION['total_items']=0;
        $_SESSION['total_price']=0;
        header('Location:index.php');
        break;

    case 'RemoveItem':
        echo 'Removing item '.$_POST['id'].'<br><br>';
        unset($_SESSION['cart'][$_POST['id']]);
        header('Location:index.php?view=ViewCart');
        break;

    default:
        echo 'index page...lalalalalal...<br>';
        include('models\cart.php');
        include('models\catalog.php');
    }

I did phpinfo on the webserver and found it’s running PHP version 5.2.17.

Whats going wrong?


Hope you know not to echo/print anything before you send headers. And can you check what your server os is, I use /, not \, in file paths


I guess your web server is running linux or another unix-like system, which uses forward slashes instead of backslashes as directory seperator. So you have to replace the slashes in the include paths:

include('models\fullcart.php');

becomes

include('models/fullcart.php');

and so on...


check the included file permissions i think they should be 755 or 775

0

精彩评论

暂无评论...
验证码 换一张
取 消