The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$variable inside file_get_contents
#1
Hello!

I have recently started using UserSpice and I think it's awesome so far! I've never experienced working with a framework this uncomplicated. So cred to the developers, keep up te good work Smile

I have run into a slight problem, and I've been looking around on the web and on this forum, and in the documentation, but haven't found exactly what i'm looking for. Being inexperienced with PHP doesn't help either.

So I thought i'd give it a shot asking you guys Smile

Here goes:

I have a page, let's called it mypage.php

On that page, I have included a php file. Let's call it include1.php.

It is reloaded every second using a piece of javascript. Like this:

<pre>
Code:
<div class="View"></div>

<script>
setInterval(function(){
$.ajax({
            url: "include1.php",
            cache: false,
            success: function(html){        
                $(".View").html(html);          

            },
        });
},1000);
</script>
</pre>



That document has a list of other php files included. Let's call one of them include2.php.

It stems out like a tree, but my question is regarding what is suppose to happen inside include2.php.

The code in there looks like this:

<pre>
Code:
<?php
$my_url = 'http://awebsite.com/'.$user->data()->MyOwnColumn.'/other/stuff';

$test_var = file_get_contents($my_url, NULL, NULL, 5, 2);
echo $test_var;

if ($test_var === "Hi") {

echo '
Success!';

}
?>
</pre>



So the idea here is that include2.php will get text from a URL that is different for each user, depending on what is stored in "MyOwnColumn", that I have added to the database. There is only plain text on the URL which file_get_contents will read.

I have tried this:

<pre>
Code:
$my_url = 'http://awebsite.com/'.$user->data()->MyOwnColumn.'/other/stuff';
echo $my_url;
</pre>



And it works fine. I found "$user->data()->MyOwnColumn" in the UserSpice account.php file and tried it. I'm not sure if this is it's correct usage? I only altered the column to fit my own needs.

I have also tried the following, and it works fine with the piece of javascript reloading it:

<pre>
Code:
$test_var = file_get_contents('http://awebsite.com/in/plain/text', NULL, NULL, 5, 2);
echo $test_var;
</pre>



I have also tried this, but WITHOUT javascript, only
Code:
<?php include 'include1.php'; ?>

<pre>
Code:
$test_var = file_get_contents('http://awebsite.com/'.$user->data()->MyOwnColumn.'/other/stuff', NULL, NULL, 5, 2);
echo $test_var;
</pre>



And that works fine.

So the problem here seems to be, that when I use javascript to reload the included php files, it won't accept that I have put $my_url in the url which file_get_contents will "read".

The reason why I am asking here and not stackoverflow for example, is that I am not really sure how to correctly fetch data from the db in userspice. I know there is documentation on that, but I don't want to fetch everything in a table, but only from the logged in user. And that's where my knowledge of PHP limits me.

I hope I haven't been too confusing, but feel free to ask questions if I have Smile

Best regards!
`
  Reply


Messages In This Thread
$variable inside file_get_contents - by MarcE - 03-20-2017, 08:02 AM
$variable inside file_get_contents - by JUG - 03-20-2017, 09:09 AM
$variable inside file_get_contents - by mudmin - 03-20-2017, 11:21 AM
$variable inside file_get_contents - by MarcE - 03-21-2017, 05:12 PM
$variable inside file_get_contents - by JUG - 03-21-2017, 06:56 PM
$variable inside file_get_contents - by MarcE - 03-22-2017, 08:10 AM
$variable inside file_get_contents - by mudmin - 03-23-2017, 09:58 AM
$variable inside file_get_contents - by MarcE - 03-24-2017, 09:16 AM
$variable inside file_get_contents - by dan - 03-24-2017, 10:31 AM
$variable inside file_get_contents - by MarcE - 03-27-2017, 06:54 AM
$variable inside file_get_contents - by mudmin - 03-30-2017, 04:33 PM
$variable inside file_get_contents - by MarcE - 04-13-2017, 01:23 PM
$variable inside file_get_contents - by MarcE - 04-19-2017, 05:13 PM
$variable inside file_get_contents - by mudmin - 04-20-2017, 10:51 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)