My URL is:
http://localhost/working/myapp/login/index/user_id=&user_email=shashankbhat11%40gmail.com&sig=%C3%86%C3%B1z%C3%BD-o6%C2%B6%01%C2%8A%C3%81%C2%A6%C2%A7z%C2%A1%C3%962%3E:%C3%83F%C2%90M%C2%99%C3%BD%C3%A7%C2%A1O%18%C3%83F%3E
How to retrieve user_email and sig values only from this URl in codeigniter controller, i tried this
$var1 = $this->uri->segment(4);
echo $user_email;
die;
and it is giving me an output as below,
user_id=&user_email=shashankbhat11%40gmail.com&sig=%C3%86%C3%B1z%C3%BD-o6%C2%B6%01%C2%8A%C3%81%C2%A6%C2%A7z%C2%A1%C3%962%3E:%C3%83F%C2%90M%C2%99%C3%BD%C3%A7%C2%A1O%18%C3%83F%3E
but I need only the value of user_email i.e shashankbhat11%40gmail.com in the variables var1 and var2 variable should contain %C3%86%C3%B1z%C3%BD-o6%C2%B6%01%C2%8A%C3%81%C2%A6%C2%A7z%C2%A1%C3%962%3E:%C3%83F%C2%90M%C2%99%C3%BD%C3%A7%C2%A1O%18%C3%83F%3E which is the sig part.
Try this
$var1 = $this->input->get('user_email');
echo $user_email;
die;
The the specified URL is not formatted correctly. You need to put "?" in the URL to access URL values as get. See the question mark in the URL below.
http://localhost/working/myapp/login/index/?user_id=&user_email=shashankbhat11%40gmail.com&sig=%C3%86%C3%B1z%C3%BD-o6%C2%B6%01%C2%8A%C3%81%C2%A6%C2%A7z%C2%A1%C3%962%3E:%C3%83F%C2%90M%C2%99%C3%BD%C3%A7%C2%A1O%18%C3%83F%3E
Once you formatted the URL you can use below code to access it:
$user_id = $this->input->get('user_id');
$user_email = $this->input->get('user_email');
Related
I'm trying to setup a page that pulls just a part of the URL but I can't even get it to echo on my page.
Since I code in PHP, I prefer dynamic pages, so my urls usually have "index.php?page=whatever"
I need the "whatever" part only.
Can someone help me. This is what I have so far, but like I said, I can't even get it to echo.
$suburl = substr($_SERVER["HTTP_HOST"],strrpos($_SERVER["REQUEST_URI"],"/")+1);
and to echo it, I have this, of course:
echo "$suburl";
If you need to get the value of the page parameter, simply use the $_GET global variable to access the value.
$page = $_GET['page']; // output => whatever
your url is index.php?page=whatever and you want to get the whatever from it
if the part is after ? ( abc.com/xyz.php?......) , you can use $_GET['name']
for your url index.php?page=whatever
use :
$parameter= $_GET['page']; //( value of $parameter will be whatever )
for your url index.php?page=whatever&no=28
use :
$parameter1= $_GET['page']; //( value of $parameter1 will be whatever )
$parameter2= $_GET['no']; //( value of $parameter2 will be 28 )
please before using the parameters received by $_GET , please sanitize it, or you may find trouble of malicious script /code injection
for url : index.php?page=whatever&no=28
like :
if(preg_match("/^[0-9]*$/", $_GET['no'])) {
$parameter2= $_GET['no'];
}
it will check, if GET parameter no is a digit (contains 0 to 9 numbers only), then only save it in $parameter2 variable.
this is just an example, do your checking and validation as per your requirement.
You can use basic PHP function parse_url for example:
<?php
$url = 'http://site.my/index.php?page=whatever';
$query = parse_url($url, PHP_URL_QUERY);
var_dump(explode('=', $query));
Working code example here: PHPize.online
I have a domain and id is coming in that domain like this
http://www.test.com/update_record_row/id/6356/
I want id value from the domain without passing ? instead of / in (query string)
Using $this->uri->segment() you get the URL parameter
$this->uri->segment(1)
For more ..https://www.codeigniter.com/userguide3/libraries/uri.html
ID
public function update_record_row($id)
{
echo "Id is :".$id;
}
or
Use URI segment
// if URL -http://www.test.com/update_record_row/id/6356/
$id = $this->uri->segment(3);
// if URL -http://www.test.com/update_record_row/6356/
$id = $this->uri->segment(2);
Use $this->uri->segment() to retreive passed value through url
If URL is http://www.test.com/update_record_row/id/6356/
You should use $this->uri->segment(3);
Codeigniter has awesome userguide.Just check this in in uri part.
https://www.codeigniter.com/userguide3/libraries/uri.html#uri-class
I want to replace my query result according to the $_GET value like
If I have URL like
URL/?userid=3255
then the output of the userid from the database should replace with $_GET value when printing the database data
PS: I don't want to update the userid in database i just want to replace userid on the front end when printing the data from database
database table:
userid | name
-----------|
userid=4332|ron
Code:
<?php str_replace("userid=","userid=echo $_GET['userid'],"$row['userid']);?>
$row['userid'] is the data that i fetch from the database
Try with this one:
<?php str_replace("userid=","userid=".$_GET['userid'], $row['userid']);?>
but if user changes $_GET['userid'] param printed result will also change according to the new userid param.
You can use parse_url on the url that return an associative array. Then use parse_str that parse the string into variables. Make any changes you need. Then reassemble the address with the changes using http_build_query.
$url = 'http://www.example.com/?userid=3255';
$parsed_url = parse_url($url);
parse_str($parsed_url['query'], $parsed_str);
if(isset($parsed_str['userid']))
{
// make any changes you want
$parsed_str['userid'] = "new id";
// reassemble the address with the changes
$link = "http://$_SERVER[HTTP_HOST]/?";
$http_builded = $link . http_build_query($parsed_str);
}
I hope this can help you.
Hey i was looking here on other posts on stackoverflow and did't find an answer
i have a problem with changing variable on row output
i am inserting url to database with a var. for example
http://www.sitename.com?id=$site_id
on my php file i have a variable called $site_id
$site_id = 5;
in the end i am using the url and the $site_id for using header but with a $site_id
$url = $row['url'];
header("Location: ".$url);
how can i change the variable?
You can do a simple string replace like this:
(Also i hope you made sure that you are save against SQL Injection for your DB)
$site_id = 5;
$url = 'http://www.sitename.com?id=$site_id'; //As an example from DB
$url = str_replace('$site_id', $site_id, $url);
header("Location: $url");
You don't need to use $url to store $row['url'].. You can use any variable of your choice..
How to put the querystring name in php?
$file_get_html('http://localhost/search/?q=');
And when accessing localhost/?name=example the code looks like this
$file_get_html('http://localhost/search/?q=example');
I do not know how to put $_GET['url'] inside a php :(
The question isn't very clear, but I suspect this is the answer:
file_get_html('http://localhost/search/?q=' . urlencode($_GET['url']));
The ?q=example will let you use something like $example = $_GET['q'],
and $example should equal the value of q in your querystring.
If you have a querystring that looks like this:
?q=example&url=myurl.com
You can access the q and url parameters like this:
$q = $_GET['q']; // which will equal 'example'
$url = $_GET['url']; // which will equal 'myurl.com'
If that is what you are trying to do.
$url = urlencode($_GET['url']);
$contents = file_get_contents("http://localhost/search/?q={$url}");
var_dump($contents);