making router for parsing javascript request through php - javascript

I have seen this request
https://somesite.com/path/script.js?shop=xyz.com
https://somesite.com/path/script.js?shop=abc.com
the output for both requests are different
earlier I was thinking that .js file cant be treated like php and dynamic data cant be passed but I was wrong and some expert advised that its router which is passing these data and according to shop name they are serving.
I have php apache+ nginx server
can anyone tell how we can make this work. don't want to go with Nodejs as it won't allow to pass php code.
just for test i want to call above links and print this.
hi i am shop xyz
or hi i am shop abc
on respective calls.
can anyone share some details guidelines how to make router. any link any guide any advise will solv the purpose.
I have never dealth with such javascript ant it is damm easy in php extension but want to learn in javascript.

Related

Sending variables inside a response node.js, vainilla js

im trying to learn nodejs and vainillajs for web development, making my first project after some months of tutorials, and im in having some very basic doubts, dont know if im conceptually wrong, if someone can point me in te right direcction ill be very grateful!
1-The user access my main page on route:/ receives the corresponding public html/css /JS and have the option to a fills a form, and send a post request with that data to route /validation.
2-on the server side i receive the post request, with the data provide by the user, i make some validations on that data
and here comes the part im very doubtfull
depending on the validation i want to send to the user a response with data containing reasigning values for existing variables inside the public js file sent in first place, (like setting the value of a variable to block, to open a modal, or just adding some innerhtml)
I believe i cannot modified the public js already sent, but i want to know if i can respond with a redirection to route / again, but adding the reasigned variable inside the response.
and is if that the proper way of doing what i im trying to do.
I know i can redirect my user to another totally diferente route, but in principle that is not how i would like it to be.
any help or guiding material about this topic would be greatly appreciated.

Get data access from a website that is developed in AngularJS

I want to create a php app that will check ticket status from FIFA page that is created in angular js.
I tried to get data by using PHP, PHP curl Method, PHP file_get_content(), Jquery, and Javascript but all the time i got empty array.
hopefully there will some restrictions from angular js and server. link is given below please help me to check data from website.
https://tickets.fifa.com/Services/ADService.html?lang=en
You are talking about screen-scraping. Screen-scraping is a fragile solution because if they change the HTML for their page then your application will break.
That said, in your case the reason you got an empty array is because that site's webserver prevents screen-scraping. If you'd checked your php error log you would have seen a 403 forbidden error.
Simply put.. FIFA does not want their data to be stolen and used for purposes other than what they intended it for.

Express routing same path to either NodeJS API code or AngularJS frontend

I have the following things I want to accomplish. In the end I feel it is just a simple thing but I can't get my mind wrapped around it architecture-wise.
I have a simple NodeJS Express server that serves an AngularJS frontend via
this.app.use(
express.static(__dirname + '/' + settings.env)
);
Now I have some API Endpoints that are supposed to be at least of RESTful path-naming. I have AJAX Calls to them on some button clicks on the Front-End.
Let's say one Button is to load and view a list of "Loans"(Whatever this might be): GET /loans.
The Angular frontend reacts on and writes links like this: /#/loans
That was Question Part 1: Why is this? And more importantly: Is it common practice to keep it like that?
Now I am also sending out e-mails that have Buttons in them that the receiver can click.
Right now I cannot remind anymore why I wanted this, but it made sense when I decided to.
I want to be able to request GET /loans as path on that button click in the e-mail and have the Express routing decide whether to run logic and return a json or to "reroute" to angular to render the page.
That was Question Part 2: Is this something I should or should not want to accomplish? And if I still want to accomplish it what would be the best way?
I'll have another shot on the 2nd Part in Short:
I want to decide depending on the Accept-Header whether to return a json or to "reroute" to static files.

How do I populate form fields on a page from a database based on the page url?

Hello first I’d like to say, please excuse my ignorance to this all, as I’m very new to this all. I just started and still trying to understand this.
So far I have a database set up and I’m trying to retrieve values from a database to fill in a form on a page when it loads. The record or row/values that need to be retrieved from a database depend on the page’s URL.
I’m ok with html and css but still trying to learn more about jquery, JavaScript, sql, php and so on and so forth. I realize I have a ways to go and honestly some of the guides and tutorials online are kind of confusing because everyone has a different way of coding. So I’m a bit confused.
I’ve included a simple chart to breakdown what I’m trying to do.
If someone could point me in the right direction I’d be really grateful! Thanks.
If I understand you well, you want to setup a form and populate some fields of this form with a query forms a database, the primary key of the record being relative to the url.
The first step is to build the url, you can pass some parameters to an url by adding a ? at the end of the url followed by the parameter name, the = sign and the parameter value. If you have more than one parameter, you should separate each parameter with the sign &.
So your url could be something like this :
www.examplesite.com/page&.html?key=key_A1
Then, you'll have to choose if you want to build the page on the server side with a language like php, in which case you retrieve the parameter, query the database, build the html form and send it to the client.
You can also go client side with plain javascript or jquery, in which case you will still have to do some server side programming to query the database but will use an ajax call to get the data and will populate the fields in Javascript or JQuery.
You can do this using Javscript(using Ajax)
U need the key to search for get the results from database
Using ajax call get the data, You might have to write code to get the details from database using any server side prog language
Using javascript to fill the form input with the received data.
Google for jquery ajax examples, and how to populate input using javascript.
There are many frameworks out there that have DataBinding built-in that do the same job a lot easier. My favourite would be Angular Js, you can try Ember and lot more out there, choose the one you feel comfortable with.

MySQL Security with PHP, javascript, and HTML?

Okay, I'm very new to web programming. I'm creating my own database-driven website. I'm attempting to setup an admin login to update the site's content. I'm worried about acessing my mySQL databse securely however.
I intend to have the database search for the given username, and then compare the password hash to the hash of the given password.
My worry is in setting up the connection to the mySQL datbase.
from what I see, the way to do this is via:
<?php
$myConn=mysqli_connect(host,user,pass,dbName);
>
Now I intend to pass this to javascript to check all the credentials but if this is defined in the HTML file, then the login details would be plain for all to see yes?
Or, should I define it in an external .js file that will to the checking? I'm still worried if that is safe enough?
I think you are a bit confused there so i will try to explain it very simple.
Front End - Client Side: HTML , CSS , JavaScript
Back End - Server Side: PHP , SQL
Everything on the Front End... can not be trusted, as it is accessible by everyone.
Then why we are validating with JavaScript?
Just to help users with typos... simple as that...
All your security, is at the Back End. You validate with PHP all the values submitted from the Front End and then you perform the required actions on your Database with SQL.
You should never pass anything to JS that you don't want your users to see/access. You should do that via PHP.
Does this help you/clear the things a bit?
PS: from my understanding you are creating a login for your project right? Find below some links with tutorials step by step that might help you.
http://www.phpeasystep.com/phptu/6.html
http://php.about.com/od/finishedphp1/ss/php_login_code.htm
http://www.wikihow.com/Create-a-Basic-Login-Script-in-PHP
http://www.homeandlearn.co.uk/php/php14p2.html
http://phpsnips.com/4/Simple-User-Login#.Uk41QYZmi-0
http://www.html-form-guide.com/php-form/php-login-form.html

Categories

Resources