Codeigniter base url include port generated randomly - codeigniter-3

I am using Codeigniter 3 to build an application with PHP Desktop and I am trying to get the base url to execute an ajax script in javascript.
$.get( "<?php echo base_url("print_ticket_associate.php"); ?>", { pin: pin, dash : "no", entree : "0", dessert : "0", repas :"1", badge : badge } );
Unfortunately, my configuration include random port on http and I need to include this to my base url on codeigniter. This means I can not set it in configuration.
Assuming the page I am trying to execute the script from is : login/match, base url for for codeigniter will be http://localhost/login/match. Which means it is not possible to paste the port after the string.
I want to access http://localhost:randomPort/print_ticket_associate.php
Is there a way to get that port at a specific time in codeigniter page ?

I had the same issue. But i got the solution.
Open the settings.json file and change the server port to a fixed port as follows...
"web_server": {
"listen_on": ["127.0.0.1", 8888],
..........
}
and in codeigniters config.php set the
$config['base_url'] = 'http://localhost:8888/';
Note : You can use any number in place of 8888.
Happy coding.

Related

Elm lang redirect to external URL

How can I redirect to external url? I've tried with Navigation module, but it seems to work only for local routes. Is there a way to do it natively, without js ports?
I.e. window.location.href = http://google.com;
Edit: I somehow missed Navigation.load function. As suggested below, it will help with redirects.
Since a tag can be always used with specified href, I'd rather try to find a solution which would avoid using redirection from update function.
a [ href "http://google.com" ] [ text "Google link" ]
But in case it's necessary to implement the logic similar to window.location.href = "http://google.com";, elm-lang/navigation provides load function (and a couple of other useful ones for forcing page loads) which does, what you're expecting.
It takes a url and returns a command load : String -> Cmd msg, so it's going to look like this:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
RedirectToGoogle ->
( model, load "http://google.com" )

Dual Base URL in Moodle

I have installed the XAMPP and Moodle 2.5 inside it.
Along side, I've also installed No-ip client to convert this to a webserver.
Now my question is, I woud like to have this server reacheble from my intranet and from outside.
My config.php file have base url like:
$CFG->wwwroot = 'http://172.16.1.1/exam';
$CFG->dataroot = 'H:\\xampp\\moodledata';
$CFG->admin = 'admin';
But not limited to local ip address, I want to use it as webserver to access it from internet. Please suggest me how to set the base url to use it from internet and also from my intranet.
The simplest solution is use a domain name which can be accessed from both internet and internal machines.
Failing that, the Moodle config file is simply a PHP file so you can do something like this:
if (access_via_internet()) {
$CFG->wwwroot = WEBROOT_FOR_INTERNET_ACCESS;
} else if (access_via_intranet()) {
$CFG->wwwroot = WEBROOT_FOR_INTRANET_ACCESS;
} else {
throw new Exception("Ye cannae change the laws of physics");
}
function access_via_internet() {
// Do something to detect access via the internet.
// Probably parse $_SERVER['HTTP_HOST']
return (did_we_detect_the_internet() ? true : false);
}
function access_via_intranet() {
// Do something to detect access via the intranet.
// Probably just negate the value of access_via_internet()
return !access_via_internet();
}
Another option is to just rely on the server address by which the user came to you:
$CFG->wwwroot = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/exam';
One potential issue, if you do allow access from different addresses: do not copy and paste Moodle URLs into course content. It's easy to forget, but the URLS will only work for users also accessing from the same route.

Reverse routing on an application deployed in a Tomcat context

I am developing a Play 1.2.5 application that will be installed in a Tomcat context:
http://mytomcat:8080/myapp
And in my routes file I have:
GET /companies/{companyID}/employees Employees.getForCompany
As per the instructions for deploying a Play application in a Tomcat context, I am generating URLs exlusively using the Reverse Router. This works fine, but I am not sure what to do in the case of a jQuery method such as an Ajax request of this style:
var companyID = $('#companies').find(":selected").val();
$.ajax({
url : "#{Employees.getForCompany(companyID)}",
...
});
Obviously the value of companyID isn't known at the time of the generation of the HTML and the resolution of routes by the reverse router.
The only solution that I can see is to reconfigure my routes file so that the URLs are different and the parameters are always at the end, but that makes the REST URLs less logical.
GET /companies/employees/{companyID} Employees.getForCompany
Is there a better way?
I have found the solution myself - Play includes the jsAction tag which generates a function that builds the correct URL:
var companyURL = #{jsAction #Employees.getForCompany(':companyID') /}
$.ajax({
url : companyURL({companyID:companyID}),
...
});
Like that I can maintain the preferred routes mapping:
GET /companies/{companyID}/employees Employees.getForCompany

Why does CasperJS form submit not redirect to the next page?

This is my first casper test, so I'm still struggling with the basics. I would like to fill in the username and password on my login form, then submit it. And then confirm if a 'log off' link is rendered on the next page (confirming that the user has been logged in).
But as far as I can tell, when then is called, the url is still the same. Looks like no post or redirect to the next page is happening. What am I doing wrong?
casper.start "http://test.local.mycompany.local/", ->
#echo 'at ' + #getCurrentUrl()
#fill 'form', { UserAlias : 'joe', Password : 'password' }, true
casper.then ->
#echo 'at ' + #getCurrentUrl()
#test.assertExists '#log-off-link', 'log-off link exists'
casper.run ->
#test.done()
So the echo of #getCurrentUrl both returns the same URL, which is wrong.
You can try to use chrome extension ressurectio to generate automated tests, for casperjs, in browser. It's very simple to use and useful. May be in a few lines(- part of generated code) you should to make some fixes but anyway it's very useful and convenient.
I had the same problem. One day my casper tests stopped working. More exactly casperjs stopped following redirects. The problem really was that my server was returning an invalid HTTP set-cookie header (with an invalid date). This was due to a configuration problem with the expiration date. Anyway, it seems that if there is an incorrect value in some header value something makes casperjs to ignore other header values such as the "location" http header for redirects.
Once I fixed the problem with the expiration date in the cookies the HTTP set-cookie header was ok and casperjs started to follow again the redirects.
Hope this helps!
It is possible that casper doesn't find the fields by name. You could try
casper.start "http://test.local.mycompany.local/", ->
#echo 'at ' + #getCurrentUrl()
#fillSelectors 'form', { 'input[name=UserAlias]' : 'joe', 'input[name=Password]' : 'password' }, true
It should mean the same as your code, but sometimes it doesn't.

Using ASP.NET MVC2, empty route is not being forwarded by IIS 6

First let me explain that I am on a hosted solution, and there is not much I can do in ways of configuration and settings for IIS 6.
I have MVC2 working to a degree, I'm using the following Global.asax code:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { action = "Index", id = "" }
);
routes.MapRoute(
"Root",
"",
new { controller = "Default", action = "Index", id = "" }
);
}
In the first route, I had to specify {controller}.aspx, due to IIS 6 not being able to execute non aspx code (or something like that, not really sure).
Which is fine, the following works:
hxxp://mysite.com/home.aspx, hxxp://mysite.com/projects.aspx, hxxp://mysite.com/contact.aspx
which are all controllers and I can run their respected actions as well.
The problem is that I can not do an empty URL properly (ie hxxp://mysite.com/), it gives me a "Directory Listing Denied" error.
The question I have, is with a default.aspx file located at root (which does execute), can I load the Home controller WITHOUT using a simple Response.Redirect?
Thank you,
Matthew
The fact that you are getting "Directory Listing Denied" means that the isapi filetr don't match for working with MVC.
The fact that you are getting "Directory Listing Denied" means that you don't have a default document and therefore the server is trying to show a list of files on the root folder.
Update the Default Document to something like "Default.aspx". Your hosting provider should have an option for this. This is very common.
You can disable this behaviour on IIS6 and IIS7
// Disable IIS looking at physical files and directories
RouteTable.Routes.RouteExistingFiles = true;