Jump to content

Simple isset($_GET)


reboot_computers

Recommended Posts

Hi

 

I have written a simple bit of code, i used to code php a little and have just decided to start coding php again but for the life of me can't work out why this isn't working, so if someone could help this would be great.

 

address

 

www.mysite.co.uk/index.php?vid=video2

<php

if (isset($_GET['vid'])){

  $video=$_GET['vid'];

}else{

$video="video1";

}

 

when i echo $video i only get video=1

Link to comment
Share on other sites

ahh i see what you are doing, well you don't need to place word video in there, just an id number

and use something like this:

www.mysite.co.uk/index.php?vid=2

if (isset($_GET['vid']) && is_numeric($_GET['vid']) && $_GET['vid'] !=''){
   $video = $_GET['vid'];
}else{
$video = 1;
}
echo "Video number is $video";

Link to comment
Share on other sites

Hi Again

 

 

Thankyou for quick response. No number passed, only video1 or video2 or video3 as a whole string because video1.php or video2.php or video3.php will be used later in an include with this line of code.

 

div id=video">

<?php

$a=file_get_contents("http://www.mysite.co.uk/includes/" . ($vid . ".php")); 

echo $a;

?>

</div>

 

the files have the embed code for a particular video, so i have one div layer with video and another with links and depending which link gets clicked on it would be something like this

<div id="links"

<a href="index.php?vid=video1">Video 1</a>

</div>

Link to comment
Share on other sites

You can just add the word video to the include.

 

$a=file_get_contents("http://www.mysite.co.uk/includes/video" . ($vid . ".php"));  

 

But I'm not sure why are passing these to individual php files.

 

Why not use a single php page and pass the id into an embed in just that.

 

Lets take a simple youtube example.

<?php
if(isset($_GET['vid']) && $_GET['vid'] !=''){
    $video = $_GET['vid'];
}else{
    $video = "JW5meKfy3fY";
}
echo "<a href='?vid=uuwfgXD8qV8'>uuwfgXD8qV8</a><br />";
echo "<a href='?vid=4e8L_Z0a_kQ'>4e8L_Z0a_kQ</a><br />";

echo "Video number is $video <br />";

?>

<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/<?php echo $video;?>" frameborder="0">
</iframe>

 

Now you don't have to display anything like I did, except the embed.

 

then can just include if wanted to

include("script-name.php?vid=$video");

 

or just link to it

echo "<a href='script-name.php?vid=$video'>Video $video</a>";

Link to comment
Share on other sites

Hi

 

Thanks again for your reply but sometimes the video's will be coming from different places, so wanted to just to create a link like <a href="index.php?vid=Video1 or <a href="index.php?vid=Video2 or <a href="index.php?vid=Video3

 

then i wanted to check to see if "vid" was set, i wanted to pass the variable "vid" as the name of the php file that had the video embed code in like this

 

<?php

if (isset($_GET['vid'])){

$video=$_GET['vid'];

}else{

$vid="video1";

}

?>

 

then later i would have

 

<?php

$a=file_get_contents("http://www.mysite.co.uk/includes/" . ($vid . ".php")); 

echo $a;

?>

 

which would load the filename of the included php file that has been passed from the links and if nothing selected then video 1 would be default.

 

Is there a way of making my code work please. It seems to be this bit that doesn't work

 

<?php

if (isset($_GET['vid'])){

$video=$_GET['vid'];

}else{

$vid="video1";

}

?>

 

p.s everything else seems to work just can't work out this bit

 

many thanks

 

Paul :-)

 

Link to comment
Share on other sites

<?php
if (isset($_GET['vid'])){
$video=$_GET['vid'];
}else{
$vid="video1";
}
?>

 

two different variables.. i assume you only want to use the $vid one as that's the one you appear to be using later

 

 

although this mistake wasn't in your first post...? but then again, you didnt show us the file_get_contents line

Link to comment
Share on other sites

Well I tried to help, what I said previous should work for you, just append video to the includes/......php file or add the word video to front of $_GET['vid']

 

Would be best to create or use an already made video embed script, depending where the url comes from, that embed is used.

 

Here is one that works ok.

http://webcodingeasy.com/PHP-classes/Get-information-about-video-and-images-from-link

Link to comment
Share on other sites

Hi

 

Just tried your code and is same as mine, the output is always video1 even if querystring reads video 2, also video's could be coming from youtube, vimeo and where ever the customer tells me to get the video.

 

by the way here is the site i am working on http://www.cannabisenergydrink.co.uk/site

 

It would be great if you could see why this bit of code doesn't work :-)

 

Thanks

 

Paul

Link to comment
Share on other sites

Like I said.. this video embed class does all those.

http://webcodingeasy.com/PHP-classes/Get-information-about-video-and-images-from-link

 

Viewing the site doesn't help much, it only renders html and can't see your php code.

 

If really want help with this...post the complete index page minus any sensitive data.

And also provide the code for video1.php,video2.php

 

But I could see you doing this within your index page.

//checking if is set, not empty values and also numeric
if(isset($_GET['vid']) && $_GET['vid'] !='' && is_numeric($_GET['vid'])){
    $video = $_GET['vid'];
} else {
    $video = 1;
}

//creating dynamic file location
$video_file = "includes/video".$video.".php";

//made links for them
echo "<a href='index.php?vid=1'>Video 1</a><br />";
echo "<a href='index.php?vid=2'>Video 2</a><br />";

//place this code in your divider
//first we see if exists then include the file, if not show a message
if(file_exists($video_file)){
include($video_file);
} else {
echo "No video available";
}

Link to comment
Share on other sites

Without seeing the actual code we can't help you any more than already given.  The code you have supplied will work, so you must be implementing it incorrectly somehow, but we can't tell how because your not showing us that part of the code.

Link to comment
Share on other sites

<?php

if (isset($_GET['vid'])){

$video=$_GET['vid'];

} else{

  $video="video1"

}

?>

<div id="container">

<div id="header">

<div id="navlogo"> <a href="index.php"><img src="images/logo.png" width="204" height="63" /></a>

<a href="index.php" title="Cannabis Energy Drink"></a></div>

<ul id="menu">

<li><a href="aboutus.php">Company Info</a></li>

<li><a href="products.php">Products</a></li>

<li><a href="news.php">Events & News</a></li>

<li><a href="buy.php">Buy</a></li>

<li><a href="contact.php">Contact</a></li>

<li><a href="games.php">Games</a></li>

</ul>

</div>

<div id="featured">

<img src="slider/temphead.jpg" alt="Overflow: Hidden No More" />

    <img src="slider/temphead2.jpg"  alt="HTML Captions" />

    <img src="slider/temphead3.jpg" alt="and more features" />

    <img src="slider/temphead4.jpg" alt="and more features" />

    <img src="slider/temphead5.jpg" alt="and more features" />

    <img src="slider/temphead6.jpg" alt="and more features" />

    <img src="slider/temphead7.jpg" alt="and more features" />

    <img src="slider/temphead8.jpg" alt="and more features" /></div>

<div id="content2"></div>

<div id="content3"><h1>Welcome to the Cannabis Energy Drink UK website</h1><br /><p> Be part of the energy revolution and keep up to date with all the latest news . Watch the action with our Cannabis TV, see who we sponsor and support, and be the first to get the lowdown on our products and new releases as they happen.<br /><br /> Check out our clubbers page with the latest clubbing events and promotions around the country, and get interactive with fun online games. Discover your inner energy with Cannabis Energy Drink UK.</p></div>

<div id="content4"></div>

<div id="content5"><?php

$a=file_get_contents("includes/" . ($video . ".php")); 

echo $a;

?>

</div>

<div id="content6"><a href="index.php?vid=video1"><p class="video1">Video 1</p></a><a href="index.php?vid=video2"><p class="video2">Video 2</p></a></div>

<div id="content7"><iframe src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fenergydrinkuk&width=320&height=590&colorscheme=light&show_faces=true&border_color=%23f60&stream=true&header=true" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:320px; height:590px;" allowTransparency="true"></iframe></div>

<div id="footer">

<div id="footer1">

<div id="facebook"><p><a href="http://www.facebook.com"><img src="images/facebook.png" width="19" height="19" /> Facebook</a></p></div>

<div id="youtube"><p><a href="http://www.facebook.com"><img src="images/youtube.png" width="19" height="19" /> Youtube</a></p></div>

    <div id="vimeo"><p><a href="http://www.vimeo.com"><img src="images/vimeo.png" width="19" height="19" /> Vimeo</a></p></div>

<div id="flickr"><p><a href="http://www.flickr.com"><img src="images/flicker.png" width="19" height="19" /> Flickr</a></p></div>

    <div id="twitter"><p><a href="http://www.twitter.com"><img src="images/twitter.png" width="19" height="19" /> Twitter</a></p></div>

<div id="share"></div>

    </div>

<div id="footer2"></div>

<div id="footer3"></div>

</div>

</div>

 

If i change

 

<?php

if (isset($_GET['vid'])){

$video=$_GET['vid'];

} else{

  $video="video1"

}

?>

 

for

 

<?php

$video="video2";

?>

 

it works great but with the isset code, just can't get that bit working

 

Hope this is better for you and i am grateful for all your help

Link to comment
Share on other sites

 

<?php
if (isset($_GET['vid'])){
$video=$_GET['vid'];
} else{
  $video="video1";//<- was missing semicolon, was not parse error?
}

echo $video;//echo this to see if changes or not
?>

 

This is as about basic as it gets, as long as your video1.php and video2.php actually contain different embed codes, I don't see why it wouldn't work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.