Using PHP Curl to redirect to my school portal

I am trying to connect to my school portal using PHP Curl, but no luck, because it seems to redirect to certain pages. I am doing a webapp to show the school schedule in jQuery mobile, but in order to show your schedule, you need to log in and go to your schedule. This is what I intend to use using CURL with PHP.

I used a tutorial from http://codeaid.net/php/get-the-last-effective-url-from-a-series-of-redirects-for-the-given-url that works with these links, but I I can’t find out which link should I use to redirect to my school portal.

If anyone has an idea what steps to take to find out which URL you should use, this will be very helpful.

The code I used:

<?php function getLastEffectiveUrl($url) { // initialize cURL $curl = curl_init($url); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, )); // execute the request $result = curl_exec($curl); // fail if the request was not successful if ($result === false) { curl_close($curl); return null; } // extract the target url $redirectUrl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); curl_close($curl); return $redirectUrl; } $lastEffectiveUrl = getLastEffectiveUrl('https://login.hhs.nl'); echo $lastEffectiveUrl . "-"; ?> 

Again this is a tutorial that I followed from Codeaid, and I take no responsibility for it.

The link to the page of my schools is https://portal.hhs.nl, and, as you can see, if you go there, it redirects me to another page.

+4
source share
1 answer

What you want to do is almost impossible ... They applied several redirects with several methods and security tokens ... Let me explain:

At first, I thought I was redirecting header (), but when I used Tamper Data , the picture became clearer:

1) When you open https://portal.hhs.nl , you are redirected by some meta tags

 <META name="verify-v1" content="Yh6PvgPdX64Vdo9akXqTvstTouu9uQcvrPpFaL9jqZs=" /> <META name="verify-v1" content="eiUD3J3OcF6SjBKGe5ZvkMTzVEJ9rnpr1NaCKV9OIKw=" /> <meta name="google-site-verification" content="Ka0UPoAllNqYvbuviJCk8iV64YfqfWbX6G1APHdY5tg" /> <META content="text/html; charset=windows-1252" http-equiv=Content-Type> <META content="0; URL=http://portal.hhs.nl/portal/pls/portal/PORTAL.home" http-equiv=Refresh> 

So, you need to parse these meta tags and redirect ... here's how you do PHP: can CURL follow meta redirects

2) For some reason, I cannot “open” the data when I am redirected using Tamper Data strong>, so you need to do some research at this point ...

3) And here is another “redirect” technique with JavaScript !!!

 <FORM NAME="SingleSignOn" METHOD="POST" ACTION="https://aselect.hhs.nl/aselectserver/server" > <INPUT TYPE="HIDDEN" NAME="request" VALUE="direct_login1" > <INPUT TYPE="HIDDEN" NAME="rid" VALUE="C741680139CA153E" > <INPUT TYPE="HIDDEN" NAME="a-select-server" VALUE="aselectserver1" > </FORM> </BODY> 

Just analyze them and redirect to https://aselect.hhs.nl/aselectserver/server with these POST values ​​...

4) Finally, we are at https://aselect.hhs.nl/aselectserver/server , where we really enter our credentials, and where you should also analyze the data and send it with authority. After this step, you only know what is behind the portal ...

Conclusion: These safety measures make it clear that they want to stop some automated children, like us, and what if someday these steps are changed? I suggest asking the school about some APIs, I know some schools in the Netherlands that use Untis , and they have a great API that returns some JSON data!

If you insist or cannot get your hand from the API, then get ready for hard work!

Success Veel (good luck)!

+1
source

Source: https://habr.com/ru/post/1445211/


All Articles