Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
How to get the current URL without the first part dynamically?
For example:
www.google.com/en/second => /second
www.google.com/en/second/third => /second/third
Where to put the function or how to implement this in the current blade view?
You can use Request::segments:
implode('/', array_slice(request()->segments(), 1));
All http link:
$link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; // www.google.com/en/second/third
Just requested link:
$requested_link = "$_SERVER[REQUEST_URI]"; // en/second/third
If you do not want any part of link, replace it with "":
str_replace("en/", "", $requested_link); // second/third
You can put this code anywhere in view or controller. For example in view:
<?php
function get_url(){
$requested_link = "$_SERVER[REQUEST_URI]";
return str_replace("en/", "", $requested_link);
}
?>
Get the current URL including the query string...
echo url()->full();
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
That is my way to check file image uploaded or not , send from view to controller php laravel
$dataImages=$request->images;
if($dataImages[0] == ""){
print_r("file null");
}else{
print_r("file not null");
$pathImage='product_images/1/image-1651261589260.jpg';
if(File::exists($pathImage)){
File::delete($pathImage);
}
}
Laravel has a helper function in the request object fo that case called hasFile
if($request->hasFile('images')){
// true
} else {
// false
}
for more info check the Retrieving Uploaded Files
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have 4 types of users in my system. So i have to include header files using conditions.
I tried below code.
if($this->session->userdata('email_admin')){
include('header_admin.php');
}
if($this->session->userdata('email_zone_manager')){
include('header_zone_manager.php');
}
if($this->session->userdata('email_state_manager')){
include('header_state_manager.php');
}
if($this->session->userdata('email_user')){
include('header_user.php');
}
When i tried with echo something and exit() its working means condition works file but header css and js etc. are not including.
if($this->session->userdata('email_admin'))
{
echo "Admin";
include('header_admin.php');
}
Above code echo "Admin" but header_admin's contents are not including.
You can load views like this...
if(isset($this->session->userdata('email_admin'))){
$this->load->view('header_admin');
}
if(isset($this->session->userdata('email_zone_manager'))){
$this->load->view('header_zone_manager');
}
if(isset($this->session->userdata('email_state_manager'))){
$this->load->view('header_state_manager');
}
if(isset($this->session->userdata('email_user'))){
$this->load->view('email_user');
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to access the URL of the video element from an external URL.
That's an example of the url I'm trying to access:
https://www.musical.ly/v/MzA4NTExODI2MDI0MjMzNDgxOTEyMzI.html
file_get_contents and curl return an html code without the video in it, what am I doing wrong?
Any PHP/jQuery solution would be great!
It seems like the MzA4NTExODI2MDI0MjMzNDgxOTEyMzI-part of the url is the video key.
They are calling: https://www.musical.ly/rest/v2/musicals/shareInfo?key=MzA4NTExODI2MDI0MjMzNDgxOTEyMzI to fetch the video information in json format.
You could do the same and just use the videoUri from the json response?
Example
Just for fun, I created an example how to fetch it from the initial URL. This would of course need a bit of validation and such, but it is a working example:
<?php
$url = 'https://www.musical.ly/v/MzA4NTExODI2MDI0MjMzNDgxOTEyMzI.html';
// Extract the url path and explode the segments
$segments = explode('/', parse_url($url, PHP_URL_PATH));
if (isset($segments[2])) {
// We have the key segment so let's build the URL to fetch the info
$infoUrl = 'https://www.musical.ly/rest/v2/musicals/shareInfo?key=' . rtrim($segments[2], '.html');
$info = file_get_contents($infoUrl);
$info = $info ? json_decode($info, true) : null;
}
if (isset($info['result'], $info['result']['videoUri'])) {
// We have all we need, let's get the video uri
echo $info['result']['videoUri'];
} else {
die('No video URI found');
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to get a variable which I declared in one php file to another without including the whole first php
while($row = mysql_fetch_assoc($sql)) {
// Urlaubstage ausgeben
if($row['frtutage'] < 1) {
$verbraucht = "0";
} else {
$verbraucht = $row['frtutage'];
}
$resturlaub = $row['miturlaubstage'] + $row['mitutagevorjahr'] - $verbraucht;
$urlaubgesamt = $row['miturlaubstage'] + $row['mitutagevorjahr'];
I need the variable $resturlaub in the second PHP without calculating the variable again.
How do I do this? Or is it even possible?
Thanks.
edit: the first php file is about calculating vacation days and how much I have remaind after taking a few vacation days, in the second file I need the calculation of the remaining days then, so I just want to use the variable again and not calculate it again
You can try somehting like
$var = 'random_query';
$page= 'yourpage.com/?my_var='.serialize($var);
header("Location: $page");
exit;
and in your page you can get the value by
if (isset($_GET['my_var']))
{
$my_var = unserialize($_GET['my_var']);
}
But it would depend on the size of that variable that you need to pass, and what is the purpose of the scripts.
If you don't want to include the whole first php file but only a variable then you should create a third file (called: variables.php or config.php for example).
Then include variables.php in both file so the variable will be shared among your scripts
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i am trying to develop a website and i want that after entering correct username and password desired page should open. how i can achieve this.
if(...)
{
// code to verify login...
header("Location: http://page_to_forward_to/");
}
else { ... }
Hope this is what you are looking for
$url = "my/url/here";
Header("Location: $url");
exit();
you can use the header function:
header("location: www.example.com/yourpage.php");
Other possibility is to use javascript:
<script>
window.location = 'yourpage.php';
</script>