Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • My code Not Working On Hosting Server

    • 2
    • 1
    • 2
    • 6
    • 0
    • 0
    • 0
    • 325
    Answer it

    Hi, My code working in my locahost wamp server. But if I uploaded it to my hosting server it's not working. Please give solution. Or reason for this problem. Thanks Here is my code :

    <?php
    session&#95;start();
    if(!isset($&#95;GET['submit']))
    {
    $rand = rand(0,10);
    $&#95;SESSION['result'] = $rand;
    echo $rand;
    echo "<form action='' method=GET><input type='hidden' name='submit' value='true'><input type='submit' value='GET IT'></form>";
    }
    if(isset($&#95;GET['submit']))
    {
    if(isset($&#95;SESSION['result']))
    {
    echo $&#95;SESSION['result'];
    session&#95;destroy();
    }
    else
    {
    echo "result not set in session";
    }
    }
    ?>
    

    If it worked normally it will do following : Prints a random number. After i clicked "GET IT" It will print that number.

 6 Answer(s)

  • Hi, Thank You @narendra.arora and @sukhminder.kaur. Finally Found the Problem. I changed 404 error page as index.php. Chrome is automatically requesting favicon.ico. But it's not in server. Therefore it responded with body of index.php. That is affected session....

  • Hi, If you moved the code from WAMP (windows) to a hosting server (Cpanel) I assume the basic problem that we see in this case is the file permissions. Please set the file permissions to 0644 and then try to execute the page again.

    If it still does not work please look into the error logs and post the messages you get.

    Hope this helps.

  • Hi Sukhminder, session_autostart is off session.save_path is c:\php55\sessiondata

    If i did like this it's working. But it's not working above mentioned code

    aaa.php:

    <?php
    session&#95;start();
    $&#95;SESSION['name']="Puvipavan";
    header(location:bbb.php);
    ?>
    

    bbb.php:

    <?php
    session&#95;start();
    echo $&#95;SESSION['name'];
    ?>
    
  • Hi

    Can you check the session settings in your php.ini files. As you are using sessions, the values need to be defined correctly in php.ini file. You can look for session_autostart which should be set to 0 and also the path where the session variables will be stored. You should have permissions to write to that folder.

  • Hi, Thanks for your answer. I think it's not a permission problem because I'm posting to same page & my other projects are working fine on that server which uses session. It's a windows 2012 server

    Comment
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: