Charles Lentz
Charles Lentz

Reputation: 63

Script works with PHP 5.4.16, but not PHP 5.3.3... where is the faulty code?

I'm a beginner in php, and... I was just trying to create this... dynamic indexing/document_display script using php... What I was trying to do isn't really important to the question, however. The thing is... my script does exactly what I want it to do, when hosted on a WAMP server with php 5.4.16... but when uploaded to a LAMP server with php 5.3.3, I get the error

Fatal error: Can't use function return value in write context in /users/clentz/testphpindex.php on line 34

I need it to work on this lamp server.

Can anyone tell me what about the following code is causing errors with the php 5.3.3 interpreter?

<?php

$courses_directory = "./Courses";
$courses_array = scandir($courses_directory);

if (empty($_SERVER['QUERY_STRING']))
{
    include 'Misc/common_components/headers/index_header.html';

    echo "\r\n\t<h1>Enrolled Courses</h1>";

    for ($uwmi_loop_var = 2; isset($courses_array[$uwmi_loop_var]); $uwmi_loop_var++)
    {
        if ($uwmi_loop_var == 2)
        {
            echo "\r\n\t<ul>";
        }

        if (isset($courses_array[$uwmi_loop_var]))
        {
            echo "\r\n\t\t<li>" . '<a href="?' . $courses_array[$uwmi_loop_var] . '">' . $courses_array[$uwmi_loop_var] . '</a></li>';
        }

        if (!isset($courses_array[($uwmi_loop_var + 1)]))
        {
            echo "\r\n\t</ul>\r\n";
        }
    }

    include 'Misc/common_components/footer.html';
}

else if (!empty($_SERVER['QUERY_STRING']))
{
    for ($uwmi_loop_var = 2; isset($courses_array[$uwmi_loop_var]); $uwmi_loop_var++)
    {
        if (explode("&",$_SERVER['QUERY_STRING'])[0] == rawurlencode($courses_array[$uwmi_loop_var]))
        {
            include "./Courses/" . $courses_array[$uwmi_loop_var] . "/index.php";
        }
    }
}



?>

If it helps, you can see the code in a little more visually appealing format at: pic of the code in a visually appealing format

Upvotes: 0

Views: 1028

Answers (1)

som
som

Reputation: 4656

Problem :

explode("&",$_SERVER['QUERY_STRING'])[0] 

In PHP 5.3.* version does not support this type of code.

You can do like this for 5.3.* version

$query_string = $_SERVER['QUERY_STRING'];
$arr = explode("&",$query_string);
if ($arr[0] == rawurlencode($courses_array[$uwmi_loop_var]))
{
   include "./Courses/" . $courses_array[$uwmi_loop_var] . "/index.php";
}

Upvotes: 5

Related Questions