How to call on next page through readmore link - php

I'm using this script in php. I have successfully added the readmore option but i want any user that clicks on this link will then open up a new page with the full article and with gallery pictures. But i want it to open into the same window.
echo "<div id=message>";
$text = $row["message"];
<?php echo substr($text,0,500);?>
Read More »

please try the following:
echo "<div id=message>";
$text = $row["message"];
<?php echo substr($text,0,500);?>
Read More »
although _self is default value of the same so you need not write it.

Related

Pass image url from one page to another in PHP

I am fetching data from database table and showing result in HTML table. What I want to achieve is that, there is image column in every row, and every image is fetched from its URL (stored in database). I am opening an image in new tab whenever it is clicked.
My question is that, how can I store url of image so that on the next page I don't want to show that real url?
The next page will look like this link:
www.example.com/full_size_image.php
and add
img tag
there to show that page
how can I store that specific image url when someone click on it?
<img src= "<?php echo $_SESSION['link'] ;">
My current code is :
while($result = $sql->fetch(PDO::FETCH_ASSOC))
{
echo "<tr>";
echo "<td>".$result['c']."</td>";
echo "<td>".$result['UserName']."</td>";
echo "<td>".$result['UserProblemKeyword']."</td>";
echo "<td> <a href ='".$result['UserProblemPicture']."' target='_blank'><img src='".$result['UserProblemPicture']."' height='62' width='62'> </a> </td>";
echo "</tr>";
}
Use a parameter via the GET Request?
So instead of directing to just /full_size_image.php direct to
/full_size_image.php?img=filename.png
then in your php code for /full_size_image.php
You can fetch the file name via
<?php
$img = isset($_GET['img']) ? htmlspecialchars($_GET['img']) : "";
if ($img == "") {
//img not set
}
//do whatever with the filename

How to display a list of all pages visited during the session

Use the page1.php and page2, page3 examples in chapter 23 as template. Create a fourth and fifth page participating the session. On each page, show links to all the other pages (it is OK to include a link to the current page).
On each page, display a list of all pages you visited during this session as shown below.
Pages display
-You may use the Superglobal variable $_SERVER[“PHP_SELF”] to access the name of the current page.
-To declare an empty array use syntax: $some_array = [];
-To append to this array: $some_array[] = ‘Appended string’;
you may use foreach() to retrieve the content of the session array
Please help me on how to display the list of pages as shown in the example above.
So far I came up with this code to get the display that is shown in the picture but I am getting errors.
<?`php`
session_start();
// .$_SESSION['`sess`_var'].'<`br` />';
$array_var = [];
$array_var[]= 'tom';
$array_var[]='`alice`';
$array_var[7] = 'Smith';
echo $_SERVER['`PHP`_SELF'];
$_SESSION['name'] = 'Tom Smith<`br`>';
// echo $_SESSION['name'];
echo '<a `href`="page1.`php`?p1">Page1.`php`</a>';
echo '<a `href`="page2.`php`?p2">Page2.`php`</a>';
echo '<a `href`="page3.`php`?p3">Page3.`php`</a>';
echo '<a `href`="page4.`php`?p4">Page4.`php`</a>';
echo '<a `href`="page5.`php`?p5">Page5.`php`</a>';
$i=0;
if(`isset`($_GET['p1']))
{
$file_array[$i]="page1.`php`";
$i++;
}
if(`isset`($_GET['p2']))
{
$file_array[$i]="page2.`php`";
$i++;
}
if(`isset`($_GET['p3']))
{
$file_array[$i]="page3.`php`";
$i++;
}
if(`isset`($_GET['p4']))
{
$file_array[$i]="page4.`php`";
$i++;
}
if(`isset`($_GET['p5']))
{
$file_array[$i]="page5.`php`";
$i++;
}
echo "The pages you visited are :";
for($i=0;$i<=$file_array[$i];$i++)
{
?>
<`br`/>
<a `href`="page1.`php`">Page 1</a>
<a `href`="page2.`php`">Page 2</a>
<a `href`="page3.`php`">Page 3</a>
<a `href`="page4.`php`">Page 4</a>
<a `href`="page5.`php`">Page 5</a>
Refer to the code below
$uri = $_SERVER['REQUEST_URI'];
array_push($_SESSION['uriHistory'], $uri);
This would get the current uri of the page and add that to the PHP SESSION variable. You can simply add this before all your pages. To get the list of pages visited simply print the $_SESSION['uriHistory'] variable.
Needless to say you need to start session for the code to run properly.

PHP print preview for popup display the link

I'm using bootstrap for my popup window. The popup winodw works fine.
Here is the code
<?php if(......my if condition for popup.......){ ?>
<a data-target="#remoteModal" data-toggle="modal" href="popup.php?book_code=<?php echo $row['BookCode']; ?>&month=<?php echo $month; ?>">My PopUp Link</a>
<?php } ?>
When I use print preview using File >> PrintPreview, the link is printed in the preview section. i.e the link is viewable ( popup.php?book_code=1&month=Apr )
How can I eliminate this?
First time i face this problem.
The print preview is like this
S.No Book Name Book Code
1 ABC 20
(popup.php?book_code=1&month=Apr )
2 DEF 40
(popup.php?book_code=1&month=Apr )
Found the solution here in this page
https://drupal.stackexchange.com/questions/59900/how-to-get-rid-of-added-urls-when-printing-a-bootstrap-themed-page
May be this will be useful..
Just what i did is.. opened the bootstrap.css
Removed these lines from the css
a[href]:after {
content: " (" attr(href) ")";
}
This will surely help someone..
Thanks,
Kimz

how to make redirect that includes data about the link that was clicked?

I have a page with two links (text link & banner link),
that should lead to the same redirect page
(on my domain).
The redirect would be to a link that shall include a variable,
that indicates which of the two link was clicked.
e.g.:
<?php
header("Location: http://external-domain.com/?ref=[value]");
die();
?>
wheareas the "value" should be "text" / "banner" or something similar.
How can I do this?
I'm not a web programmer at all so I don't have much technical knowledge,
I guess one possible solution (which I would rather avoid) would be to give a separate id for the text link and for the banner, e.g.:
text link:
http://mydomain.com/redirect.php?id=text
banner link:
http://mydomain.com/redirect.php?id=banner
whereas redirect.php would contain:
<?php
$source = $_GET['id']
?>
<?php
header("Location: http://external-domain.com/?ref=<?php print $source; ?>");
die();
?>
But that would mean that I have to use a different id for these internal links;
I would rather find a way to use the same exact internal links (maybe for example, have each link in a "div" or a "class" and get the div/class name somehow, and have them appear as the [value].
*EDIT:
Let me emphasize again: I'm looking for a way to do this without having to use any "?id=[something]" at the end of the text link or the banner link.
Thanks!
If you're already outputting the banner/text do this for the banner
<img src="imageHere.png">
And this for the text
text here
Then catch the id get values with
<?php
$id = $_GET['id'];
if ($id == 'banner'){
echo 'The clicked link was a banner';
}
else{
echo 'The clicked link was text';
}
<?php
$source = $_GET['id']
?>
<?php
header("Location: http://external-domain.com/?ref=<?php print $source; ?>");
die();
?>
should be
<?php
$source = $_GET['id'];
header("Location: http://external-domain.com/?ref=".$source);
die();
?>
Basic concatenation.

make my current link active

Well lets try to explain am sorry about my english.
I have some xml files where I get the url from with some php scripts
everything goes right the only prob is i want to change the li BGcolor of the selected link like in css :active or giving only that link eg a class="current"
this below make dynamically the urls to the data
echo "<ul><li ><a href='?xml1=".$xmlGet."&link=".$link." '>".$slide->title."</a></li></ul><br/>";
with the above i get a list of links not only one like below as urls
http://localhost/html5/playerEnd/hoofdstuks.php?xml1=chapter_3733&link=1
http://localhost/html5/playerEnd/hoofdstuks.php?xml1=chapter_3733&link=2
http://localhost/html5/playerEnd/hoofdstuks.php?xml1=chapter_3733&link=3
etc etc
and it display as menu like this
link 1
link 2
link 3
link 4
etc etc
each link load a different data to my page when clicked so i want the one clicked to be active like an other color or something.
Use $_GET['link'] to find out which link has been clicked. Then add a class to the link which corresponds to this. You'll have to define the active class.
$linkID = $_GET['link'];
echo "<ul><li ><a href='?xml1=".$xmlGet."&link=".$link." '";
if ($linkID == $link) { echo " class=\"active\" "; }
echo ">".$slide->title."</a></li></ul><br/>";
And if you want the li to have the class (as asked in comments):
$linkID = $_GET['link'];
echo "<ul><li";
if ($linkID == $link) { echo " class=\"active\" "; }
echo "><a href='?xml1=".$xmlGet."&link=".$link."'>".$slide->title."</a></li></ul><br/>";

Categories