I have a PHP file, TableUpdates.php, that I am trying to add a menu to. I have 2 different menus based on who is logged in. I have a MenuCheck.aspx file that determines who is logged in and then include
the correct Menu.php file. However, I can not get this to work. Here's the relevant part of TableUpdates.php:
<head>
<meta charset="utf-8" />
<title>Table Updates</title>
<link rel="StyleSheet" href="StyleSheet.css" type="text/css">
</head>
<body>
<!-- #include file="MenuCheck.aspx"-->
I've also tried switching out the <!-- #include file="MenuCheck.aspx"-->
with:
<script type="text/javascript">
<% if (User.Identity.Name == @"CORP\mmm976") {%>
<!-- #include file="AdminMenu.php"-->
<% } else if (User.Identity.Name == @"CORP\ibb601"){%>
<!-- #include file="AdminMenu.php"-->
<% } else { %>
<!-- #include file="Menu.php"-->
<% } %>
</script>
Neither works. The MenuCheck.aspx is this:
<%@ Page Language="C#" %>
<% if (User.Identity.Name == @"CORP\mmm976") {%>
<!-- #include file="AdminMenu.php"-->
<% } else if (User.Identity.Name == @"CORP\ibb601"){%>
<!-- #include file="AdminMenu.php"-->
<% } else { %>
<!-- #include file="Menu.php"-->
<% } %>
What am I doing wrong that this does not work?
I have ended up creating a PHP work around. Since I'm trying to get the authenticated user and base the menu on that I had my server admin turn off anonymous authentication so that the php $_SERVER['AUTH_USER']
would have the local user and not a blank. Then I added this to the php files in the body of the HTML for the menus:
<?php
if ($_SERVER['AUTH_USER'] == 'CORP\mmm976'){
include('AdminMenu.php');
}elseif ($_SERVER['AUTH_USER'] == 'CORP\ibb601'){
include('AdminMenu.php');
}else {
include('Menu.php');
}
?>
I still have the <!-- #include file="MenuCheck.aspx"-->
in the body of the aspx files.
So, although this doesn't actually call the aspx file and get the results in my php files, I still end up with the result that I wanted => the admins have access to the admin reports, everyone else has access to only the reports that they need.
It's impossible to use two different languages in one script. You can make ASP script on ASP hosting and make API to authenticate your users from PHP script. Or just do from php:
file_get_contents('https://yourserver.com/asp-auth.php?login=xxx&pass=xxx');
ASP script must return you correct data you can work with.
You can't include PHP code to ASP script and can't include ASP code to PHP script.
But both your scripts may work at one hosting, just create web-server rules to correct handling .php and .asp.
It is possible if the ASPX Page have methods like [WebMethod] on the code behind like this
[WebMethod]
public string getHello(string name)
{
return "Hello " + name;
}