Jump to content

PHP Include


Lebofly

Recommended Posts

Hey guys,

I have a PHP file created in the root of the forum directory, basically what I'm trying to do is include a file created by a plugin. but I'm getting a 403 Forbidden error.

This is the Include in question:

include("system/Login/Steam.php");
 

Yes, the directory is exactly like that and the file exists. What is preventing this from working? 

Link to comment
Share on other sites

It really depends on what you want to do. I'm assuming that you are wanting to use the Steam plugin file for the purpose of pulling information from Steam. In this case, you don't need to include Steam.php directly as the IPS suite does everything for you and more!

First of all, you need to call the IPS suite in your PHP file, or else calling that Steam.php file will not work at all.

<?php
//Note that this is at the very top of your PHP file
require_once( 'init.php' );
\IPS\Dispatcher\External::i();

If you're just wanting to get the name of the currently signed in account, you can always use this:

$member = \IPS\Member::load();
echo $member->name;

The "name" part of $member->name reflects your core_members table in the database. You can pull any information from the database in this way! For example, you can use $member->email to get their email address. Going by the plugin that you mentioned, you can obtain their Steam ID by doing this:

//You only need this first line once, but if it's not in your code, add it:
$member = \IPS\Member::load();
//Are they a guest?
if ($member->real_name == "") {
	//Hi guest
	echo "Guest";
} else {
	//Hi member
	//We can pull stuff from Steam!
	$steamid = $member->steamid;
	//Provide your Steam API Key below:
	$steamapi = "";
	$response = \IPS\Http\Url::external("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamapi."&steamids=".$steamid)->request()->get()->decodeJson();
	if ($response) {
		$userData = $response['response']['players'][0];
		echo $userData['personaname']; //Show their Steam name
		//You can also find many different cool things through print_r($userData);
		//For example, $userData['avatarfull'] will give you their Steam avatar url
		echo "<img src=".$userData['avatarfull']." />";
		//Are they logged in on Steam right now?
		$loggedinstate = $userData['personastate'];
		//0 for Offline, 1 for Online, 2 for Busy, 3 for Away, 4 for Snooze, 5 for Looking for Trade, and 6 for Looking for Play
		if ($loggedinstate == 0) {
			//offline
			echo "Offline";
		}
	}
}

If you're wanting to do a full login, IPS already handles this automatically through its authentication. You could just link to the sign in page on your IPS suite. If you want, I can provide the code in which you can create a custom authentication form, but this seems a little bit unnecessary to me when IPS already has done a good job with their login form.

I hope this was helpful! :)

Link to comment
Share on other sites

It was extremely helpful. what I'm essentially trying to do is check if the steamid is in another DB, if it is set that user to a group. I have steam login working and all, so that's good. 

Thanks again. 

 

Trying to do 

$member = \IPS\Member::load();
echo $member->name;

results in "c8e5f31994e237cc918aa97bdb6d406c" and changes upon refresh, any idea why?

Link to comment
Share on other sites

14 hours ago, Lebofly said:

It was extremely helpful. what I'm essentially trying to do is check if the steamid is in another DB, if it is set that user to a group. I have steam login working and all, so that's good. 

Thanks again. 

 

Trying to do 


$member = \IPS\Member::load();
echo $member->name;

results in "c8e5f31994e237cc918aa97bdb6d406c" and changes upon refresh, any idea why?

This happens when you're not logged in. :)

Oh sorry, I didn't see that you said set it to a group. What you can do is check the ACP for the user group ID that you want (I recommend going to the ACP and then going to the group's settings and checking the URL for the ID), and then use this bit of code:

if ($steamid is in $db) { //Of course fill this part out accurately
	$member->member_group_id = 4;
	$member->save();
}

IPS is able to change member data that easily!

Link to comment
Share on other sites

3 hours ago, MDPP said:

This happens when you're not logged in. :)

Oh sorry, I didn't see that you said set it to a group. What you can do is check the ACP for the user group ID that you want (I recommend going to the ACP and then going to the group's settings and checking the URL for the ID), and then use this bit of code:


if ($steamid is in $db) { //Of course fill this part out accurately
	$member->member_group_id = 4;
	$member->save();
}

IPS is able to change member data that easily!

That's the thing I am logged in when I press the button that leads to the PHP file, guessing it has something to do with sessions?

Link to comment
Share on other sites

30 minutes ago, Aiwa said:

It's likely you've got a scope problem... Are you doing this with a plugin and controller?  Or just calling the external file directly?

 

Also, you can't load() an empty value... 


$member = \IPS\Member::load(\IPS\Member::loggedIn()->member_id);

 

Yes, thank you for that Aiwa. It works fine now, although I did it with this:

{{if isset( $_SESSION['logged_in_as_key'] )}}{lang="front_logged_in_as" sprintf="$_SESSION['logged_in_from']['steamid']"} {{endif}} {member="steamid"}

I'll give your way a try as it looks cleaner (Worked!)

Link to comment
Share on other sites

You can also simplify it to:

$member = \IPS\Member::loggedIn();

It does the same thing as:

$member = \IPS\Member::load(\IPS\Member::loggedIn()->member_id);

I kind of assumed that people knew how to use the load() function, but I guess not. :lol:

Link to comment
Share on other sites

27 minutes ago, MDPP said:

You can also simplify it to:


$member = \IPS\Member::loggedIn();

It does the same thing as:


$member = \IPS\Member::load(\IPS\Member::loggedIn()->member_id);

I kind of assumed that people knew how to use the load() function, but I guess not. :lol:

Indeed it does. That's what I get for replying when I'm distracted. 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...