PHP $SITE_URL Messing - php

We are hosting a WordPress site on our own Windows server its working fine, but few days back realized that there is a PHP contact form which sends a PDF attachments with radio buttons, which works fine when it was Hosted on Godaddy, now the problem is radio buttons are not loaded cos I see the URL is
<img src=\"$SITE_URL/patientform/ckedimage.png\"/>
and the $site_url is
$SITE_URL="http://".$_SERVER['SERVER_NAME'];
I think its pulling up the local server name,how do I set the Site URL as domain.com ?
whole code
<?php
$SITE_URL="http://".$_SERVER['SERVER_NAME'];
$cnt1=1;
foreach($caffinarr as $sympKey=>$sympVal6)
{
if(in_array($sympVal6, $caffinevalue))
{
$html .="<td><img src=\"$SITE_URL/patientform/ckedimage.png\"/>
<td>$sympVal6 </td>";
}
else
{
$html .="<td><img src=\"$SITE_URL/patientform/uncheckedimage.png\"/>
<td >$sympVal6</td>";

Fix your code to
<?php
$SITE_URL = 'http://'.$_SERVER['SERVER_NAME'];
$dir = "/patientform/ckedimage.png";
//echo $SITE_URL.$dir;
?>
<img src="<?php echo $SITE_URL.$dir; ?>" />
This is how your code would be:
<?php
$SITE_URL = 'http://'.$_SERVER['SERVER_NAME'];
$dir = "/patientform/ckedimage.png";
$dir_uncheck = "/patientform/uncheckedimage.png";
//echo'<img src="'.$SITE_URL.$dir.'" />';
$cnt1=1;
foreach($caffinarr as $sympKey=>$sympVal6)
{
if(in_array($sympVal6, $caffinevalue))
{
$html ='<td><img src="'.$SITE_URL.$dir.'" />
<td>'.$sympVal6.'</td>';
echo $html;
}
else
{
$html ='<td><img src="'.$SITE_URL.$dir_uncheck .'" />
<td>'.$sympVal6.'</td>';
echo $html;
?>

Related

JSON + PHP - Cant get a valid download/streaming link

I wanna get a functional download/videostreaming link, i'm trying this through
Openload and pCloud API, but I always getting error when I put my script in anywhere outside my localhost.
My pCloud code is:
<?
ini_set('display_errors','0');
echo '<form method="POST" enctype="multipart/form-data" id="add-row-form" action="">';
echo "<input type='text' value='XZ1Ix57ZIVJU5FGmV8bkvWwukuJ0JBkIKJzX' placeholder='ID da Série' name='tvshowid'></input>";
echo "<button name='ok' type='submit'>Tudo certo</button>";
echo '</form>';
$query = $_POST['tvshowid'];
$lang = $_POST['lang'];
if(isset($_POST['ok'])) {
$postdata = file_get_contents("https://api.pcloud.com/getpublinkdownload?code=". $query);
$request = json_decode($postdata);
print_r($request);
$theData = $request;
$host = $theData->hosts[rand(0,1)];
$path = $theData->path;
$vlink = 'https://'.$host. $path;
echo '<div>';
echo '<video width="30%" height="auto" controls autoplay>
<source src="'.$vlink.'" type="video/mp4">
</video>';
echo "</div>";
}
?>
Preview
Always when i try to generate a link, it says "This link was generated for another IP address. Try previous step again."
The question is: How can I get data from a JSON through my user's IP or server adrres and not by my server address (as has been happening), so that the video link is valid?

Instagram URL --> JSON

How can I go about convering a public instagram URL into JSON using PHP? Ex: https://www.instagram.com/explore/tags/brindle/
I can't use the API as I need public hashtag content and my use case won't qualify for their app review process :-(.
Here is what I have so far but it does not pull all images. Also, I'd like to be able to load the "load more" images as well. Any help would be much appreciated!
$instagram_source = file_get_contents("https://www.instagram.com/explore/tags/brindle/");
$instagram_data = explode("window._sharedData = ", $instagram_source);
$instagram_json = explode(';</script>', $instagram_data[1]);
$instagram_array = json_decode($instagram_json[0], TRUE);
$instagram_media = $instagram_array['entry_data']['TagPage'][0]['tag']['media']['nodes'];
if(!empty($instagram_media)) {
echo '<ul>';
foreach($instagram_media as $im) {
echo '<li>';
echo '<a href="https://www.instagram.com/p/'.$im['code'].'/" target="_blank">';
echo '<img src="'.$im["display_src"].'" alt="" width="'.$im["dimensions"]["width"].'" height="'.$im["dimensions"]["height"].'" />';
echo '</a>';
echo '</li>';
}
echo '</ul>';
}
Take a look at this solution here: https://github.com/Bolandish/Instagram-Grabber
Thats the best one i know until now.

How to echo Wordpress default thumbnail via php inside php if else

Hey guys i have this code
<?php $jthumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
if ($jthumb> "0")
{
echo $jthumb;
}
else
{
echo "http://placehold.it/350x250&text= Jedcore";
}
?>);background-attachment:fixed;">
What i wanted to do is to replace the
http://placehold.it/350x250&text= Jedcore with an image inside my wordpress theme like
<?php bloginfo('template_url'); ?>/images/theimage.png
But i just cant replace it liek that i will prompt an error,
I'm no expert with php :)
try this:
echo '<img src="'. bloginfo('template_url') . '/images/img.jpg" alt="">';
try after this
change
echo "http://placehold.it/350x250&text= Jedcore";
to
echo get_bloginfo('template_url').'images/theimage.png';

How to Displaying an image with path stored in Database?

I have stored images path in database and images in project folder. Now i am trying to view all IMAGES with their PRODUCTS in my HTML template. I have written the following code and its given me an empty images box in the output and when i open that image box in the new tab, it opens the following URL.
http://localhost/cms/1
Kindly tell me the way of referring images in 'img src ' tag.
include 'connect.php';
$image_query = "select * from product_images";
$image_query_run = mysql_query($image_query);
$image_query_fetch = mysql_fetch_array($image_query_run);
if (!$query=mysql_query ("select product_id,name from products")) {
echo mysql_error();
} else {
while ($query_array = mysql_fetch_array($query)) {
echo '</br><pre>';
$product_id = $query_array['product_id'];
echo "<a href='single_product.php?product_id=$product_id' >";
print_r ($query_array['name']);
echo "</a>";
echo "<img src=". $image_query_fetch
['images'] ." alt=\"\" />";
echo '</pre>';
}
}
} else {
echo "You need to Log in to visit this Page";
}
Add your local image path before source
example
echo "<img src='http://localhost/cms/1/". $image_query_fetch['images'] .'" alt=\"\" />";
*Use PHP *
<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>
You can use the HTML base tag to set a base URL that relative URLs will be resolved from.
See -> http://www.w3schools.com/tags/tag_base.asp

Wrong usage of php in a javascript "if"?

I'm trying to automatically switch my background image in wordpress depending on the visitors screen size. If he/she has a big screen, he/she gets the big version of the image. If the screen is small, he/she gets the smaller version. (Just for loading time reduction. The image will be resized to fill the screen afterwards, but that's already working.)
What isn't working is the check wether or not the smaller version even exists. If it doesn't exist, the script should fall back to the bigger version and just use that image. I get a background image, but it's only the big one (wordpress field name "BG_value". The url of the small image is stored in "BG_value-medium").
The images DO exist and the paths passed through the wordpress fields are fine, too, so that is NOT the problem. :/
But, without further ado, I present you the code (from my header.php from wordpress).
<body>
<!-- Wordpress Loop -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<script type="text/javascript">
if (($(window).width() < 1340) && (<?php
if(file_exists(bloginfo('template_url').get_post_meta($post->ID, 'BG_value-medium', $single = true))){
echo "true";
}else{
echo "false"; } ?> )){
<?php $bgimg = get_post_meta($post->ID, 'BG_value-medium', $single = true); ?>
} else {
<?php $bgimg = get_post_meta($post->ID, 'BG_value', $single = true); ?>
}
</script>
<div id="bgimage"> <img class="stretch" src="<?php bloginfo('template_url'); ?><?php echo $bgimg; ?>" alt="" /> </div>
<?php endwhile; endif; ?>
I'm sorry if this looks a bit messy, I've been working on this for the last few hours, changing it over and over again.
Any ideas what's going wrong here? Check out the page
You have a big logical error in this. You want to set the bg image with an javascript function, but you never try to set it with javascript, only with an php echo. Take a look at the sourcecode of this javascript snippet in your browser, and you will see what i mean.
You should store the image-pathes in javascript variables inside the then and else, and use them to set the bg image.
Untested:
<script type="text/javascript">
if (($(window).width() < 1340) && (<?php if(file_exists(bloginfo('template_url').get_post_meta($post->ID, 'BG_value-medium', $single = true)))){
echo "true";
}else{
echo "false"; } ?> )){
var bgimage="<?php echo get_post_meta($post->ID, 'BG_value-medium', $single = true); ?>";
} else {
var bgimage="<?php echo get_post_meta($post->ID, 'BG_value', $single = true); ?>";
}
document.getElementById("bgimageimg").src=bgimage;
</script>
<div id="bgimage"><img id="bgimageimg" class="stretch" src="" alt="" /></div>
I've tried to clean up that mess to see what is happening. The following is untested, but if something doesn't work you can now atleast see why it doesn't work.
<?php
if (have_posts()) {
while (have_posts()) {
the_post();
echo '<script type="text/javascript">';
$url = bloginfo('template_url');
$img = get_post_meta($post->ID, 'BG_value-medium', $single = true);
$file_exists = 'false';
if (file_exists($url.$img)) {
$file_exists = 'true';
}
echo 'var bgimg = '.get_post_meta($post->ID, 'BG_value', $single = true).';';
echo 'if ($(window).width() < 1340 && '.$file_exists.') {';
echo ' bgimg = '.get_post_meta($post->ID, 'BG_value-medium', $single = true).';';
echo '}';
echo '$("#bgimage").attr("src", bgimg);';
echo '</script>';
}
}
?>

Categories