The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Open Page as hidden, Open new page
Freshman
post Dec 25 2018, 04:46 AM
Post #1


Newbie
*

Group: Members
Posts: 12
Joined: 19-December 18
Member No.: 26,776



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


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Dec 25 2018, 01:15 PM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



If you want to send the SMS and stay on the same page then you need to use either 'ajax' or a 'promise'.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Dec 25 2018, 03:05 PM
Post #3


.
********

Group: WDG Moderators
Posts: 9,628
Joined: 10-August 06
Member No.: 7



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Dec 25 2018, 03:12 PM
Post #4


.
********

Group: WDG Moderators
Posts: 9,628
Joined: 10-August 06
Member No.: 7



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

or a 'promise'.

Yet another concept I have never heard about before. smile.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Dec 25 2018, 03:57 PM
Post #5


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



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 here.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Freshman
post Dec 26 2018, 03:05 AM
Post #6


Newbie
*

Group: Members
Posts: 12
Joined: 19-December 18
Member No.: 26,776



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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Dec 26 2018, 04:34 AM
Post #7


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Then the IFRAME Christian suggested sounds like a better choice for you.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Dec 26 2018, 01:31 PM
Post #8


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Freshman
post Dec 27 2018, 03:29 AM
Post #9


Newbie
*

Group: Members
Posts: 12
Joined: 19-December 18
Member No.: 26,776



@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;
}


This post has been edited by Freshman: Dec 27 2018, 03:30 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Dec 27 2018, 11:45 AM
Post #10


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



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?

This post has been edited by CharlesEF: Dec 27 2018, 11:47 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Freshman
post Dec 27 2018, 12:01 PM
Post #11


Newbie
*

Group: Members
Posts: 12
Joined: 19-December 18
Member No.: 26,776



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;
?>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Freshman
post Dec 27 2018, 12:04 PM
Post #12


Newbie
*

Group: Members
Posts: 12
Joined: 19-December 18
Member No.: 26,776



@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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Dec 27 2018, 01:51 PM
Post #13


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Ok, I will be busy this afternoon but I'll put together a sample tonight.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Dec 28 2018, 12:01 AM
Post #14


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



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: 758
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Freshman
post Dec 28 2018, 02:28 AM
Post #15


Newbie
*

Group: Members
Posts: 12
Joined: 19-December 18
Member No.: 26,776



@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!!!!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Dec 28 2018, 11:34 AM
Post #16


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Ah, good old cURL. Don't know how I missed it. Anyway, glad you got it working.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th March 2024 - 11:34 PM