PHP how to pass URL parameters to create a new URL - php

Very newbie question: setting up a Meraki wireless EXCAP walled garden, and will have users land on a terms-of-service.php (simple checkbox)... upon submission, will land on page with other info THEN need to pass to open web. Need to grab first URL, save it, pass to page2.php, and then out to web.
Meraki's example of incoming URL (when user attempts to access wireless):
http://MyCompany.com/MerakiSplashPage/?base_grant_url=https://example.meraki.com/splash/grant&user_continue_url=http://www.google.com&node_id=222222&gateway_id=222222&client_ip=10.222.222.222
Then "When you are ready to grant access to the user, send the user to GET['base_grant_url'] + "?continue_url=" + GET['user_continue_url']. In the case of the example above, this URL would be:
https://example.meraki.com/splash/grant?continue_url=http://www.google.com
Going in circles on how to do this, any suggestions would be much appreciated.

Use rawurlencode to encode the value properly:
'http://MyCompany.com/MerakiSplashPage/?base_grant_url='.rawurlencode('https://example.meraki.com/splash/grant&user_continue_url=http://www.google.com').'&node_id=222222&gateway_id=222222&client_ip=10.222.222.222'
You can also use http_build_query to build the query automatically:
$query = array(
'base_grant_url' => 'https://example.meraki.com/splash/grant&user_continue_url=http://www.google.com',
'node_id' => '222222',
'gateway_id' => '222222',
'client_ip' => '10.222.222.222'
);
'http://MyCompany.com/MerakiSplashPage/?'.http_build_query($query)

Your final URL would be:
$_GET['base_grant_url']."?".$_GET['user_continue_url'];

Related

Laminas toRoute as POST?

I work with Laminas and in a ControllerAction function I want to redirect to another url as a post by using $this->redirect()->toRoute('newSite', $noURLParams, $options);
When I use the "query"-Option ($options = [$query => ['postPara1' => 'blabla', 'postPara2' => 'blubblub']]), I will get the "post"-Parameter as GET-Parameter in the URL:
hhttp://localhost/new-site?postPara1=blabla&postPara2=blubblub
So everyone could see the content of the parameters.
Is there a way to get the toRoute() to make a "POST" out of it?
Or do I have to use another function for this?
Thank you for your interest and help. After you said that it doesn't work, I changed the sequence of what, when should be called and now I can do it without an additional redirect.

Get and store a URL segment into a cookie with CodeIgniter

For a kind of conversion tracking, I want to store a part of the URL into a cookie and use this into my model functions.
So I think about https//:www.example.com?track=this
How I can get the part of the track (=this) with CodeIgniter and save it into a cookie?
To create a cookie I think that's the way,
$this->load->helper('cookie');
$cookie = array(
'name' => 'track',
'value' => '???',
'expire' => '300',
'secure' => TRUE
);
set_cookie($cookie);
How I can get the part of URL and set cookie etc with CodeIgniter on every possible page? So I mean, no matter over which page the user call the website, I need to make sure that this tracking info is stored in every case.
Go get the cookie later, I think I can use $cookie= get_cookie('track');
Thanks for showing me the way to do it with CodeIgniter.
Mainly you need to use parse_url to extract url to query string and then parse_str to extract query string.
First, you need to get query string from you URL
$query = parse_url('https//:www.example.com?track=this&h=1');
echo'<pre>';print_r($query);
Output:
Array
(
[path] => https//:www.example.com
[query] => track=this&h=1
)
Then you need to extract query
parse_str($query['query'],$array);
echo'<pre>';print_r($array);die;
Output:
Array
(
[track] => this
[h] => 1
)
From here you can store your above array information in cookies
to get the wanted part of the query-string there is a built-in function of Codeigniter
$myval=$this->input->get('track', TRUE);
I've add this with a part to store and get the cookie in the header of my mainlayout-theme.
So it will works :-)

CodeIgniter not inserting urls to database

I am currently building an API using the CodeIgniter framework. I have run into an issue and can't find an answer anywhere.
Currently when my end point gets called to post data it requires a URL to be saved to my DB however the format of the URL gets broken when being inserted.
In my request the URL looks like this:
web_url: "https://someurl.com"
However in my DB it looks like this:
https // google.com
Also, when really long URLs are inserted only a small part of the URL is saved. Here is an example:
Original
https://some.service.com/source/update?user=116&subscription=186248&hash=eyJpdiI6IlpSZytyMXI5NFE2XC80Qmc3MTJMREJHVHgyR2dlQU5NakxEbFFWM2Fsb0hNPSIsInZhbHVlIjoiZWdBT0FrZGFYNkw0cllzcXRRcitvMUFRMDNSaFwveVR6bXVRODlSUFM5MUt6aFQzSDNiczJoRUVzdUZ3VE11MHZjWnFnYzNOUUMyTmxmRnpHNVQ0alF3PT0iLCJtYWMiOiI5NjBlMmI3YTZlMzk2MzU1ZmUxMTI3ZTViODQwMTEyYmQ5NTU4OTc5MTg3Mzk1YzBkZWZkODIxOTQzNTNkYmUyIn0%253D
DB:
https //some.service.com/source/update?user=116&subscripti
In my DB the URL field is set asvarchar(1000)
Here is my code that I am using to store the URL:
if ($status == "active")
{
$user_id = $this->post('user_id');
$update_url = $this->post('update_url');
$cancel_url = $this->post('cancel_url');
$account = array("status" => $status,
"user_id" => $user_id,
"update_url" => $update_url,
"cancel_url" => $cancel_url);
$this->db->insert('accounts', $account);
Any ideas how to resolve this?
maybe you can change the datatype of your field to text
I managed to resolve this issue by using $data = $this->input->post(); to get all the data in the post request rather then getting each individual element.
Appears to be working now :)

How to to implement a forgot password feature using the Google Identity Toolkit in php

I am trying to add google identity toolkit in php. Signin option is working correctly but when i am clicking on problem in sign in link it is showing capthca after submitting captcha it is not navigating to any url.
email.php
<?php
include "identity-toolkit-php-client-master/src/GitkitClient.php";
$gitkitClient=new Gitkit_Client();
$oob_response = $gitkitClient->getOobResults($_POST);
$oob_link = $oob_response['oobLink'];
echo json_encode($oob_response);
?>
email.php is the oobactionurl file. when i am using this code I am getting this error .image
You need to create a php file to retrieve and send the reset link to the user. Make sure the oobActionUrl widget option points to this file. Within the file, you'll get the generated link and additional information by calling $gitkitClient->getOobResults($_POST). It should also work if you exclude $_POST, as the function will check the post contents if no arguments are passed. Then, you can get the link itself like this:
$oob_response = $gitkitClient->getOobResults($_POST);
$oob_link = $oob_response['oobLink'];
From there, you can use your email function of choice to send it to the user. The returned array should contain the following.
'email' => email of the user,
'oldEmail' => old email (for ChangeEmail only),
'newEmail' => new email (for ChangeEmail only),
'oobLink' => url for user click to finish the operation,
'action' => 'RESET_PASSWORD', or 'CHANGE_EMAIL',
'response_body' => http response to be sent back to Gitkit widget
Let me know if you have any further questions.

How to mail to a static list segment with mailchimp API

Once I've identified identified the email addresses of my list segment (using get_emails() custom function, I am setting up my list segment as follows:
$batch = get_emails();
//now create my list segment:
$api->listStaticSegmentAdd(WEDDING_LIST_ID, 'new_wedding_guests');
$api->listStaticSegmentMembersAdd(WEDDING_LIST_ID, 'new_wedding_guests', $batch);
//do I build vars for a campaign?
$options = array (
'list_id' => WEDDING_LIST_ID, //What value id's my list segment?
'subject' => 'Alpha testing.',
'from_email' => 'wedding#juicywatermelon.com',
'from_name' => 'Pam & Kellzo',
'to_name' => $account->name,
);
From here can I use a basic campaign and send it?
$content['text'] = "Some text.";
$content['html'] = get_link($account);
$cid = $api->campaignCreate('regular', $options, $content);
$result = $api->campaignSendNow($cid);
I'm not sure if I'm understanding the api documentation correctly. I also tried 'list_id' => 'new_wedding_guests'; which failed to create a campaign.
Thanks!
I'll assume this is test code and just make the cursory mention of how you probably don't need to be creating a new Static Segment every time. However, your call to add members is not going to work. Per the listStaticSegmentMembersAdd documentation, you should be passing the static segment id, not the name of it. Also note that the docs cross-reference themselves when input params can come from other calls - that parameter there is a good example (it also happens to be returned by listStaticSegmentAdd).
Your options for campaignCreate look like a good start. The documentation for it has examples below - those examples are included in the PHP MCAPI wrapper you likely downloaded. As per above, the list_id you need is the one for the list you used in the listStaticSegment calls (also linked in the documentation).
Now the real key - further down in the campaignCreate docs is the segment_opts parameter - that is how you control segmentation. Follow the link it gives you and you'll find tons of info on the ways you can do segmentation, including using a static_segment.
Hopefully all of that made sense, if not, take a step back and check out these links (and play with segmentation in the app), then it should:
Introduction to MailChimp List Management
How can I send to a segment of my list?
Our Release Info on how Static Segments are used

Categories