Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Server-side Scripting _ Open Page as hidden

Posted by: Freshman Dec 25 2018, 04:46 AM

Hi all,

I have a line of code that sends a SMS to a Mobile number.
Problem is that it opens a page to do that, so it navigates away from the page I'm on.
So I want it to do it's thing and then come back to the page I was on.

I was wondering it there is a way to open a page "silently" or hidden or if there is a way to navigate to a site and wait a while and then come back.

Here is the code:

CODE

header('Location: http://www.mymobileapi.com/api5/http5.aspx?Type=sendparam&username=$User&password=$Pass&numto=' . $getcell . '&data1=Test123;
exit;


If I add a second line header('Location: index.php'); then it does come back to the index page but it does not send the SMS.
I tried adding a sleep command inbetween but still not sending the sms then

The other problem is that if it open the mymobileapi page it also shows the username and password in clear text. So it would have also been nice to hide that but the site is a 3rd party site so I don't have any control over it unless I can add something to the Header command to hide the URL??

Thanks a lot



Posted by: CharlesEF Dec 25 2018, 01:15 PM

If you want to send the SMS and stay on the same page then you need to use either 'ajax' or a 'promise'.

Posted by: Christian J Dec 25 2018, 03:05 PM

Hi!

QUOTE(Freshman @ Dec 25 2018, 10:46 AM) *

I was wondering it there is a way to open a page "silently" or hidden or if there is a way to navigate to a site and wait a while and then come back.

You could put the PHP header in a hidden iframe page.

QUOTE
If I add a second line header('Location: index.php'); then it does come back to the index page but it does not send the SMS.

That's sounds normal, you can only send one redirect per page. The redirect back to index.php would have to be placed in the page at www.mymobileapi.com.

QUOTE
The other problem is that if it open the mymobileapi page it also shows the username and password in clear text. So it would have also been nice to hide that but the site is a 3rd party site so I don't have any control over it unless I can add something to the Header command to hide the URL??

With Ajax or a hidden iframe it would not be visible in the browser's address bar, but the user might still see it in the HTML source.

Posted by: Christian J Dec 25 2018, 03:12 PM

QUOTE(CharlesEF @ Dec 25 2018, 07:15 PM) *

or a 'promise'.

Yet another concept I have never heard about before. smile.gif

Posted by: CharlesEF Dec 25 2018, 03:57 PM

QUOTE(Christian J @ Dec 25 2018, 02:12 PM) *

QUOTE(CharlesEF @ Dec 25 2018, 07:15 PM) *

or a 'promise'.

Yet another concept I have never heard about before. smile.gif

I think javascript promises was introduced in ES6. ES5 can support promises if you include a library (Bluebird or Q). A short tutorial can be found https://scotch.io/tutorials/javascript-promises-for-dummies.

Posted by: Freshman Dec 26 2018, 03:05 AM

Hi all, Unfortunately I don't have any control over the 3rd party website (mymobileapi) so I cannot put the re-direct there.

Since I'm super new to php etc (I'm an old-school VBA developer) I will have to research ajax and promise.
Anyone willing to post an example of code I might be able to modify?

Posted by: pandy Dec 26 2018, 04:34 AM

Then the IFRAME Christian suggested sounds like a better choice for you.

Posted by: CharlesEF Dec 26 2018, 01:31 PM

QUOTE(Freshman @ Dec 26 2018, 02:05 AM) *

Hi all, Unfortunately I don't have any control over the 3rd party website (mymobileapi) so I cannot put the re-direct there.

Since I'm super new to php etc (I'm an old-school VBA developer) I will have to research ajax and promise.
Anyone willing to post an example of code I might be able to modify?

I can help with 'ajax' code (I don't use 'promises' myself, yet) but it would be better if I can see your web page code. Making an 'ajax' request requires javascript and PHP code. Javascript makes the request, then PHP fills the request and can return a status. Javascript then receives the status and can display the results in your web page.

Posted by: Freshman Dec 27 2018, 03:29 AM

@CharlesEE

Thanks for the offer.
Here is an extract of the code I'm using:

The code is inside index.php. It prompts the User to enter his Mobile number and password. He he doens't have or forgot the password, then he would click on "forgot" which will then run the code to gererate the SMS.
All this does is pass the parameters to a 3rd party site and the SMS gets sent automatically. I all want to do it come back to the index.php site once the SMS is sent. But at this moment once the Header command is actioned, the page remain on the 3rd party's page and the User have to click the Back button on their Browser to get back. This is not ideal. I would like for the index.php page to appear once the www.mymobileapi.com 3rd party page have fully loaded (and processed).

Does that make sense?

Thanks again


CODE

if(isset($_POST['forgot'])) {
    if(empty($getcell)) {
        echo "Please enter Cellphone number<br/>";
        exit;
}

    if(empty($PassW)) {
        header('Location: register.php?cell=' . $getcell);
        exit;
}

    header('Location: [url=https://api.smsportal.com/api5/http5.aspx?Type=sendparam&username=xxx&password=zzz&numto=']https://api.smsportal.com/api5/http5.aspx?T...amp;numto='[/url] . $getcell . '&data1=Password for HaKehilla is ' . $PassW);
    exit;
}

Posted by: CharlesEF Dec 27 2018, 11:45 AM

I wanted to see your HTML code so I could better understand the flow of data.

So, to send an SMS does this mean that each user enters a username and password and that username/password is what is sent to the SMS server? Meaning each user must have their own SMS login information.

Or, is the username and password sent to the SMS server a general login? Meaning only 1 SMS account is used to send all users messages.

And, after you send the SMS do you get a reply on the SMS website? Meaning do you see some kind of 'Message Sent' or 'Message Not Send' message? Do you even care about a status reply?

Posted by: Freshman Dec 27 2018, 12:01 PM

Ahh - thanks a lot guys I got it right:

CODE

<?php
// Get cURL resource
$curl = curl_init();
$sms = "https://api.smsportal.com/api5/http5.aspx?Type=sendparam&username=xxx&password=xxx&numto=0831231234&data1=Test123";
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $sms,
    CURLOPT_USERAGENT => 'Codular Sample cURL Request',
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => array(
        item1 => 'value',
        item2 => 'value2'
    )
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
header('Location: index.php');
exit;
?>

Posted by: Freshman Dec 27 2018, 12:04 PM

@CharlesEE

Just to answer your questions. The login details are mine so all SMS will use the same login details (global account) but their individual password will be sent to their mobile phones (if they click Forgot Password). Veyr much like a one-time-pin.
Also there is a status report which I don't care for and which was causing it to go to the "result" page. But with the above code no navigation takes place and all is 100% fine smile.gif

Posted by: CharlesEF Dec 27 2018, 01:51 PM

Ok, I will be busy this afternoon but I'll put together a sample tonight.

Posted by: CharlesEF Dec 28 2018, 12:01 AM

Attached is a sample of what I think you want. Before you test the code be sure to assign values to the 3 variables in the '<script>' section. This is just a basic example, like I didn't check for blank values but maybe you should. And I 'encodeURIComponent' the values but maybe you don't need to. If you have any questions just ask.
Attached File  ajax.html ( 1.26k ) Number of downloads: 762

Posted by: Freshman Dec 28 2018, 02:28 AM

@CharlesEF - It seems like you missed my post #11 with the solution I found but I must say your solution also worked and I actually like it better since I understand the code better than the solution I posted.
So THANKS A LOT for helping with this!!!!

Posted by: CharlesEF Dec 28 2018, 11:34 AM

Ah, good old cURL. Don't know how I missed it. Anyway, glad you got it working.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)