Php post method not getting data from url - php

I have an URL which is to be used for getting post data after pasting and pressing enter in the browser.
My link is :
http://vtrails.us/mixtape-builder/?song_urls=http://vtrails.us/wp-content/uploads/2015/12/mpthreetest.mp3&song_artist=ganja
<?php
if(isset($_POST['song_urls']) && !empty($_POST['song_urls'])){
$song_url = $_POST['song_urls'];
$song_artist = $_POST['song_artist'];
}
echo $song_url;
echo $song_artist;
?>
But i am not getting any of them.So what can i do now?

If you use $_GET instead of $_POST you will get desired result:
Here is the code
<?php
if(isset($_POST['song_urls']) && !empty($_POST['song_urls'])){
$song_url = $_POST['song_urls'];
$song_artist = $_POST['song_artist'];
}
echo $song_url;
echo $song_artist;
?>

Its $_GET, not $_POST. Do this:
<?php
if(isset($_GET['song_urls']) && !empty($_GET['song_urls'])){
$song_url = $_GET['song_urls'];
$song_artist = $_GET['song_artist'];
}
echo $song_url;
echo $song_artist;
?>

Related

POST variable - XHTTP, PHP [duplicate]

I have an URL which is to be used for getting post data after pasting and pressing enter in the browser.
My link is :
http://vtrails.us/mixtape-builder/?song_urls=http://vtrails.us/wp-content/uploads/2015/12/mpthreetest.mp3&song_artist=ganja
<?php
if(isset($_POST['song_urls']) && !empty($_POST['song_urls'])){
$song_url = $_POST['song_urls'];
$song_artist = $_POST['song_artist'];
}
echo $song_url;
echo $song_artist;
?>
But i am not getting any of them.So what can i do now?
If you use $_GET instead of $_POST you will get desired result:
Here is the code
<?php
if(isset($_POST['song_urls']) && !empty($_POST['song_urls'])){
$song_url = $_POST['song_urls'];
$song_artist = $_POST['song_artist'];
}
echo $song_url;
echo $song_artist;
?>
Its $_GET, not $_POST. Do this:
<?php
if(isset($_GET['song_urls']) && !empty($_GET['song_urls'])){
$song_url = $_GET['song_urls'];
$song_artist = $_GET['song_artist'];
}
echo $song_url;
echo $song_artist;
?>

Dynamic variable in PHP [GET]

I'm trying to use the php get. everthing is working find exept the include page.
it's adding 1 at the end of include content
any ide how do i ride that?
example:
I love norway
I love norway1
Code:
<?php
if($_GET['boy'] == 'zabi') $zabkas = 'it is Zabi';
if($_GET['girl'] == 'veronka') $verona = 'It is veronka';
if($_GET['place'] == 'norway') $norge = include('norway.php');
?>
<?php echo $zabkas ?>
<?php echo $verona ?>
<?php echo $norge ?>
We should use file_get_contents, instead of include.
$norge = file_get_contents("norway.php");
Use the output buffer functions to capture the output from the included script.
<?php
if($_GET['boy'] == 'zabi') $zabkas = 'it is Zabi';
if($_GET['girl'] == 'veronka') $verona = 'It is veronka';
if($_GET['place'] == 'norway') {
ob_start();
include("norway.php");
$norge = ob_get_clean();
}
?>
<?php echo $zabkas ?>
<?php echo $verona ?>
<?php echo $norge ?>

If session has value echo it else echo "all"

Update 2
I'll just leave this here for future references. But this is the solution I created with all the help I got here. Thanks!
<script>
function Refresh() {
location.reload();
}
</script>
<?php $number = $_SESSION["page_id"]; ?>
<?php
if (isset($_SESSION['page_id']) && !empty($_SESSION['page_id'])) {
echo do_shortcode('[RICH_REVIEWS_SHOW category="page" num="all" id="'. $number .'"]');
session_destroy();
echo ('<button class="btn btn-0001" onclick="Refresh()">Show All</button>');
}
else{ echo do_shortcode('[RICH_REVIEWS_SHOW num="all"]'); }
;
?>
Update
So I'm trying to just do a simple echo to see if the session is set using this code:
<?php if(isset($_SESSION['page_id']) && !empty($_SESSION['page_id'])) {
echo 'Set and not empty, and no undefined index error!');
};?>
But doing this breaks my page, I just get a blank page? How do I check if the session is set? When I do a echo of the session using this code:
<?php echo $_SESSION["page_id"]; ?>
It does output the correct session value?? What am I doing wrong?
I have a sessions saved with PHP and I'm using this so that the page ID from Wordpress is echo-ed in a shortcode do_shortcode('');
This is what my code looks like:
<?php $number = $_SESSION["page_id"]; ?>
<?php echo do_shortcode('[RICH_REVIEWS_SHOW category="page" num="all" id="'. $number .'"]'); ?>
<?php echo do_shortcode_all('[RICH_REVIEWS_SHOW category="page" num="all" id="all"]'); ?>
<?php echo $shortcode ;?>
<?php echo $shortcode_all ;?>
Now, what I would like to do is IF the page_id is not stored in the session it should echo all. So how do I go about this?
I found this code, and I think its something I need... But I'm not that great a programmer/coder...
<?php
$var = 0;
// Evaluates to true because $var is empty
if (empty($var)) {
echo '$var is either 0, empty, or not set at all';
}
// Evaluates as true because $var is set
if (isset($var)) {
echo '$var is set even though it is empty';
}
?>
So, if I where to put these two together I would get something like this
<?php
$number = $_SESSION["page_id"];
// Evaluates to true because $var is empty
if (empty($number)) {
echo $shortcode_all ;
}
// Evaluates as true because $var is set
if (isset($number)) {
echo $shortcode ;
}
?>
Am I in the right direction?
Solution
<?php
if (isset($_SESSION['page_id']) && !empty($_SESSION['page_id'])) {
echo('Set and not empty, and no undefined index error!');
};
?>
What am I supposed to feel from the missing (?
If you are using wordpress then you should use the session_start(); in wp-config.php file so please first put in you wp-config.php at top and then check.
<?php
$number = $_SESSION["page_id"];
// Evaluates to true because $var is empty
if (empty($number) || $number=='') {
echo $shortcode_all ;
}else{
echo $shortcode ;
}
?>

If variable is link, echo link

I having issues getting a function to echo, where $lightbox_link1 = get_custom_field('lightbox_link1'). I'm fairly new to PHP.
Below is the defining function:
// Check for a lightbox link, if it exists, use that as the value.
// If it doesn't, use the featured image URL from above.
if(get_custom_field('lightbox_link1')) {
$lightbox_link1 = get_custom_field('lightbox_link1');
} else {
$lightbox_link1 = $image_full[0];
}
Echo Function:
<?php if ($lightbox_link1 = get_custom_field('lightbox_link1')) {
echo '';
} ?>
<?php if ($lightbox_link1 = get_custom_field('lightbox_link1')) {
should be
<?php if ($lightbox_link1 == get_custom_field('lightbox_link1')) {
= is used for assignment
== is used for comparison
=== is used for typesafe comparison
also you can't declare <?php ... ?> inside another <?php ... ?>
to get something like <?php ... <?php ... ?> ... ?>
take a look at what you did up to here:
<?php if ($lightbox_link1 = get_custom_field('lightbox_link1')) {
echo '<a href="<?php
Instead, using doublequotes in your echo statement will allow for the php variables inside to be parsed, so you could just do
echo "<a href='{$lightbox_link1}' data-rel='prettyPhoto[{$post_slug}]'></a>";
to get
<?php if ($lightbox_link1 == get_custom_field('lightbox_link1')) {
echo "<a href='{$lightbox_link1}' data-rel='prettyPhoto[{$post_slug}]'></a>";
} ?>

HTML Iframe get src with php

I have an webpage where I want to have another html page displayed. I used iframes. The page gets to know what to load is via the get procedure. But there is an fault in this coding I think...
<iframe src="
<?
$file = ($_GET['ti'])
if ($title = '')
echo "information.html";
else echo "$file";
?>
"></iframe>
The url the page would recieve looks like this:
http://www.website.com/reference.html?ti=unlimited.html
http://www.w3schools.com/php/php_if_else.asp
It's your if / else syntax and over all php code. It's not very well written.
<?php
$file = $_GET['ti'];
if ($title = '') {
echo "information.html";
} else {
echo "$file";
}
?>
Need semicolon:
$file = ($_GET['ti']);
Use empty(), like this:
<iframe src="
<?
$file = ($_GET['ti'])
if (empty($title))
echo "information.html";
else echo $file;
?>
"></iframe>
<?php
$possible = array("information.html", "home.html", "test.html");
$file = isset($_GET['ti']) &&
in_array($_GET['ti'], $possible)? $_GET['ti'] : "information.html";
?>
<iframe src="<?php echo $file;?>"></iframe>

Categories