-1

i'm trying to pass variables from userInfo.php to flips.php but for some reason the variables don't go through. When i do echo "hello"; in the userInfo.php then i do see 'hello' in the website but when i do:

if (isset($variable)) {
 echo "it is set!";
} else {
 echo "nope!";
}

Then it returns 'nope!' even though i have set $variable in userInfo.php.

userInfo.php:

<?php
$variable = "hello everyone!";
echo "hello!";

flips.php:

<?php
include ('userInfo.php');

if (isset($variable)) {
 echo "it is set!";
} else {
 echo "nope!";
}

Website output: hello!nope!

what am i doing wrong so flips.php doesn't see $variable?


Edit (the real code from my website):

flips.php:

include ('../csgodonut/application/views/steamauth/userInfo.php');
if (isset($steamprofile["personaname"])) {
  echo "yes!";
} else {
  echo "nope..";
}

userInfo.php:

$steamprofile['personaname'] = "Smokey";
echo "test";

Website: www.csgodonut.com (you have to login to steam in order to see the hello! nope..) flips.php location: csgodonut/application/views/gebruiker/home/flips.php userInfo.php location: csgodonut/application/views/steamauth/userInfo.php

33
  • 1
    impossible based on what you have provided, make sure to show your full code Commented Jan 14, 2018 at 22:01
  • this iseverything, only the $variable is called $steamprofile in my code, other then that it is exactly the same Commented Jan 14, 2018 at 22:03
  • so no <?php ? seems unlikley Commented Jan 14, 2018 at 22:04
  • i meant the code is the same, <?php is in my code Commented Jan 14, 2018 at 22:05
  • 1
    Have you explicitly set the include path anywhere? You ought to check the include path using get_include_path() &/or set with set_include_path() - maybe also check in flips.php what files have been included with var_dump(get_included_files()); ~ or try with require to see any errors it may throw Commented Jan 14, 2018 at 22:18

2 Answers 2

1

File system

<path-to-views-dir>/steamauth/userInfo.php
<path-to-views-dir>/gebruiker/home/flips.php
<path-to-views-dir>/gebruiker/home/home.php

userInfo.php

<?php

$variable = "Hello everyone, I am the coolest variable!";

echo 'Hello from userInfo.php!<br/>';

flips.php

<?php

include __DIR__ . '/../../steamauth/userInfo.php';

if (isset($variable)) {
    echo 'Helo from flips.php. The variable is set.<br/>';
} else {
    echo 'Helo from flips.php. The variable is NOT set.<br/>';
}

home.php

<?php

include __DIR__ . '/flips.php';

error_reporting(E_ALL);
ini_set('display_errors', 1);

if (isset($variable)) {
    echo 'Hello from home.php. The variable is set.<br/>';
} else {
    echo 'Hello from home.php. The variable is NOT set.<br/>';
}

...or home.php (fetching flips.php content through ajax)

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes" />
        <meta charset="UTF-8" />
        <!-- The above 3 meta tags must come first in the head -->

        <title>Demo</title>
        <script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>

        <script type="text/javascript">
            $(document).ready(function () {
                $('#testButton').click(function (event) {
                    alert('testButton clicked!');

                    $.ajax({
                        method: 'post',
                        dataType: 'html',
                        url: 'flips.php',
                        data: {},
                        success: function (response, textStatus, jqXHR) {
                            $('#results').html(response);
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            $('#results').html(textStatus + '<br />' + errorThrown);
                        },
                        cmplete: function (jqXHR, textStatus) {
                            //...
                        }
                    });

                });
            });
        </script>

        <style type="text/css">
            body {
                padding: 30px;
            }

            button {
                padding: 5px 10px;
                background-color: #8daf15;
                color: #fff;
                border: none;
            }
        </style>
    </head>
    <body>

        <button type="button" id="testButton" name="testButton">
            Fetch some data
        </button>

        <br/><br/>

        <div id="results">
            Here comes the response data from the ajax request...
        </div>

    </body>
</html>

To do

In browser, access the home.php page.

Sign up to request clarification or add additional context in comments.

3 Comments

@Smokey Well, there is something which doesn't fit... It would be very helpful if you would give us the whole codes. Otherwise I don't think that someone of us could help you. I might be wrong though :-)
I just got it by changing the url from the $.get to a function in my controller, and then loading flips.php with $data (in which are all the variables from userInfo.php), thanks for all your help anyway!
@Smokey You are welcome. Good to know that it's working now.
0

I just got it to work by changing the url of the $.get to a function in my controller. Then in that function i loaded the flips.php and send $data (an array with all variables from userInfo.php) with it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.