I have PHP application that contain three small applications. Each application have own users and they are unique for all system. I have problem with session management. When one user is logged in server.com/app1 and write server.com/app2 second application log in automaticaly with this user. But this user hasn't any rights on this application. In login page I do this:
$status = $user->status;
if($status != 4) {
$auth_key = session_encrypt($userdata, $passdata);
$SQL = "UPDATE customer SET auth_key = '$auth_key'
WHERE username = '$userdata' ";
$auth_query = mysql_db_query($db, $SQL);
setcookie("auth_key", $auth_key, time() + 60 * 60 * 24 * 7, "/app1", "server.com", false, true);
// Assign variables to session
session_regenerate_id(true);
$session_id = $user->id;
$session_username = $userdata;
$_SESSION['cid'] = $session_id;
$_SESSION['username'] = $session_username;
$_SESSION['status'] = $status;
$_SESSION['user_lastactive'] = time();
header("Location: index.php");
exit;
}
But this doesn't work. Can someone help me how to repair my sessions. Thanks :)
If I'm reading your question correctly, your problem is that your three apps are independent but are hosted on the same server/use the same php instance. This results in their using the same php session, and the latter gets filled up with inappropriate garbage.
You've several potential solutions:
The first and easiest is to prefix your sessions in the way or another, i.e. use $_SESSION['app1']['param'] or $_SESSION['app1_param'] rather than $_SESSION['param'].
Another, if you've php installed as cgi rather than as an Apache module, is to configure each individual apps' php.ini in such a way that they're no longer sharing their session_id (i.e. configure the session cookie name and/or path) nor storing the session data in the same location (which is somewhere in /tmp if I recall correctly).
If you would like your sessions to be handled independently by each app then it might be easier to just set the unique sessionid for each app in the cookie.
setcookie("auth_key", $auth_key, time() + 60 * 60 * 24 * 7, "/app1", "server.com", false, true);
setcookie("auth_key", $auth_key, time() + 60 * 60 * 24 * 7, "/app2", "server.com", false, true);
setcookie("auth_key", $auth_key, time() + 60 * 60 * 24 * 7, "/app3", "server.com", false, true);
Related
Embarcadero C++ Builder 11.2 Architect.
I trying to access the Multi-Tenant information in my RAD Server programmatically. Access is not provided via EMSInternalAPI to get at that information, so I tried the following:
The .dfm file, localhost is the remote server running IIS and Rad Server:
object TenantModuleResource: TTenantModuleResource
Height = 258
Width = 441
object qryTenants: TFDQuery
Connection = TenantConection
Left = 72
Top = 40
end
object FDStanStorageJSONLink: TFDStanStorageJSONLink
Left = 272
Top = 128
end
object FDPhysIBDriverLink: TFDPhysIBDriverLink
Left = 272
Top = 48
end
object TenantConection: TFDConnection
Params.Strings = (
'Server=localhost'
'User_Name=sysdba'
'Password=masterkey'
'Database=C:\Data\emsserver.ib'
'InstanceName=gds_db'
'Port=3050'
'DriverID=IB')
Left = 72
Top = 128
end
end
The code:
void TTenantModuleResource::Get(TEndpointContext* AContext, TEndpointRequest* ARequest, TEndpointResponse* AResponse)
{
std::unique_ptr<TMemoryStream> oStr(new TMemoryStream());
qryTenants->Close();
qryTenants->SQL->Text = "SELECT tenantid, tenantname FROM tenants";
qryTenants->Open();
qryTenants->SaveToStream(oStr.get(), TFDStorageFormat::sfJSON);
AResponse->Body->SetStream(oStr.release(), "application/json", true);
}
static void Register()
{
std::unique_ptr<TEMSResourceAttributes> attributes(new TEMSResourceAttributes());
attributes->ResourceName = "tenants";
RegisterResource(__typeinfo(TTenantModuleResource), attributes.release());
}
and ended getting a log error of unknown "...Win32 error 10060" which is a timeout from what I can tell. I've seen where the Interbase docs suggest that there is no client license when that error is thrown.
I have the RAD Server Site license, but not the client license, however I would like to have the ability to work with the tenant records without using the Multi-Tenant Console app.
My questions is does anyone know of a way to programmatically get to the Tenant data in the emserver.ib database?
I want to change headers value every time when user injected in Gatling. because I have an error in my code when code is running. error is " Signature expired: 20200124T170359Z is now earlier than 20200124T170552Z (20200124T172052Z - 15 min. ".
My code is
val signer: AwsSigner = AwsSigner(AwsCredentialsProviderWithSession, region, Service, clock)
val signedHeaders = signer.getSignedHeaders(Uri, PostMethod, queryParams, headers, emptyPayload)
val scen =scenario("Home page").repeat(100) {
.exec(
http("Custom headers")
.get("Url"+"?Action=SendMessage&MessageBody=" + queryEnc)
.headers(signedHeaders)
setUp(
sendLoadToAws.scen.inject(rampUsersPerSec(10) to 15 during (60))
)
You need use feed, there is documentation for more informations https://gatling.io/docs/current/session/feeder/ .
So, the first create this feed
val signedHeaders = {
val signedHeaders = signer.getSignedHeaders(Uri, PostMethod, queryParams, headers, emptyPayload)
Iterator.continually(Map(
"header_1" -> signedHeaders.header_1,
"header_2" -> signedHeaders.header_2
}
Now need add feed for your scenario
.feed(signedHeaders)
.exec(
http("Custom headers")
.get("url"+"?Action=SendMessage&MessageBody=" + queryEnc)
And finaly add headers to request
.feed(signedHeaders)
.exec(
http("Custom headers")
.get("url"+"?Action=SendMessage&MessageBody=" + queryEnc)
.header("header_name_1", "${header_1}")
.header("header_name_2", "${header_2}")
I have a problem in to refresh of headers value before 15 Minutes, because my code run after 15 minutes shows that singatureDoesNotMatch or signature expired after 15 minutes. so I did corrections in my code with the hint of #Amerousful. I used Session like
val scen = scenario("Home page") {
exec(session => session.set("authroization", signedHeaders("Authorization"))
.set("host", signedHeaders("Host"))
.set("x-amz-date", signedHeaders("x-amz-date"))
.set("x-amz-security-token", signedHeaders("x-amz-security-token"))
)
.exec(
http("Custom headers")
.get("url + "?Action=SendMessage&MessageBody=" + message)
.header("Authorization", "${authroization}")
.header("Host", "${host}")
.header("x-amz-date", "${x-amz-date}")
.header("x-amz-security-token", "${x-amz-security-token}")
//.header("header", "${signer}")
)
setUp(
scen.inject(nothingFor(5), constantUsersPerSec(80) during (3600)))
After running this code, the header value refreshes every time when user injects and make new Signature. And the scenario is running as your given time.
I've been researching A LOT for past 2 weeks and can't pinpoint the exact reason of my Meteor app returning results too slow.
Currently I have only a single collection in my Mongo database with around 2,00,000 documents. And to search I am using Meteor subscriptions on the basis of a given keyword. Here is my query:
db.collection.find({$or:[
{title:{$regex:".*java.*", $options:"i"}},
{company:{$regex:".*java.*", $options:"i"}}
]})
When I run above query in mongo shell, the results are returned instantly. But when I use it in Meteor client, the results take almost 40 seconds to return from server. Here is my meteor client code:
Template.testing.onCreated(function () {
var instance = this;
// initialize the reactive variables
instance.loaded = new ReactiveVar(0);
instance.limit = new ReactiveVar(20);
instance.autorun(function () {
// get the limit
var limit = instance.limit.get();
var keyword = Router.current().params.query.k;
var searchByLocation = Router.current().params.query.l;
var startDate = Session.get("startDate");
var endDate = Session.get("endDate");
// subscribe to the posts publication
var subscription = instance.subscribe('sub_testing', limit,keyword,searchByLocation,startDate,endDate);
// if subscription is ready, set limit to newLimit
$('#searchbutton').val('Searching');
if (subscription.ready()) {
$('#searchbutton').val('Search');
instance.loaded.set(limit);
} else {
console.log("> Subscription is not ready yet. \n\n");
}
});
instance.testing = function() {
return Collection.find({}, {sort:{id:-1},limit: instance.loaded.get()});
}
And here is my meteor server code:
Meteor.publish('sub_testing', function(limit,keyword,searchByLocation,startDate,endDate) {
Meteor._sleepForMs(200);
var pat = ".*" + keyword + ".*";
var pat2 = ".*" + searchByLocation + ".*";
return Jobstesting.find({$or:[{title:{$regex: pat, $options:"i"}}, { company:{$regex:pat,$options:"i"}},{ description:{$regex:pat,$options:"i"}},{location:{$regex:pat2,$options:"i"}},{country:{$regex:pat2,$options:"i"}}],$and:[{date_posted: { $gte : endDate, $lt: startDate }},{sort:{date_posted:-1},limit: limit,skip: limit});
});
One point I'd also like to mention here that I use "Load More" pagination and by default the limit parameter gets 20 records. On each "Load More" click, I increment the limit parameter by 20 so on first click it is 20, on second click 40 and so on...
Any help where I'm going wrong would be appreciated.
But when I use it in Meteor client, the results take almost 40 seconds to return from server.
You may be misunderstanding how Meteor is accessing your data.
Queries run on the client are processed on the client.
Meteor.publish - Makes data available on the server
Meteor.subscribe - Downloads that data from the server to the client.
Collection.find - Looks through the data on the client.
If you think the Meteor side is slow, you should time it server side (print time before/after) and file a bug.
If you're implementing a pager, you might try a meteor method instead, or
a pager package.
Has anyone noticed that if you try to post a string that exceeds 1,000,000 characters, it simply does not include the field with the request?
...and doesn't throw()!
eg.
<cfscript>
var h = new http( url = "http://...", method = "post" );
h.addParam( type = "formField", name = "a", value = repeatString("a",5000) );
h.addParam( type = "formField", name = "b", value = repeatString("b",1000000) );
h.addParam( type = "formField", name = "c", value = repeatString("c",1000001) );
var p = h.send().getPrefix();
writeDump( var = p, abort = true );
</cfscript>
The "a" and "b" fields are present in the form scope of the recipient page.
The "c" field is missing!
ColdFusion 9,0,1,274733 + chf9010002.jar, Mac OS X 10.6.8, Java 1.6.0_31
Edit: It now works as expected!
Not sure what has changed? My cf admin configuration remains the same. The only possible candidate I can come up with is a recent Apple Java update. Could that be it?
You may need to specify
enctype="multipart/form-data"
This is a setting within CF administrator.
In Coldfusion 9 (this setting has existed for a while, but may exist elsewhere in other versions):
Click on "server settings" group to expand, click on "settings" link (top link). On the settings page:
Maximum size of post data 100 MB (default)
Limits the amount of data that can be posted to the server in a single request. ColdFusion rejects requests larger than the specified limit.
It's interesting that you're hitting a limit right at 100,000 ; sounds like someone got a little lazy with the "bytes" computation. :) At any rate, I'd try tinkering with this setting.
Just an FYI: You'll encounter a similar issue with data truncation on data inserts/updates unless you set your datasource to allow "Long Text Buffer (chr)" greater than the 64,000 default limit.
I've looked through the wss 3.0 documentation, but I can't find anything. I would like to retrieve the locale for a Sharepoint 2007 site using web services (no access to server so can't deploy anything on it), so as to know what time zone is site the configured in. Is that possible?
thx
The time zone of a SharePoint web site can be obtained by the GetList method of the Lists web service. It seems weird to ask for information about a list to get regional settings of a web site but that's it :-)
This is an excerpt of the method response about a single list:
<List>
...
<RegionalSettings>
<Language>1033</Language>
<Locale>1033</Locale>
<AdvanceHijri>0</AdvanceHijri>
<CalendarType>1</CalendarType>
<Time24>False</Time24>
<TimeZone>-60</TimeZone>
<SortOrder>2070</SortOrder>
<Presence>True</Presence>
</RegionalSettings>
...
</List>
The time zone is returned as an offset to the UTC time in minutes. If you add it to the time in the web site local time zone you will get the time in the UTC time zone. (If you want to get the correct value you will have to consider the daylight saving changes and apply them according to the season of the time.).
// Instantiate the web service. Don't forget to dispose it later.
// Append the web service suffix (/_vti_bin/Lists.asmx) to the URL
// of the web site which time zone of you are interested in.
// If you don't use IWA or the current user has no access to the
// web site set the service.Credentials instead.
var service = new Lists();
service.Url = "http://myhost/sites/mysite/_vti_bin/Lists.asmx";
service.UseDefaultCredentials = true;
// Get all lists from the web site you want to get the time zone of.
// Get the XML element at /Lists/List[1]. It can be any accessible list.
// We will use just the unique list identifier from the atribute ID.
var lists = service.GetListCollection();
var list = lists.ChildNodes.OfType<XmlElement>().FirstOrDefault();
if (list == null)
throw new ApplicationException("The web has no lists.");
// Get information about the list which a little about the web too.
// Get the XML element at /List/RegionalSettings/TimeZone.
list = (XmlElement) service.GetList(list.GetAttribute("ID"));
var regionalSettings = list.ChildNodes.OfType<XmlElement>().First(
item => item.LocalName == "RegionalSettings");
var timeZone = regionalSettings.ChildNodes.OfType<XmlElement>().First(
item => item.LocalName == "TimeZone");
// The offset can be added to the time in the web site local time zone
// to get the UTC time. For example, UTC+1 has the offset -60 minutes.
var utcOffset = new TimeSpan(0, int.Parse(timeZone.InnerText), 0);
--- Ferda
Ok, here's what I did to solve this:
make a query to the list for 1 element, getting times set for site's locale
make a query for that element, getting times in UTC
calculate the difference between the 2 results.
Code:
/// <summary>
/// Gets the difference between local time and UTC to calculate offset.
/// Makes a query to the list that returns 1 element with times using the locale as set in the site's settings.
/// Then makes another query for the same element with UTC times to calculate the difference.
/// </summary>
/// <param name="list">list to query</param>
/// <param name="client">WS object</param>
/// <returns>Time offset as TimeSpan object</returns>
private TimeSpan getSiteTZOffset(List list, WSLists.Lists client )
{
//Set up query parameters
XmlDocument xmlDoc = new XmlDocument();
XmlNode emptyQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode queryWithID = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
ndOptions.InnerXml = "<DateInUtc>True</DateInUtc>";
XmlNamespaceManager xnm = new XmlNamespaceManager(xmlDoc.NameTable);
xnm.AddNamespace("z", "#RowsetSchema");
// Gets the attribute that serves as modified date
MapAttribute modifiedDateAttr = attributes.Single(x => x.Value.DateTimeModifiedField).Value;
// Gets the Id attribute
MapAttribute idAttr = attributes.Single(x => x.Value.KeyReference).Value;
//Get 1 result with site's local time
XmlNode resLocalTime = client.GetListItems(list.ListID, list.ViewID, emptyQuery, null, "1", null, null);
XmlNodeList itemsLocalTime = resLocalTime.SelectNodes("//z:row", xnm);
// 2nd query filters on ID of the item returned by 1st query
queryWithID.InnerXml = string.Format("<Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>{0}</Value></Eq></Where>",
itemsLocalTime[0].Attributes[idAttr.Name].Value);
//get the result with UTC time
XmlNode resUtc = client.GetListItems(list.ListID, list.ViewID, queryWithID, null, "1", ndOptions, null);
XmlNodeList itemsUtc = resUtc.SelectNodes("//z:row", xnm);
//Converts string values to DateTime objects
DateTime localTime = DateTime.Parse(itemsLocalTime[0].Attributes[modifiedDateAttr.Name].Value);
DateTime utcTime = getUtcTime(itemsUtc[0].Attributes[modifiedDateAttr.Name].Value);
// Gets offset
TimeSpan offset = localTime - utcTime;
return offset;
}